aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WWW')
-rw-r--r--lib/WWW/StrawViewer.pm9
-rw-r--r--lib/WWW/StrawViewer/Channels.pm5
-rw-r--r--lib/WWW/StrawViewer/PlaylistItems.pm27
-rw-r--r--lib/WWW/StrawViewer/Utils.pm25
4 files changed, 41 insertions, 25 deletions
diff --git a/lib/WWW/StrawViewer.pm b/lib/WWW/StrawViewer.pm
index ecd31c9..336811e 100644
--- a/lib/WWW/StrawViewer.pm
+++ b/lib/WWW/StrawViewer.pm
@@ -485,7 +485,14 @@ sub default_arguments {
sub _make_feed_url {
my ($self, $path, %args) = @_;
- $self->get_feeds_url() . $path . '?' . $self->default_arguments(%args);
+ my $extra_args = $self->default_arguments(%args);
+ my $url = $self->get_feeds_url() . $path;
+
+ if ($extra_args) {
+ $url .= '?' . $extra_args;
+ }
+
+ return $url;
}
sub _extract_from_invidious {
diff --git a/lib/WWW/StrawViewer/Channels.pm b/lib/WWW/StrawViewer/Channels.pm
index d48c744..309aa07 100644
--- a/lib/WWW/StrawViewer/Channels.pm
+++ b/lib/WWW/StrawViewer/Channels.pm
@@ -23,6 +23,11 @@ sub _make_channels_url {
return $self->_make_feed_url('channels', %opts);
}
+sub videos_from_channel_id {
+ my ($self, $channel_id) = @_;
+ return $self->_get_results($self->_make_feed_url("channels/$channel_id/videos"));
+}
+
=head2 channels_from_categoryID($category_id)
Return the YouTube channels associated with the specified category.
diff --git a/lib/WWW/StrawViewer/PlaylistItems.pm b/lib/WWW/StrawViewer/PlaylistItems.pm
index 046e065..ab41a0d 100644
--- a/lib/WWW/StrawViewer/PlaylistItems.pm
+++ b/lib/WWW/StrawViewer/PlaylistItems.pm
@@ -80,18 +80,7 @@ Get videos from a specific playlistID.
sub videos_from_playlist_id {
my ($self, $id) = @_;
- return $self->_get_results($self->_make_playlistItems_url(playlistId => $id, part => 'contentDetails,snippet'));
-}
-
-=head2 videos_from_id($playlist_id)
-
-Get videos from a specific playlistID.
-
-=cut
-
-sub playlists_from_id {
- my ($self, $id) = @_;
- return $self->_get_results($self->_make_playlistItems_url(id => $id));
+ $self->_get_results($self->_make_feed_url("playlists/$id"));
}
=head2 favorites($channel_id)
@@ -120,22 +109,12 @@ Get the favorites, uploads and likes for a given YouTube username.
*{__PACKAGE__ . '::' . $name . '_from_username'} = sub {
my ($self, $username) = @_;
- my $playlist_id = $self->get_playlist_id(
- $name, $username
- ? (forUsername => $username)
- : do { $self->get_access_token() // return; (mine => 'true') }
- ) // return;
- $self->videos_from_playlist_id($playlist_id);
+ $self->videos_from_username($username);
};
*{__PACKAGE__ . '::' . $name} = sub {
my ($self, $channel_id) = @_;
- my $playlist_id = $self->get_playlist_id(
- $name, ($channel_id and $channel_id ne 'mine')
- ? (id => $channel_id)
- : do { $self->get_access_token() // return; (mine => 'true') }
- ) // return;
- $self->videos_from_playlist_id($playlist_id);
+ $self->videos_from_channel_id($channel_id);
};
}
}
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') {