From 8fb1e2ead0d522e280ce148e36568adc727ee41c Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Fri, 25 Jun 2021 19:04:40 +0200 Subject: [PATCH] fix empty thumbnails --- shared/shared.go | 1 + sources/youtubeVideo.go | 3 +++ thumbs/uploader.go | 10 ++++------ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/shared/shared.go b/shared/shared.go index b142e42..10474e5 100644 --- a/shared/shared.go +++ b/shared/shared.go @@ -90,6 +90,7 @@ var ErrorsNoRetry = []string{ "This video has been removed by the uploader", "Premiere will begin shortly", "cannot unmarshal number 0.0", + "default youtube thumbnail found", } var WalletErrors = []string{ "Not enough funds to cover this transaction", diff --git a/sources/youtubeVideo.go b/sources/youtubeVideo.go index 734bfda..7ed5a37 100644 --- a/sources/youtubeVideo.go +++ b/sources/youtubeVideo.go @@ -683,6 +683,9 @@ func (v *YoutubeVideo) delete(reason string) error { func (v *YoutubeVideo) triggerThumbnailSave() (err error) { thumbnail := thumbs.GetBestThumbnail(v.youtubeInfo.Thumbnails) + if thumbnail.Width == 0 { + return errors.Err("default youtube thumbnail found") + } v.thumbnailURL, err = thumbs.MirrorThumbnail(thumbnail.URL, v.ID(), v.awsConfig) return err } diff --git a/thumbs/uploader.go b/thumbs/uploader.go index 9197c44..e293a6b 100644 --- a/thumbs/uploader.go +++ b/thumbs/uploader.go @@ -117,13 +117,11 @@ func MirrorThumbnail(url string, name string, s3Config aws.Config) (string, erro } func GetBestThumbnail(thumbnails []ytdl.Thumbnail) *ytdl.Thumbnail { - var bestWidth *ytdl.Thumbnail + var bestWidth ytdl.Thumbnail for _, thumbnail := range thumbnails { - if bestWidth == nil { - bestWidth = &thumbnail - } else if bestWidth.Width < thumbnail.Width { - bestWidth = &thumbnail + if bestWidth.Width < thumbnail.Width { + bestWidth = thumbnail } } - return bestWidth + return &bestWidth }