diff options
Diffstat (limited to 'lib/WWW/FairViewer/Search.pm')
-rw-r--r-- | lib/WWW/FairViewer/Search.pm | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/WWW/FairViewer/Search.pm b/lib/WWW/FairViewer/Search.pm index 7242637..68f4521 100644 --- a/lib/WWW/FairViewer/Search.pm +++ b/lib/WWW/FairViewer/Search.pm @@ -6,7 +6,7 @@ use warnings; =head1 NAME -WWW::FairViewer::Search - Search functions for Fair API v3 +WWW::FairViewer::Search - Search for stuff on YouTube =head1 SYNOPSIS @@ -85,16 +85,26 @@ sub search_for { # Search in a channel's videos if (defined(my $channel_id = $self->get_channelId)) { - my $url = $self->_make_feed_url("channels/search/$channel_id", q => $keywords,); + + $self->set_channelId(); # clear the channel ID + + if (my $results = $self->yt_channel_search($channel_id, q => $keywords, type => $type, %$args)) { + return $results; + } + + my $url = $self->_make_feed_url("channels/search/$channel_id", q => $keywords); return $self->_get_results($url); } + if (my $results = $self->yt_search(q => $keywords, type => $type, %$args)) { + return $results; + } + my $url = $self->_make_search_url( type => $type, q => $keywords, - %$args, + %$args ); - return $self->_get_results($url); } @@ -161,15 +171,12 @@ be set to a YouTube video ID. sub related_to_videoID { my ($self, $videoID) = @_; - my %info = $self->_get_video_info($videoID); - my $watch_next_response = $self->parse_json_string($info{watch_next_response}); + my $watch_next_response = $self->parse_json_string($self->_get_video_next_info($videoID) // return {results => []}); + my $related = eval { $watch_next_response->{contents}{twoColumnWatchNextResults}{secondaryResults}{secondaryResults}{results} } // return {results => []}; - #use Data::Dump qw(pp); - #pp $related; - my @results; foreach my $entry (@$related) { |