diff options
author | trizen <trizen@protonmail.com> | 2020-11-01 00:55:39 +0200 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2020-11-09 17:36:03 -0500 |
commit | 1beb25dc7752554f3f0dc585b98c57ec1cd7e121 (patch) | |
tree | 286fafbc7b6ea871813437c19827d432664fc01c | |
parent | 383aa38991ab0166a985f6a8e24697fb6af8a8f7 (diff) | |
download | fair-viewer-1beb25dc7752554f3f0dc585b98c57ec1cd7e121.tar.lz fair-viewer-1beb25dc7752554f3f0dc585b98c57ec1cd7e121.tar.xz fair-viewer-1beb25dc7752554f3f0dc585b98c57ec1cd7e121.zip |
- Fixed some potential corner-cases in the selection of thumbnails.
Also fixes the thumbnails for mixes.
Signed-off-by: Jesús <heckyel@hyperbola.info>
-rw-r--r-- | lib/WWW/FairViewer/Utils.pm | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/WWW/FairViewer/Utils.pm b/lib/WWW/FairViewer/Utils.pm index 0aaac4f..ccb5800 100644 --- a/lib/WWW/FairViewer/Utils.pm +++ b/lib/WWW/FairViewer/Utils.pm @@ -522,22 +522,29 @@ sub get_thumbnail_url { if ($info->{type} eq 'channel') { ref($info->{authorThumbnails}) eq 'ARRAY' or return ''; - return $info->{authorThumbnails}[0]{url}; + + foreach my $thumbnail (map { ref($_) eq 'ARRAY' ? @{$_} : $_ } @{$info->{authorThumbnails}}) { + if (exists $thumbnail->{quality} and $thumbnail->{quality} eq $type) { + return $thumbnail->{url}; + } + } + + return eval { $info->{authorThumbnails}[0]{url} } // ''; } ref($info->{videoThumbnails}) eq 'ARRAY' or return ''; - my @thumbs = @{$info->{videoThumbnails}}; - my @wanted = grep { $_->{quality} eq $type } @thumbs; + my @thumbs = map { ref($_) eq 'ARRAY' ? @{$_} : $_ } @{$info->{videoThumbnails}}; + my @wanted = grep { $_->{quality} eq $type } grep { ref($_) eq 'HASH' } @thumbs; my $url; if (@wanted) { - $url = $wanted[0]{url}; + $url = eval { $wanted[0]{url} } // return ''; } else { warn "[!] Couldn't find thumbnail of type <<$type>>..."; - $url = $thumbs[0]{url}; + $url = eval { $thumbs[0]{url} } // return ''; } # Clean URL of trackers and other junk @@ -773,7 +780,11 @@ sub get_comments { my ($self, $item) = @_; if ($pair->[0] eq 'video') { - return 1 if exists $item->{videoId}; + return 1 if defined $item->{videoId}; + } + + if ($pair->[0] eq 'playlist') { + return 1 if defined $item->{playlistId}; } exists $pair->[1]{$item->{type} // ''}; |