aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WWW')
-rw-r--r--lib/WWW/FairViewer.pm19
-rw-r--r--lib/WWW/FairViewer/Channels.pm5
-rw-r--r--lib/WWW/FairViewer/GuideCategories.pm2
-rw-r--r--lib/WWW/FairViewer/VideoCategories.pm48
-rw-r--r--lib/WWW/FairViewer/Videos.pm31
5 files changed, 31 insertions, 74 deletions
diff --git a/lib/WWW/FairViewer.pm b/lib/WWW/FairViewer.pm
index d7be54c..8d8abff 100644
--- a/lib/WWW/FairViewer.pm
+++ b/lib/WWW/FairViewer.pm
@@ -50,7 +50,6 @@ my %valid_options = (
v => {valid => q[], default => 3},
page => {valid => qr/^(?!0+\z)\d+\z/, default => 1},
http_proxy => {valid => qr/./, default => undef},
- hl => {valid => qr/^\w+(?:[\-_]\w+)?\z/, default => undef},
maxResults => {valid => [1 .. 50], default => 10},
order => {valid => [qw(relevance rating upload_date view_count)], default => undef},
date => {valid => [qw(hour today week month year)], default => undef},
@@ -283,7 +282,7 @@ sub set_lwp_useragent {
// do { require LWP::UserAgent; 'LWP::UserAgent' }
);
- $self->{lwp} = $lwp->new(
+ my $agent = $lwp->new(
cookie_jar => {}, # temporary cookies
timeout => $self->get_timeout,
@@ -329,7 +328,6 @@ sub set_lwp_useragent {
HTTP::Message::decodable();
};
- my $agent = $self->{lwp};
$agent->ssl_opts(Timeout => $self->get_timeout);
$agent->default_header('Accept-Encoding' => $accepted_encodings);
$agent->conn_cache($cache);
@@ -366,8 +364,9 @@ sub set_lwp_useragent {
$agent->cookie_jar($cookies);
}
- push @{$self->{lwp}->requests_redirectable}, 'POST';
- return $self->{lwp};
+ push @{$agent->requests_redirectable}, 'POST';
+ $self->{lwp} = $agent;
+ return $agent;
}
=head2 prepare_access_token()
@@ -399,7 +398,7 @@ sub _auth_lwp_header {
sub _warn_reponse_error {
my ($resp, $url) = @_;
- warn sprintf("[%s] Error occurred on URL: %s\n", $resp->status_line, $url =~ s/([&?])key=(.*?)&/${1}key=[...]&/r);
+ warn sprintf("[%s] Error occurred on URL: %s\n", $resp->status_line, $url);
}
=head2 lwp_get($url, %opt)
@@ -463,7 +462,7 @@ sub lwp_get {
$opt{depth} ||= 0;
# Try again on 500+ HTTP errors
- if ( $opt{depth} <= 3
+ if ( $opt{depth} < 3
and $response->code() >= 500
and $response->status_line() =~ /(?:Temporary|Server) Error|Timeout|Service Unavailable/i) {
return $self->lwp_get($url, %opt, depth => $opt{depth} + 1);
@@ -581,7 +580,7 @@ sub select_good_invidious_instances {
my %ignored = (
'yewtu.be' => 1,
- 'invidiou.site' => 0,
+ 'invidiou.site' => 1,
'invidious.xyz' => 1,
'vid.mint.lgbt' => 1,
'invidious.ggc-project.de' => 1,
@@ -704,7 +703,6 @@ sub _extract_from_invidious {
require List::Util;
@instances = List::Util::shuffle(map { $_->[0] } @instances);
push @instances, 'invidious.snopyta.org';
- push @instances, 'invidious.13ad.de';
}
else {
@instances = qw(
@@ -712,7 +710,6 @@ sub _extract_from_invidious {
invidious.site
invidious.fdn.fr
invidious.snopyta.org
- invidious.13ad.de
);
}
@@ -1240,6 +1237,8 @@ sub previous_page {
local $ENV{HTTP_PROXY} = $self->{lwp}->proxy('http');
local $ENV{HTTPS_PROXY} = $self->{lwp}->proxy('https');
+ local $" = " ";
+
$name eq 'exec' ? exec(@args)
: $name eq 'system' ? system(@args)
: $name eq 'stdout' ? qx(@args)
diff --git a/lib/WWW/FairViewer/Channels.pm b/lib/WWW/FairViewer/Channels.pm
index c554044..3ee44d4 100644
--- a/lib/WWW/FairViewer/Channels.pm
+++ b/lib/WWW/FairViewer/Channels.pm
@@ -41,6 +41,11 @@ Get the most popular videos for a given channel ID.
sub popular_videos {
my ($self, $channel_id) = @_;
+
+ if (not defined($channel_id)) { # trending popular videos
+ return $self->_get_results($self->_make_feed_url('popular'));
+ }
+
return $self->_get_results($self->_make_feed_url("channels/$channel_id/videos", sort_by => 'popular'));
}
diff --git a/lib/WWW/FairViewer/GuideCategories.pm b/lib/WWW/FairViewer/GuideCategories.pm
index a348abb..cead9f6 100644
--- a/lib/WWW/FairViewer/GuideCategories.pm
+++ b/lib/WWW/FairViewer/GuideCategories.pm
@@ -25,7 +25,7 @@ sub _make_guideCategories_url {
$opts{region} //= $self->get_region;
}
- $self->_make_feed_url('guideCategories', hl => $self->get_hl, %opts);
+ $self->_make_feed_url('guideCategories', %opts);
}
=head2 guide_categories(;$region_id)
diff --git a/lib/WWW/FairViewer/VideoCategories.pm b/lib/WWW/FairViewer/VideoCategories.pm
index 85045fd..4dfc125 100644
--- a/lib/WWW/FairViewer/VideoCategories.pm
+++ b/lib/WWW/FairViewer/VideoCategories.pm
@@ -18,16 +18,6 @@ WWW::FairViewer::VideoCategories - videoCategory resource handler.
=cut
-sub _make_videoCategories_url {
- my ($self, %opts) = @_;
-
- $self->_make_feed_url(
- 'videoCategories',
- hl => $self->get_hl,
- %opts,
- );
-}
-
=head2 video_categories()
Return video categories for a specific region ID.
@@ -37,37 +27,13 @@ Return video categories for a specific region ID.
sub video_categories {
my ($self) = @_;
- require File::Spec;
-
- my $region = $self->get_region() // 'US';
- my $url = $self->_make_videoCategories_url(region => $region);
- my $file = File::Spec->catfile($self->get_config_dir, "categories-$region-" . $self->get_hl() . ".json");
-
- my $json;
- if (open(my $fh, '<:utf8', $file)) {
- local $/;
- $json = <$fh>;
- close $fh;
- }
- else {
- $json = $self->lwp_get($url, simple => 1);
- open my $fh, '>:utf8', $file;
- print {$fh} $json;
- close $fh;
- }
-
- return $self->parse_json_string($json);
-}
-
-=head2 video_category_id_info($cagegory_id)
-
-Return info for the comma-separated specified category ID(s).
-
-=cut
-
-sub video_category_id_info {
- my ($self, $id) = @_;
- return $self->_get_results($self->_make_videoCategories_url(id => $id));
+ return [{id => "music", title => "Music"},
+ {id => "gaming", title => "Gaming"},
+ {id => "news", title => "News"},
+ {id => "movies", title => "Movies"},
+ {id => "trending", title => "Trending"},
+ {id => "popular", title => "Popular"},
+ ];
}
=head1 AUTHOR
diff --git a/lib/WWW/FairViewer/Videos.pm b/lib/WWW/FairViewer/Videos.pm
index aaaacc7..4acd866 100644
--- a/lib/WWW/FairViewer/Videos.pm
+++ b/lib/WWW/FairViewer/Videos.pm
@@ -48,22 +48,6 @@ sub _make_videos_url {
}
}
-=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.
@@ -71,14 +55,17 @@ Get popular videos from a category ID.
=cut
sub trending_videos_from_category {
- my ($self, $cat_id) = @_;
+ my ($self, $category) = @_;
+
+ if (defined($category) and $category eq 'popular') {
+ return $self->popular_videos;
+ }
- my $results = do {
- local $self->{videoCategoryId} = $cat_id;
- $self->search_videos("");
- };
+ if (defined($category) and $category eq 'trending') {
+ $category = undef;
+ }
- return $results;
+ return $self->_get_results($self->_make_feed_url('trending', (defined($category) ? (type => $category) : ())));
}
=head2 my_likes()