From 1f2457ab861de83a272d6141d1b02b3eeeeb8a25 Mon Sep 17 00:00:00 2001 From: Patrick Baxter Date: Wed, 20 Nov 2024 17:10:18 +1300 Subject: [PATCH] add webm support --- cmd/thermal-uploader/main.go | 21 ++++++++++++--------- cmd/thermal-uploader/uploadjob.go | 7 ++++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/thermal-uploader/main.go b/cmd/thermal-uploader/main.go index 8eff9bd..c3fa061 100644 --- a/cmd/thermal-uploader/main.go +++ b/cmd/thermal-uploader/main.go @@ -40,9 +40,11 @@ const ( failedRetryMaxInterval = time.Hour * 24 ) -var log = logging.NewLogger("info") -var version = "No version provided" -var globs = [4]string{"*.cptv", "*.avi", "*.mp4", "*.aac"} +var ( + log = logging.NewLogger("info") + version = "No version provided" + globs = [7]string{"*.cptv", "*.avi", "*.mp4", "*.aac", "*.mp3", "*.wav", "*.webm"} +) type Args struct { ConfigDir string `arg:"-c,--config" help:"path to configuration directory"` @@ -133,7 +135,7 @@ func runMain() error { return err } - //try failed uploads again if succeeded + // try failed uploads again if succeeded if time.Now().After(nextFailedRetry) { if retryFailedUploads(apiClient, conf.Directory) { failedRetryAttempts = 0 @@ -171,7 +173,7 @@ func minDuration(a, b time.Duration) time.Duration { } func uploadFiles(apiClient *api.CacophonyAPI, directory string) error { - var matches = make([]string, 0, 5) + matches := make([]string, 0, 5) for _, glob := range globs { globMatches, _ := filepath.Glob(filepath.Join(directory, glob)) matches = append(matches, globMatches...) @@ -202,7 +204,7 @@ func uploadFiles(apiClient *api.CacophonyAPI, directory string) error { } func retryFailedUploads(apiClient *api.CacophonyAPI, directory string) bool { - var matches = make([]string, 0, 5) + matches := make([]string, 0, 5) for _, glob := range globs { globMatches, _ := filepath.Glob(filepath.Join(directory, failedUploadsDir, glob)) matches = append(matches, globMatches...) @@ -217,7 +219,6 @@ func retryFailedUploads(apiClient *api.CacophonyAPI, directory string) bool { filename := matches[index] job := newUploadJob(filename) err := job.upload(apiClient) - if err != nil { log.Printf("Uploading still failing to upload %v: %v", filename, err) return false @@ -244,8 +245,10 @@ func uploadFileWithRetries(apiClient *api.CacophonyAPI, job *uploadJob) error { return job.moveToFailed() } -const dbusDest = "org.cacophony.ATtiny" -const dbusPath = "/org/cacophony/ATtiny" +const ( + dbusDest = "org.cacophony.ATtiny" + dbusPath = "/org/cacophony/ATtiny" +) func getDbusObj() (dbus.BusObject, error) { conn, err := dbus.SystemBus() diff --git a/cmd/thermal-uploader/uploadjob.go b/cmd/thermal-uploader/uploadjob.go index c723a80..6a7a13f 100644 --- a/cmd/thermal-uploader/uploadjob.go +++ b/cmd/thermal-uploader/uploadjob.go @@ -31,7 +31,7 @@ func (u *uploadJob) isIR() bool { } func (u *uploadJob) isAudio() bool { - return filepath.Ext(u.filename) == ".aac" + return filepath.Ext(u.filename) == ".aac" || filepath.Ext(u.filename) == ".mp3" || filepath.Ext(u.filename) == ".wav" || filepath.Ext(u.filename) == ".webm" } func (u *uploadJob) isThermal() bool { @@ -82,6 +82,7 @@ func (u *uploadJob) delete() { } } } + func (u *uploadJob) preprocess() error { err := u.setDuration() if err != nil { @@ -91,8 +92,8 @@ func (u *uploadJob) preprocess() error { } func (u *uploadJob) convertMp4() error { - var extension = filepath.Ext(u.filename) - var name = u.filename[0:len(u.filename)-len(extension)] + ".mp4" + extension := filepath.Ext(u.filename) + name := u.filename[0:len(u.filename)-len(extension)] + ".mp4" cmd := exec.Command("ffmpeg", "-y", // Yes to all "-i", u.filename, "-map_metadata", "-1", // strip out all (mostly) metadata