aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortrizen <trizen@protonmail.com>2020-02-27 08:31:20 +0200
committertrizen <trizen@protonmail.com>2020-02-27 08:31:20 +0200
commit3bb78645fd553b3d58b222931c4828e373cc49c3 (patch)
tree673d629ff8f876279e74d61250252daa0d8a6a78
parent1659520ed4f2bf9a3039a5c59218fa32fddb6580 (diff)
downloadfair-viewer-3bb78645fd553b3d58b222931c4828e373cc49c3.tar.lz
fair-viewer-3bb78645fd553b3d58b222931c4828e373cc49c3.tar.xz
fair-viewer-3bb78645fd553b3d58b222931c4828e373cc49c3.zip
- Added support for next pages of results. (fixes https://github.com/trizen/straw-viewer/issues/1)
-rw-r--r--README.md2
-rwxr-xr-xbin/gtk-straw-viewer9
-rw-r--r--lib/WWW/StrawViewer.pm47
3 files changed, 34 insertions, 24 deletions
diff --git a/README.md b/README.md
index 85aa7f5..2984c4b 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ A lightweight application for searching and streaming videos from YouTube, using
### STATUS
-The project is in its early development stages and some features are not implemented yet.
+The project is in its early stages of development and some features are not implemented yet.
### AVAILABILITY
diff --git a/bin/gtk-straw-viewer b/bin/gtk-straw-viewer
index c1f9b5d..bd21d26 100755
--- a/bin/gtk-straw-viewer
+++ b/bin/gtk-straw-viewer
@@ -2395,9 +2395,9 @@ sub make_row_description {
}
sub append_next_page {
- my ($url, $token) = @_;
+ my ($url) = @_;
- $token // return; # no next page is available
+ #$token // return; # no next page is available
my $iter = $liststore->append;
@@ -2405,7 +2405,6 @@ sub append_next_page {
$iter,
0 => "<big><b>LOAD MORE</b></big>",
3 => $url,
- 5 => $token,
7 => 'next_page',
);
}
@@ -3305,9 +3304,9 @@ sub comments_row_activated {
if (defined($url) and $url =~ m{^https?://}) { # load more comments
- my $token = $feeds_liststore->get($iter, 2);
+ #my $token = $feeds_liststore->get($iter, 2);
$feeds_liststore->remove($iter);
- my $results = $yv_obj->next_page($url, $token);
+ my $results = $yv_obj->next_page($url);
if ($yv_utils->has_entries($results)) {
display_comments($results);
diff --git a/lib/WWW/StrawViewer.pm b/lib/WWW/StrawViewer.pm
index 99331d5..5f0ae02 100644
--- a/lib/WWW/StrawViewer.pm
+++ b/lib/WWW/StrawViewer.pm
@@ -271,7 +271,7 @@ sub set_lwp_useragent {
$self->{lwp} = $lwp->new(
- cookie_jar => {}, # temporary cookies
+ cookie_jar => {}, # temporary cookies
timeout => $self->get_lwp_timeout,
show_progress => $self->get_debug,
agent => $self->get_lwp_agent,
@@ -998,26 +998,37 @@ sub post_as_json {
$self->_save('POST', $url, $json_str);
}
-# SUBROUTINE FACTORY
-{
- no strict 'refs';
+sub next_page {
+ my ($self, $url) = @_;
- # Create {next,previous}_page subroutines
- foreach my $name ('next_page', 'previous_page') {
- *{__PACKAGE__ . '::' . $name} = sub {
- my ($self, $url, $token) = @_;
+ my $pt_url = (
+ $url =~ s{[?&]page=\K(\d+)}{$1+1}e
+ ? $url
+ : $self->_append_url_args($url, page => 2)
+ );
- my $pt_url = (
- $url =~ s/[?&]pageToken=\K[^&]+/$token/
- ? $url
- : $self->_append_url_args($url, pageToken => $token)
- );
+ my $res = $self->_get_results($pt_url);
+ $res->{url} = $pt_url;
+ return $res;
+}
- my $res = $self->_get_results($pt_url);
- $res->{url} = $pt_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
+ );
+
+ my $res = $self->_get_results($pt_url);
+ $res->{url} = $pt_url;
+ return $res;
+}
+
+# SUBROUTINE FACTORY
+{
+ no strict 'refs';
# Create proxy_{exec,system} subroutines
foreach my $name ('exec', 'system', 'stdout') {