allow thumbnail.png to not exist
This commit is contained in:
parent
2fcbc31f77
commit
234caa159e
3 changed files with 30 additions and 22 deletions
6
main.go
6
main.go
|
|
@ -217,15 +217,17 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// scan for thumbnail
|
// scan for thumbnail
|
||||||
|
var thumbnail *yt.Thumbnail
|
||||||
thumbnailPath, thumbnailSizeBytes, err := scanner.ScanThumbnail(directory)
|
thumbnailPath, thumbnailSizeBytes, err := scanner.ScanThumbnail(directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to fetch thumbnail: %v", err)
|
log.Fatalf("Failed to fetch thumbnail: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
} else {
|
||||||
thumbnail := &yt.Thumbnail{
|
thumbnail = &yt.Thumbnail{
|
||||||
Filepath: thumbnailPath,
|
Filepath: thumbnailPath,
|
||||||
SizeBytes: thumbnailSizeBytes,
|
SizeBytes: thumbnailSizeBytes,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// build video template for upload
|
// build video template for upload
|
||||||
video, err := yt.BuildVideo(metadata)
|
video, err := yt.BuildVideo(metadata)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package scanner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -65,6 +66,9 @@ func ScanThumbnail(directory string) (string, int64, error) {
|
||||||
thumbnailPath := path.Join(directory, "thumbnail.png")
|
thumbnailPath := path.Join(directory, "thumbnail.png")
|
||||||
stat, err := os.Stat(thumbnailPath)
|
stat, err := os.Stat(thumbnailPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return "", 0, err
|
||||||
|
}
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
}
|
}
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
|
|
|
||||||
|
|
@ -285,14 +285,15 @@ func UploadVideo(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if thumbnail != nil {
|
||||||
// upload thumbnail
|
// upload thumbnail
|
||||||
|
|
||||||
thumbnailService := youtube.NewThumbnailsService(service)
|
thumbnailService := youtube.NewThumbnailsService(service)
|
||||||
thumbnailSetCall := thumbnailService.Set(ytVideo.Id)
|
thumbnailSetCall := thumbnailService.Set(ytVideo.Id)
|
||||||
thumbnailFile, err := os.Open(thumbnail.Filepath)
|
thumbnailFile, err := os.Open(thumbnail.Filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to open thumbnail: %v\n", err)
|
log.Printf("Failed to open thumbnail: %v\n", err)
|
||||||
return nil, err
|
return ytVideo, err
|
||||||
}
|
}
|
||||||
thumbnailSetCall.Media(thumbnailFile)
|
thumbnailSetCall.Media(thumbnailFile)
|
||||||
|
|
||||||
|
|
@ -307,6 +308,7 @@ func UploadVideo(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to upload thumbnail: %v\n", err)
|
log.Printf("Failed to upload thumbnail: %v\n", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ytVideo, err
|
return ytVideo, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue