add --dry-run option
This commit is contained in:
parent
f6e42cd7e6
commit
0ac59c5407
2 changed files with 57 additions and 42 deletions
24
main.go
24
main.go
|
|
@ -77,6 +77,7 @@ func main() {
|
||||||
var logout bool = false
|
var logout bool = false
|
||||||
var deleteFullVod bool = false
|
var deleteFullVod bool = false
|
||||||
var forceUpload bool = false
|
var forceUpload bool = false
|
||||||
|
var dryRun bool = false
|
||||||
var directory string = "."
|
var directory string = "."
|
||||||
|
|
||||||
for i, arg := range os.Args {
|
for i, arg := range os.Args {
|
||||||
|
|
@ -110,6 +111,9 @@ func main() {
|
||||||
case "--force":
|
case "--force":
|
||||||
forceUpload = true
|
forceUpload = true
|
||||||
|
|
||||||
|
case "--dry-run":
|
||||||
|
dryRun = true
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "Unknown option `%s`\n", arg)
|
fmt.Fprintf(os.Stderr, "Unknown option `%s`\n", arg)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -273,11 +277,11 @@ func main() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// concatenate VOD segments into full VOD
|
if (!dryRun) {
|
||||||
fullVodExists := func () bool {
|
|
||||||
// check if full VOD already exists with expected duration
|
// check if full VOD already exists with expected duration
|
||||||
|
fullVodExists := false
|
||||||
fullVodProbe, err := scanner.ProbeSegment(video.Filepath)
|
fullVodProbe, err := scanner.ProbeSegment(video.Filepath)
|
||||||
if err != nil { return false }
|
if err == nil {
|
||||||
video.SizeBytes = fullVodProbe.Format.Size
|
video.SizeBytes = fullVodProbe.Format.Size
|
||||||
var totalLength float64 = 0
|
var totalLength float64 = 0
|
||||||
|
|
||||||
|
|
@ -286,17 +290,23 @@ func main() {
|
||||||
if err != nil { continue }
|
if err != nil { continue }
|
||||||
totalLength += probe.Format.Duration
|
totalLength += probe.Format.Duration
|
||||||
}
|
}
|
||||||
return math.Abs(fullVodProbe.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 fullVodExists {
|
||||||
log.Print("Full VOD appears to already exist- uploading this file...")
|
log.Print("Full VOD appears to already exist- uploading this file...")
|
||||||
} else {
|
} else {
|
||||||
|
// concatenate VOD segments into full VOD
|
||||||
video.SizeBytes, err = vid.ConcatVideo(video, vodFiles, verbose)
|
video.SizeBytes, err = vid.ConcatVideo(video, vodFiles, verbose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to concatenate VOD segments: %v", err)
|
log.Fatalf("Failed to concatenate VOD segments: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Print("Dry run: Skipping VOD concatenation")
|
||||||
|
}
|
||||||
|
|
||||||
// youtube oauth flow
|
// youtube oauth flow
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
@ -329,6 +339,7 @@ func main() {
|
||||||
log.Fatalf("Failed to save OAuth token: %v", err)
|
log.Fatalf("Failed to save OAuth token: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dryRun) {
|
||||||
// okay actually upload now!
|
// okay actually upload now!
|
||||||
ytVideo, err := yt.UploadVideo(ctx, tokenSource, video, thumbnail, templates)
|
ytVideo, err := yt.UploadVideo(ctx, tokenSource, video, thumbnail, templates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -359,6 +370,9 @@ func main() {
|
||||||
log.Fatalf("Failed to delete full VOD: %v", err)
|
log.Fatalf("Failed to delete full VOD: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Print("Dry run: Skipping video upload")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialiseDirectory(directory string) error {
|
func initialiseDirectory(directory string) error {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ OPTIONS:
|
||||||
--init: Initialise `directory` as a VOD directory.
|
--init: Initialise `directory` as a VOD directory.
|
||||||
--logout: Logs out of the current YouTube account.
|
--logout: Logs out of the current YouTube account.
|
||||||
-d, --deleteAfter: Deletes the full VOD after upload.
|
-d, --deleteAfter: Deletes the full VOD after upload.
|
||||||
|
--dry-run: Don't upload or modify any files (Useful with -v)
|
||||||
-f, --force: Force uploading the VOD, even if it already exists.
|
-f, --force: Force uploading the VOD, even if it already exists.
|
||||||
|
|
||||||
SOURCE: https://codeberg.org/arimelody/vodular
|
SOURCE: https://codeberg.org/arimelody/vodular
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue