From 0abafd26c54c9aefb9c6b992d287c815dd44239e Mon Sep 17 00:00:00 2001 From: ari melody Date: Sun, 28 Jun 2026 16:22:36 +0100 Subject: [PATCH] improve verbose logging, skip concat if only one VOD file present --- main.go | 98 +++++++++++++++++++++++++--------------------- youtube/youtube.go | 6 --- 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/main.go b/main.go index 26b7d03..cd1a461 100644 --- a/main.go +++ b/main.go @@ -73,7 +73,7 @@ func main() { var verbose bool = false var initDirectory bool = false var logout bool = false - var deleteFullVod bool = false + var keepFullVOD bool = false var forceUpload bool = false var dryRun bool = false var directory string = "." @@ -101,8 +101,8 @@ func main() { case "-d": fallthrough - case "--deleteAfter": - deleteFullVod = true + case "--keep-vod": + keepFullVOD = true case "-f": fallthrough @@ -193,10 +193,18 @@ func main() { if verbose { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", "\t") - fmt.Printf("Directory metadata: ") - enc.Encode(metadata) - fmt.Printf("\nVOD files available: ") - enc.Encode(vodFiles) + log.Print("[ Metadata ]") + log.Printf("Title: %s", metadata.Title) + log.Printf("Part: %d", metadata.Part) + log.Printf("Date: %s", metadata.Date.String()) + log.Printf( + "Category: `%s` - %s (%s)", + metadata.Category.Type, + metadata.Category.Name, + metadata.Category.Url, + ) + log.Printf("Tags: %s", strings.Join(metadata.Tags, ", ")) + log.Printf("VOD files: [ %s ]", strings.Join(vodFiles, ", ")) } // scan for thumbnail @@ -239,17 +247,9 @@ func main() { ) } if verbose { - enc := json.NewEncoder(os.Stdout) - fmt.Printf("\nVideo template: ") - enc.Encode(videoMeta) - - fmt.Printf( - "\n================================\n\n" + - "< TITLE >\n%s\n\n" + - "< DESCRIPTION >\n%s\n" + - "\n================================\n", - title, description, - ) + log.Print() + log.Printf("[ TITLE ]\n\n%s\n\n", title) + log.Printf("[ DESCRIPTION ]\n\n%s\n\n", description) } // youtube oauth flow @@ -325,34 +325,44 @@ func main() { os.Exit(0) } - if !dryRun { - // check if full VOD already exists with expected duration - fullVodExists := false - fullVodProbe, err := scanner.ProbeSegment(videoMeta.Filepath) - if err == nil { - videoMeta.SizeBytes = fullVodProbe.Format.Size - var totalLength float64 = 0 + videoMeta.Filepath = path.Join(metadata.FootageDir, vodFiles[0]) - for _, filename := range vodFiles { - probe, err := scanner.ProbeSegment(path.Join(footageDir, filename)) - if err != nil { continue } - totalLength += probe.Format.Duration + // no need to concat if VOD is already one whole file + if len(vodFiles) > 1 { + videoMeta.Filepath = path.Join( + metadata.FootageDir, + fmt.Sprintf("%s-fullvod.mkv", metadata.Date.String()), + ) + + if !dryRun { + // check if full VOD already exists with expected duration + concatVodExists := false + concatVodProbe, err := scanner.ProbeSegment(videoMeta.Filepath) + if err == nil { + videoMeta.SizeBytes = concatVodProbe.Format.Size + var totalLength float64 = 0 + + for _, filename := range vodFiles { + probe, err := scanner.ProbeSegment(path.Join(footageDir, filename)) + if err != nil { continue } + totalLength += probe.Format.Duration + } + // full VOD may exist, but not be complete (interrupted concat) + concatVodExists = math.Abs(concatVodProbe.Format.Duration - totalLength) < float64(0.1) } - // full VOD may exist, but not be complete (interrupted concat) - fullVodExists = math.Abs(fullVodProbe.Format.Duration - totalLength) < float64(0.1) - } - if fullVodExists { - log.Print("Full VOD appears to already exist- uploading this file...") + if concatVodExists { + log.Print("Full VOD appears to already exist- uploading this file...") + } else { + // concatenate VOD segments into full VOD + videoMeta.SizeBytes, err = vid.ConcatVideo(videoMeta, vodFiles, verbose) + if err != nil { + log.Fatalf("Failed to concatenate VOD segments: %v", err) + } + } } else { - // concatenate VOD segments into full VOD - videoMeta.SizeBytes, err = vid.ConcatVideo(videoMeta, vodFiles, verbose) - if err != nil { - log.Fatalf("Failed to concatenate VOD segments: %v", err) - } + log.Print("Dry run: Skipping VOD concatenation") } - } else { - log.Print("Dry run: Skipping VOD concatenation") } if !dryRun { @@ -384,9 +394,9 @@ func main() { } // delete full VOD after upload, if requested - if deleteFullVod { - err = os.Remove(videoMeta.Filepath) - if err != nil { + // if len(vodFiles) == 1, the full VOD is the *only* VOD. do not delete this!!! + if len(vodFiles) > 1 && !keepFullVOD { + if err = os.Remove(videoMeta.Filepath); err != nil { log.Fatalf("Failed to delete full VOD: %v", err) } } diff --git a/youtube/youtube.go b/youtube/youtube.go index 681d9f7..2c4e18c 100644 --- a/youtube/youtube.go +++ b/youtube/youtube.go @@ -72,12 +72,6 @@ func BuildVideo(metadata *scanner.Metadata) (*VideoMetadata, error) { Part: metadata.Part, Date: metadata.Date.AsTime(time.UTC), Tags: metadata.Tags, - Filepath: path.Join( - metadata.FootageDir, - fmt.Sprintf( - "%s-fullvod.mkv", - metadata.Date.String(), - )), }, nil }