From 1beb25dc7752554f3f0dc585b98c57ec1cd7e121 Mon Sep 17 00:00:00 2001 From: trizen Date: Sun, 1 Nov 2020 00:55:39 +0200 Subject: - Fixed some potential corner-cases in the selection of thumbnails. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fixes the thumbnails for mixes. Signed-off-by: Jesús --- lib/WWW/FairViewer/Utils.pm | 23 +++++++++++++++++------ 1 file 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} // ''}; -- cgit v1.2.3