allow thumbnail.png to not exist

This commit is contained in:
ari melody 2026-06-23 19:07:51 +01:00
parent 2fcbc31f77
commit 234caa159e
Signed by: ari
GPG key ID: 60B5F0386E3DDB7E
3 changed files with 30 additions and 22 deletions

View file

@ -285,27 +285,29 @@ func UploadVideo(
return nil, err
}
// upload thumbnail
if thumbnail != nil {
// upload thumbnail
thumbnailService := youtube.NewThumbnailsService(service)
thumbnailSetCall := thumbnailService.Set(ytVideo.Id)
thumbnailFile, err := os.Open(thumbnail.Filepath)
if err != nil {
log.Fatalf("Failed to open thumbnail: %v\n", err)
return nil, err
}
thumbnailSetCall.Media(thumbnailFile)
thumbnailService := youtube.NewThumbnailsService(service)
thumbnailSetCall := thumbnailService.Set(ytVideo.Id)
thumbnailFile, err := os.Open(thumbnail.Filepath)
if err != nil {
log.Printf("Failed to open thumbnail: %v\n", err)
return ytVideo, err
}
thumbnailSetCall.Media(thumbnailFile)
log.Println("Uploading thumbnail...")
log.Println("Uploading thumbnail...")
thumbnailSetCall.ProgressUpdater(func(current, total int64) {
if total == 0 { total = thumbnail.SizeBytes }
fmt.Printf("\t(%.2f%%)\n", float64(current) / float64(total) * 100)
})
// kinda don't care about the response here- so long as it works!
_, err = thumbnailSetCall.Do()
if err != nil {
log.Printf("Failed to upload thumbnail: %v\n", err)
thumbnailSetCall.ProgressUpdater(func(current, total int64) {
if total == 0 { total = thumbnail.SizeBytes }
fmt.Printf("\t(%.2f%%)\n", float64(current) / float64(total) * 100)
})
// kinda don't care about the response here- so long as it works!
_, err = thumbnailSetCall.Do()
if err != nil {
log.Printf("Failed to upload thumbnail: %v\n", err)
}
}
return ytVideo, err