aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortrizen <trizen@protonmail.com>2020-03-06 04:45:26 +0200
committerJesús <heckyel@hyperbola.info>2020-03-07 14:02:09 -0500
commit1cddf3aff73e53e07c816b9974347d4dbe8c33c3 (patch)
treefc99ae6378572a6014d0c3b63762268175b60640
parent82dacf03883cacbb27aad0fadee541e82684f299 (diff)
downloadfair-viewer-1cddf3aff73e53e07c816b9974347d4dbe8c33c3.tar.lz
fair-viewer-1cddf3aff73e53e07c816b9974347d4dbe8c33c3.tar.xz
fair-viewer-1cddf3aff73e53e07c816b9974347d4dbe8c33c3.zip
- Support for next pages of playlists from username. - Better detection for the last page of results.
Signed-off-by: Jesús <heckyel@hyperbola.info>
-rwxr-xr-xbin/fair-viewer15
-rwxr-xr-xbin/gtk-fair-viewer15
-rw-r--r--lib/WWW/FairViewer.pm42
-rw-r--r--lib/WWW/FairViewer/Utils.pm6
4 files changed, 43 insertions, 35 deletions
diff --git a/bin/fair-viewer b/bin/fair-viewer
index 83d35e2..76fb6a8 100755
--- a/bin/fair-viewer
+++ b/bin/fair-viewer
@@ -2269,7 +2269,14 @@ sub general_options {
my $callback = $args{sub};
my $results = $args{res};
my $info = $args{info};
- my $token = $args{token};
+
+ my $token = undef;
+ my $has_token = 0;
+
+ if (ref($info->{results}) eq 'HASH' and exists $info->{results}{continuation}) {
+ $has_token = 1;
+ $token = $info->{results}{continuation};
+ }
if (not defined($option)) {
return;
@@ -2279,9 +2286,9 @@ sub general_options {
main_quit(0);
}
elsif ($option =~ /^(?:n|next)\z/ and defined $url) {
- if (exists $args{token}) {
+ if ($has_token) {
if (defined $token) {
- my $request = $yv_obj->next_page_with_token($url, $token);
+ my $request = $yv_obj->next_page($url, $token);
$callback->($request);
}
else {
@@ -2639,7 +2646,6 @@ sub print_comments {
my $url = $results->{url};
my $comments = $results->{results}{comments} // [];
- my $token = $results->{results}{continuation};
my $i = 0;
foreach my $comment (@{$comments}) {
@@ -2698,7 +2704,6 @@ sub print_comments {
info => $results,
mode => 'comments',
args => [$videoID],
- token => $token,
)
) {
## ok
diff --git a/bin/gtk-fair-viewer b/bin/gtk-fair-viewer
index bc9c747..42ab174 100755
--- a/bin/gtk-fair-viewer
+++ b/bin/gtk-fair-viewer
@@ -2404,16 +2404,14 @@ sub make_row_description {
}
sub append_next_page {
- my ($url) = @_;
-
- #$token // return; # no next page is available
-
+ my ($url, $continuation) = @_;
my $iter = $liststore->append;
$liststore->set(
$iter,
0 => "<big><b>LOAD MORE</b></big>",
3 => $url,
+ 5 => $continuation,
7 => 'next_page',
);
}
@@ -2663,7 +2661,14 @@ sub display_results {
}
}
- append_next_page($url); #, #$info->{nextPageToken});
+ if (ref($results->{results}) eq 'HASH' and exists($results->{results}{continuation})) {
+ if (defined $results->{results}{continuation}) {
+ append_next_page($url, $results->{results}{continuation});
+ }
+ }
+ else {
+ append_next_page($url);
+ }
}
sub set_entry_tooltip {
diff --git a/lib/WWW/FairViewer.pm b/lib/WWW/FairViewer.pm
index e8040d4..47e87c4 100644
--- a/lib/WWW/FairViewer.pm
+++ b/lib/WWW/FairViewer.pm
@@ -1001,42 +1001,38 @@ sub post_as_json {
sub next_page_with_token {
my ($self, $url, $token) = @_;
- my $pt_url = (
- $url =~ s{[?&]continuation=\K([^&]+)}{$token}
- ? $url
- : $self->_append_url_args($url, continuation => $token)
- );
-
- my $res = $self->_get_results($pt_url);
- $res->{url} = $pt_url;
+ if (not $url =~ s{[?&]continuation=\K([^&]+)}{$token}) {
+ $url = $self->_append_url_args($url, continuation => $token);
+ }
+
+ my $res = $self->_get_results($url);
+ $res->{url} = $url;
return $res;
}
sub next_page {
- my ($self, $url) = @_;
+ my ($self, $url, $token) = @_;
- my $pt_url = (
- $url =~ s{[?&]page=\K(\d+)}{$1+1}e
- ? $url
- : $self->_append_url_args($url, page => 2)
- );
+ if ($token) {
+ return $self->next_page_with_token($url, $token);
+ }
+
+ if (not $url =~ s{[?&]page=\K(\d+)}{$1+1}e) {
+ $url = $self->_append_url_args($url, page => 2);
+ }
- my $res = $self->_get_results($pt_url);
- $res->{url} = $pt_url;
+ my $res = $self->_get_results($url);
+ $res->{url} = $url;
return $res;
}
sub previous_page {
my ($self, $url) = @_;
- my $pt_url = (
- $url =~ s{[?&]page=\K(\d+)}{($1 > 2) ? ($1-1) : 1}e
- ? $url
- : $url
- );
+ $url =~ s{[?&]page=\K(\d+)}{($1 > 2) ? ($1-1) : 1}e;
- my $res = $self->_get_results($pt_url);
- $res->{url} = $pt_url;
+ my $res = $self->_get_results($url);
+ $res->{url} = $url;
return $res;
}
diff --git a/lib/WWW/FairViewer/Utils.pm b/lib/WWW/FairViewer/Utils.pm
index 4e614f8..5ca1106 100644
--- a/lib/WWW/FairViewer/Utils.pm
+++ b/lib/WWW/FairViewer/Utils.pm
@@ -224,8 +224,10 @@ sub has_entries {
if (ref($result->{results}) eq 'HASH') {
- if (exists $result->{results}{comments}) {
- return scalar @{$result->{results}{comments}} > 0;
+ foreach my $type(qw(comments videos playlists)) {
+ if (exists $result->{results}{$type}) {
+ return scalar @{$result->{results}{$type}} > 0;
+ }
}
my $type = $result->{results}{type}//'';