Skip to content

Commit

Permalink
add webm support
Browse files Browse the repository at this point in the history
  • Loading branch information
Zainrax committed Nov 20, 2024
1 parent 38946d0 commit 1f2457a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
21 changes: 12 additions & 9 deletions cmd/thermal-uploader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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...)
Expand All @@ -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
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions cmd/thermal-uploader/uploadjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -82,6 +82,7 @@ func (u *uploadJob) delete() {
}
}
}

func (u *uploadJob) preprocess() error {
err := u.setDuration()
if err != nil {
Expand All @@ -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
Expand Down

0 comments on commit 1f2457a

Please sign in to comment.