aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW/StrawViewer/Utils.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WWW/StrawViewer/Utils.pm')
-rw-r--r--lib/WWW/StrawViewer/Utils.pm25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/WWW/StrawViewer/Utils.pm b/lib/WWW/StrawViewer/Utils.pm
index f3855b8..87a7ac0 100644
--- a/lib/WWW/StrawViewer/Utils.pm
+++ b/lib/WWW/StrawViewer/Utils.pm
@@ -221,6 +221,11 @@ Returns true if a given result has entries.
sub has_entries {
my ($self, $result) = @_;
+
+ if (ref($result->{results}) eq 'HASH' and $result->{results}{type} eq 'playlist') {
+ return $result->{results}{videoCount} > 0;
+ }
+
scalar(@{$result->{results}}) > 0;
#ref($result) eq 'HASH' and ($result->{results}{pageInfo}{totalResults} > 0);
}
@@ -450,6 +455,22 @@ Get thumbnail URL.
sub get_thumbnail_url {
my ($self, $info, $type) = @_;
+
+ if (exists $info->{videoId}) {
+ $info->{type} = 'video';
+ }
+
+ if ($info->{type} eq 'playlist') {
+ return $info->{playlistThumbnail};
+ }
+
+ if ($info->{type} eq 'channel') {
+ ref($info->{authorThumbnails}) eq 'ARRAY' or return '';
+ return $info->{authorThumbnails}[0]{url};
+ }
+
+ ref($info->{videoThumbnails}) eq 'ARRAY' or return '';
+
my @thumbs = @{$info->{videoThumbnails}};
my @wanted = grep{$_->{quality} eq $type} @thumbs;
@@ -655,6 +676,10 @@ sub get_comments {
*{__PACKAGE__ . '::' . 'is_' . $pair->[0]} = sub {
my ($self, $item) = @_;
+ if ($pair->[0] eq 'video') {
+ return 1 if exists $item->{videoId};
+ }
+
exists $pair->[1]{$item->{type} // ''};
#~ if (ref($item->{id}) eq 'HASH') {