improve verbose logging, skip concat if only one VOD file present

This commit is contained in:
ari melody 2026-06-28 16:22:36 +01:00
parent c961aa3b6c
commit 0abafd26c5
Signed by: ari
GPG key ID: 60B5F0386E3DDB7E
2 changed files with 54 additions and 50 deletions

98
main.go
View file

@ -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)
}
}