aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW/FairViewer/Videos.pm
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2020-03-02 08:18:54 -0500
committerJesús <heckyel@hyperbola.info>2020-03-02 08:18:54 -0500
commitc67158fa409f1b1b4f98a8621a69bb2013b76451 (patch)
treebb4ca80f29cda70734a868d372e00c85e172e7d3 /lib/WWW/FairViewer/Videos.pm
parentad7ec1785fc28799e10d10e7a679dc5bb4891ee3 (diff)
downloadfair-viewer-c67158fa409f1b1b4f98a8621a69bb2013b76451.tar.lz
fair-viewer-c67158fa409f1b1b4f98a8621a69bb2013b76451.tar.xz
fair-viewer-c67158fa409f1b1b4f98a8621a69bb2013b76451.zip
rebrand app
Diffstat (limited to 'lib/WWW/FairViewer/Videos.pm')
-rw-r--r--lib/WWW/FairViewer/Videos.pm230
1 files changed, 230 insertions, 0 deletions
diff --git a/lib/WWW/FairViewer/Videos.pm b/lib/WWW/FairViewer/Videos.pm
new file mode 100644
index 0000000..3e44b52
--- /dev/null
+++ b/lib/WWW/FairViewer/Videos.pm
@@ -0,0 +1,230 @@
+package WWW::FairViewer::Videos;
+
+use utf8;
+use 5.014;
+use warnings;
+
+=head1 NAME
+
+WWW::FairViewer::Videos - videos handler.
+
+=head1 SYNOPSIS
+
+ use WWW::FairViewer;
+ my $obj = WWW::FairViewer->new(%opts);
+ my $info = $obj->video_details($videoID);
+
+=head1 SUBROUTINES/METHODS
+
+=cut
+
+sub _make_videos_url {
+ my ($self, %opts) = @_;
+ return $self->_make_feed_url('videos', %opts);
+}
+
+{
+ no strict 'refs';
+ foreach my $part (
+ qw(
+ id
+ snippet
+ contentDetails
+ fileDetails
+ player
+ liveStreamingDetails
+ processingDetails
+ recordingDetails
+ statistics
+ status
+ suggestions
+ topicDetails
+ )
+ ) {
+ *{__PACKAGE__ . '::' . 'video_' . $part} = sub {
+ my ($self, $id) = @_;
+ return $self->_get_results($self->_make_videos_url(id => $id, part => $part));
+ };
+ }
+}
+
+=head2 videos_from_category($category_id)
+
+Get videos from a category ID.
+
+=cut
+
+sub videos_from_category {
+ my ($self, $cat_id) = @_;
+ $self->_get_results(
+ $self->_make_videos_url(
+ chart => $self->get_chart,
+ videoCategoryId => $cat_id,
+ )
+ );
+}
+
+=head2 trending_videos_from_category($category_id)
+
+Get popular videos from a category ID.
+
+=cut
+
+sub trending_videos_from_category {
+ my ($self, $cat_id) = @_;
+
+ my $results = do {
+ local $self->{publishedAfter} = do {
+ state $yv_utils = WWW::FairViewer::Utils->new;
+ $yv_utils->period_to_date(1, 'w');
+ } if !defined($self->get_publishedAfter);
+ local $self->{videoCategoryId} = $cat_id;
+ local $self->{regionCode} = "US" if !defined($self->get_regionCode);
+ $self->search_videos("");
+ };
+
+ return $results;
+}
+
+=head2 popular_videos($channel_id)
+
+Get the most popular videos for a given channel ID.
+
+=cut
+
+sub popular_videos {
+ my ($self, $id) = @_;
+
+ my $results = do {
+ local $self->{channelId} = $id;
+ local $self->{order} = 'viewCount';
+ $self->search_videos("");
+ };
+
+ return $results;
+}
+
+=head2 my_likes()
+
+Get the videos liked by the authenticated user.
+
+=cut
+
+sub my_likes {
+ my ($self) = @_;
+ $self->get_access_token() // return;
+ $self->_get_results($self->_make_videos_url(myRating => 'like', pageToken => $self->page_token));
+}
+
+=head2 my_dislikes()
+
+Get the videos disliked by the authenticated user.
+
+=cut
+
+sub my_dislikes {
+ my ($self) = @_;
+ $self->get_access_token() // return;
+ $self->_get_results($self->_make_videos_url(myRating => 'dislike', pageToken => $self->page_token));
+}
+
+=head2 send_rating_to_video($videoID, $rating)
+
+Send rating to a video. $rating can be either 'like' or 'dislike'.
+
+=cut
+
+sub send_rating_to_video {
+ my ($self, $video_id, $rating) = @_;
+
+ if ($rating eq 'none' or $rating eq 'like' or $rating eq 'dislike') {
+ my $url = $self->_simple_feeds_url('videos/rate', id => $video_id, rating => $rating);
+ return defined($self->lwp_post($url, $self->_auth_lwp_header()));
+ }
+
+ return;
+}
+
+=head2 like_video($videoID)
+
+Like a video. Returns true on success.
+
+=cut
+
+sub like_video {
+ my ($self, $video_id) = @_;
+ $self->send_rating_to_video($video_id, 'like');
+}
+
+=head2 dislike_video($videoID)
+
+Dislike a video. Returns true on success.
+
+=cut
+
+sub dislike_video {
+ my ($self, $video_id) = @_;
+ $self->send_rating_to_video($video_id, 'dislike');
+}
+
+=head2 videos_details($id, $part)
+
+Get info about a videoID, such as: channelId, title, description,
+tags, and categoryId.
+
+Available values for I<part> are: I<id>, I<snippet>, I<contentDetails>
+I<player>, I<statistics>, I<status> and I<topicDetails>.
+
+C<$part> string can contain more values, comma-separated.
+
+Example:
+
+ part => 'snippet,contentDetails,statistics'
+
+When C<$part> is C<undef>, it defaults to I<snippet>.
+
+=cut
+
+sub video_details {
+ my ($self, $id, $fields) = @_;
+ $fields //= $self->basic_video_info_fields;
+ $self->_get_results($self->_make_feed_url("videos/$id", fields => $fields));
+}
+
+=head2 Return details
+
+Each function returns a HASH ref, with a key called 'results', and another key, called 'url'.
+
+The 'url' key contains a string, which is the URL for the retrieved content.
+
+The 'results' key contains another HASH ref with the keys 'etag', 'items' and 'kind'.
+From the 'results' key, only the 'items' are relevant to us. This key contains an ARRAY ref,
+with a HASH ref for each result. An example of the item array's content are shown below.
+
+=cut
+
+=head1 AUTHOR
+
+Trizen, C<< <echo dHJpemVuQHByb3Rvbm1haWwuY29tCg== | base64 -d> >>
+
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc WWW::FairViewer::Videos
+
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2013-2015 Trizen.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See L<http://dev.perl.org/licenses/> for more information.
+
+=cut
+
+1; # End of WWW::FairViewer::Videos