package main package main import ( "fmt" "log" "sync" "time" "github.com/jeffreydwalter/arlo-go" ) const ( USERNAME = "user@example.com" PASSWORD = "supersecretpassword" ) func main() { // Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. // Subsequent successful calls to login will update the oAuth token. arlo, err := arlo.Login(USERNAME, PASSWORD) if err != nil { log.Printf("Failed to login: %s\n", err) return } // At this point you're logged into Arlo. now := time.Now() start := now.Add(-7 * 24 * time.Hour) // Get all of the recordings for a date range. library, err := arlo.GetLibrary(start, now) if err != nil { log.Println(err) return } // We need to wait for all of the recordings to download. var wg sync.WaitGroup for _, recording := range *library { // Let the wait group know about the go routine that we're about to run. wg.Add(1) // The go func() here makes this script download the files concurrently. // If you want to download them serially for some reason, just remove the go func() call. go func() { fileToWrite, err := os.Create(fmt.Sprintf("downloads/%s_%s.mp4", time.Unix(0, recording.UtcCreatedDate*int64(time.Millisecond)).Format(("2006-01-02_15.04.05")), recording.UniqueId)) defer fileToWrite.Close() if err != nil { log.Fatal(err) } // The videos produced by Arlo are pretty small, even in their longest, best quality settings. // DownloadFile() efficiently streams the file from the http.Response.Body directly to a file. if err := arlo.DownloadFile(recording.PresignedContentUrl, fileToWrite); err != nil { log.Println(err) } else { log.Printf("Downloaded video %s from %s", recording.CreatedDate, recording.PresignedContentUrl) } // Mark this go routine as done in the wait group. wg.Done() }() } // Wait here until all of the go routines are done. wg.Wait() // The below example demonstrates how you could delete the cloud recordings after downloading them. // Simply uncomment the below code to start using it. // Delete all of the videos you just downloaded from the Arlo library. // Notice that you can pass the "library" object we got back from the GetLibrary() call. /* if err := arlo.BatchDeleteRecordings(library); err != nil { log.Println(err) return } */ // If we made it here without an exception, then the videos were successfully deleted. /* log.Println("Batch deletion of videos completed successfully.") */ }