Skip to content

Commit

Permalink
fix empty thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
nikooo777 committed Jun 25, 2021
1 parent 3b84db3 commit 8fb1e2e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions sources/youtubeVideo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 4 additions & 6 deletions thumbs/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 8fb1e2e

Please sign in to comment.