From 04eb4211869c8b319879a48bb442632d4c9267cb Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 11 Apr 2020 12:42:47 +0200 Subject: [PATCH] Refactor a bit how ffmpeg is used to get metadata - createProbeCommand returns a []string instead of (string, string[]) - Simplify the loop of createProbeCommand --- conf/configuration.go | 2 +- scanner/metadata_ffmpeg.go | 27 ++++++++++----------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/conf/configuration.go b/conf/configuration.go index 635faf12..9913b66d 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -29,7 +29,7 @@ type nd struct { TranscodingCacheSize string `default:"100MB"` // in MB ImageCacheSize string `default:"100MB"` // in MB - ProbeCommand string `default:"ffmpeg -i %s -f ffmetadata"` + ProbeCommand string `default:"ffmpeg %s -f ffmetadata"` // DevFlags. These are used to enable/disable debugging and incomplete features DevLogSourceLine bool `default:"false"` diff --git a/scanner/metadata_ffmpeg.go b/scanner/metadata_ffmpeg.go index 4f247414..9ca90a6d 100644 --- a/scanner/metadata_ffmpeg.go +++ b/scanner/metadata_ffmpeg.go @@ -74,10 +74,10 @@ func LoadAllAudioFiles(dirPath string) (map[string]os.FileInfo, error) { } func ExtractAllMetadata(inputs []string) (map[string]*Metadata, error) { - cmdLine, args := createProbeCommand(inputs) + args := createProbeCommand(inputs) - log.Trace("Executing command", "arg0", cmdLine, "args", args) - cmd := exec.Command(cmdLine, args...) + log.Trace("Executing command", "args", args) + cmd := exec.Command(args[0], args[1:]...) output, _ := cmd.CombinedOutput() mds := map[string]*Metadata{} if len(output) == 0 { @@ -269,25 +269,18 @@ func (m *Metadata) parseDuration(tagName string) float32 { } // Inputs will always be absolute paths -func createProbeCommand(inputs []string) (string, []string) { - cmd := conf.Server.ProbeCommand - - split := strings.Split(cmd, " ") +func createProbeCommand(inputs []string) []string { + split := strings.Split(conf.Server.ProbeCommand, " ") args := make([]string, 0) - first := true + for _, s := range split { if s == "%s" { for _, inp := range inputs { - if !first { - args = append(args, "-i") - } - args = append(args, inp) - first = false + args = append(args, "-i", inp) } - continue + } else { + args = append(args, s) } - args = append(args, s) } - - return args[0], args[1:] + return args }