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

@ -217,15 +217,17 @@ func main() {
}
// scan for thumbnail
var thumbnail *yt.Thumbnail
thumbnailPath, thumbnailSizeBytes, err := scanner.ScanThumbnail(directory)
if err != nil {
log.Fatalf("Failed to fetch thumbnail: %v", err)
os.Exit(1)
}
thumbnail := &yt.Thumbnail{
} else {
thumbnail = &yt.Thumbnail{
Filepath: thumbnailPath,
SizeBytes: thumbnailSizeBytes,
}
}
// build video template for upload
video, err := yt.BuildVideo(metadata)

View file

@ -2,6 +2,7 @@ package scanner
import (
"encoding/json"
"errors"
"fmt"
"os"
"path"
@ -65,6 +66,9 @@ func ScanThumbnail(directory string) (string, int64, error) {
thumbnailPath := path.Join(directory, "thumbnail.png")
stat, err := os.Stat(thumbnailPath)
if err != nil {
if os.IsNotExist(err) {
return "", 0, err
}
return "", 0, err
}
if stat.IsDir() {

View file

@ -285,14 +285,15 @@ func UploadVideo(
return nil, err
}
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
log.Printf("Failed to open thumbnail: %v\n", err)
return ytVideo, err
}
thumbnailSetCall.Media(thumbnailFile)
@ -307,6 +308,7 @@ func UploadVideo(
if err != nil {
log.Printf("Failed to upload thumbnail: %v\n", err)
}
}
return ytVideo, err
}