diff options
author | trizen <trizen@protonmail.com> | 2020-10-05 13:14:38 +0300 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2020-11-09 16:03:11 -0500 |
commit | 76bf4687e70cc573ed4bb82fbdaa030d7b9e4d25 (patch) | |
tree | 5150439575f9b7a86c01e0a74908e449952ff726 /lib/WWW/FairViewer/Channels.pm | |
parent | bbe5dab9e37a2cd6f25edb09e2949ce7270b3784 (diff) | |
download | fair-viewer-76bf4687e70cc573ed4bb82fbdaa030d7b9e4d25.tar.lz fair-viewer-76bf4687e70cc573ed4bb82fbdaa030d7b9e4d25.tar.xz fair-viewer-76bf4687e70cc573ed4bb82fbdaa030d7b9e4d25.zip |
Implemented support for popular videos.
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'lib/WWW/FairViewer/Channels.pm')
-rw-r--r-- | lib/WWW/FairViewer/Channels.pm | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/WWW/FairViewer/Channels.pm b/lib/WWW/FairViewer/Channels.pm index b08bfac..c554044 100644 --- a/lib/WWW/FairViewer/Channels.pm +++ b/lib/WWW/FairViewer/Channels.pm @@ -33,6 +33,17 @@ sub videos_from_username { return $self->_get_results($self->_make_feed_url("channels/$channel_id/videos")); } +=head2 popular_videos($channel_id) + +Get the most popular videos for a given channel ID. + +=cut + +sub popular_videos { + my ($self, $channel_id) = @_; + return $self->_get_results($self->_make_feed_url("channels/$channel_id/videos", sort_by => 'popular')); +} + =head2 channels_from_categoryID($category_id) Return the YouTube channels associated with the specified category. @@ -131,15 +142,13 @@ Return the channel ID for an username. sub channel_id_from_username { my ($self, $username) = @_; - state $username_lookup = {}; - - if (exists $username_lookup->{$username}) { - return $username_lookup->{$username}; + # A channel's username (if it doesn't include spaces) is also valid in place of ucid. + if ($username =~ /\w/ and not $username =~ /\s/) { + return $username; } - $username_lookup->{$username} = undef; - my $channel = $self->channels_from_username($username) // return; - $username_lookup->{$username} = $channel->{results}{items}[0]{id} // return; + # TODO: resolve channel name to channel ID + return $username; } =head2 channel_title_from_id($channel_id) |