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
62
main.go
62
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,12 +325,21 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
videoMeta.Filepath = path.Join(metadata.FootageDir, vodFiles[0])
|
||||
|
||||
// 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
|
||||
fullVodExists := false
|
||||
fullVodProbe, err := scanner.ProbeSegment(videoMeta.Filepath)
|
||||
concatVodExists := false
|
||||
concatVodProbe, err := scanner.ProbeSegment(videoMeta.Filepath)
|
||||
if err == nil {
|
||||
videoMeta.SizeBytes = fullVodProbe.Format.Size
|
||||
videoMeta.SizeBytes = concatVodProbe.Format.Size
|
||||
var totalLength float64 = 0
|
||||
|
||||
for _, filename := range vodFiles {
|
||||
|
|
@ -339,10 +348,10 @@ func main() {
|
|||
totalLength += probe.Format.Duration
|
||||
}
|
||||
// full VOD may exist, but not be complete (interrupted concat)
|
||||
fullVodExists = math.Abs(fullVodProbe.Format.Duration - totalLength) < float64(0.1)
|
||||
concatVodExists = math.Abs(concatVodProbe.Format.Duration - totalLength) < float64(0.1)
|
||||
}
|
||||
|
||||
if fullVodExists {
|
||||
if concatVodExists {
|
||||
log.Print("Full VOD appears to already exist- uploading this file...")
|
||||
} else {
|
||||
// concatenate VOD segments into full VOD
|
||||
|
|
@ -354,6 +363,7 @@ func main() {
|
|||
} else {
|
||||
log.Print("Dry run: Skipping VOD concatenation")
|
||||
}
|
||||
}
|
||||
|
||||
if !dryRun {
|
||||
// okay actually upload now!
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue