improve verbose logging, skip concat if only one VOD file present
This commit is contained in:
parent
c961aa3b6c
commit
0abafd26c5
2 changed files with 54 additions and 50 deletions
98
main.go
98
main.go
|
|
@ -73,7 +73,7 @@ func main() {
|
||||||
var verbose bool = false
|
var verbose bool = false
|
||||||
var initDirectory bool = false
|
var initDirectory bool = false
|
||||||
var logout bool = false
|
var logout bool = false
|
||||||
var deleteFullVod bool = false
|
var keepFullVOD bool = false
|
||||||
var forceUpload bool = false
|
var forceUpload bool = false
|
||||||
var dryRun bool = false
|
var dryRun bool = false
|
||||||
var directory string = "."
|
var directory string = "."
|
||||||
|
|
@ -101,8 +101,8 @@ func main() {
|
||||||
|
|
||||||
case "-d":
|
case "-d":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "--deleteAfter":
|
case "--keep-vod":
|
||||||
deleteFullVod = true
|
keepFullVOD = true
|
||||||
|
|
||||||
case "-f":
|
case "-f":
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -193,10 +193,18 @@ func main() {
|
||||||
if verbose {
|
if verbose {
|
||||||
enc := json.NewEncoder(os.Stdout)
|
enc := json.NewEncoder(os.Stdout)
|
||||||
enc.SetIndent("", "\t")
|
enc.SetIndent("", "\t")
|
||||||
fmt.Printf("Directory metadata: ")
|
log.Print("[ Metadata ]")
|
||||||
enc.Encode(metadata)
|
log.Printf("Title: %s", metadata.Title)
|
||||||
fmt.Printf("\nVOD files available: ")
|
log.Printf("Part: %d", metadata.Part)
|
||||||
enc.Encode(vodFiles)
|
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
|
// scan for thumbnail
|
||||||
|
|
@ -239,17 +247,9 @@ func main() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if verbose {
|
if verbose {
|
||||||
enc := json.NewEncoder(os.Stdout)
|
log.Print()
|
||||||
fmt.Printf("\nVideo template: ")
|
log.Printf("[ TITLE ]\n\n%s\n\n", title)
|
||||||
enc.Encode(videoMeta)
|
log.Printf("[ DESCRIPTION ]\n\n%s\n\n", description)
|
||||||
|
|
||||||
fmt.Printf(
|
|
||||||
"\n================================\n\n" +
|
|
||||||
"< TITLE >\n%s\n\n" +
|
|
||||||
"< DESCRIPTION >\n%s\n" +
|
|
||||||
"\n================================\n",
|
|
||||||
title, description,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// youtube oauth flow
|
// youtube oauth flow
|
||||||
|
|
@ -325,34 +325,44 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dryRun {
|
videoMeta.Filepath = path.Join(metadata.FootageDir, vodFiles[0])
|
||||||
// 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
|
|
||||||
|
|
||||||
for _, filename := range vodFiles {
|
// no need to concat if VOD is already one whole file
|
||||||
probe, err := scanner.ProbeSegment(path.Join(footageDir, filename))
|
if len(vodFiles) > 1 {
|
||||||
if err != nil { continue }
|
videoMeta.Filepath = path.Join(
|
||||||
totalLength += probe.Format.Duration
|
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 {
|
if concatVodExists {
|
||||||
log.Print("Full VOD appears to already exist- uploading this file...")
|
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 {
|
} else {
|
||||||
// concatenate VOD segments into full VOD
|
log.Print("Dry run: Skipping VOD concatenation")
|
||||||
videoMeta.SizeBytes, err = vid.ConcatVideo(videoMeta, vodFiles, verbose)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Failed to concatenate VOD segments: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.Print("Dry run: Skipping VOD concatenation")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dryRun {
|
if !dryRun {
|
||||||
|
|
@ -384,9 +394,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete full VOD after upload, if requested
|
// delete full VOD after upload, if requested
|
||||||
if deleteFullVod {
|
// if len(vodFiles) == 1, the full VOD is the *only* VOD. do not delete this!!!
|
||||||
err = os.Remove(videoMeta.Filepath)
|
if len(vodFiles) > 1 && !keepFullVOD {
|
||||||
if err != nil {
|
if err = os.Remove(videoMeta.Filepath); err != nil {
|
||||||
log.Fatalf("Failed to delete full VOD: %v", err)
|
log.Fatalf("Failed to delete full VOD: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,12 +72,6 @@ func BuildVideo(metadata *scanner.Metadata) (*VideoMetadata, error) {
|
||||||
Part: metadata.Part,
|
Part: metadata.Part,
|
||||||
Date: metadata.Date.AsTime(time.UTC),
|
Date: metadata.Date.AsTime(time.UTC),
|
||||||
Tags: metadata.Tags,
|
Tags: metadata.Tags,
|
||||||
Filepath: path.Join(
|
|
||||||
metadata.FootageDir,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"%s-fullvod.mkv",
|
|
||||||
metadata.Date.String(),
|
|
||||||
)),
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue