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