diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/WWW/StrawViewer.pm | 16 | ||||
-rw-r--r-- | lib/WWW/StrawViewer/CommentThreads.pm | 13 | ||||
-rw-r--r-- | lib/WWW/StrawViewer/Utils.pm | 44 |
3 files changed, 52 insertions, 21 deletions
diff --git a/lib/WWW/StrawViewer.pm b/lib/WWW/StrawViewer.pm index 336811e..42206d1 100644 --- a/lib/WWW/StrawViewer.pm +++ b/lib/WWW/StrawViewer.pm @@ -69,7 +69,7 @@ my %valid_options = ( safeSearch => {valid => [qw(none moderate strict)], default => undef}, videoType => {valid => [qw(any episode movie)], default => undef}, - comments_order => {valid => [qw(time relevance)], default => 'time'}, + comments_order => {valid => [qw(top new)], default => 'top'}, subscriptions_order => {valid => [qw(alphabetical relevance unread)], default => undef}, # Misc @@ -95,9 +95,10 @@ my %valid_options = ( refresh_token => {valid => [qr/^.{15}/], default => undef}, authentication_file => {valid => [qr/^./], default => undef}, + api_host => {valid => [qr{^https?://}], default => "https://invidio.us"}, # No input value allowed - feeds_url => {valid => q[], default => 'https://invidio.us/api/v1/'}, + api_path => {valid => q[], default => '/api/v1/'}, video_info_url => {valid => q[], default => 'https://www.youtube.com/get_video_info'}, oauth_url => {valid => q[], default => 'https://accounts.google.com/o/oauth2/'}, video_info_args => {valid => q[], default => '?video_id=%s&el=detailpage&ps=default&eurl=&gl=US&hl=en'}, @@ -457,9 +458,14 @@ sub _append_url_args { : $url; } +sub get_api_url { + my ($self) = @_; + join('', $self->get_api_host, $self->get_api_path); +} + sub _simple_feeds_url { - my ($self, $suburl, %args) = @_; - $self->get_feeds_url() . $suburl . '?' . $self->list_to_url_arguments(key => $self->get_key, %args); + my ($self, $path, %args) = @_; + $self->get_api_url . $path . '?' . $self->list_to_url_arguments(key => $self->get_key, %args); } =head2 default_arguments(%args) @@ -486,7 +492,7 @@ sub default_arguments { sub _make_feed_url { my ($self, $path, %args) = @_; my $extra_args = $self->default_arguments(%args); - my $url = $self->get_feeds_url() . $path; + my $url = $self->get_api_url . $path; if ($extra_args) { $url .= '?' . $extra_args; diff --git a/lib/WWW/StrawViewer/CommentThreads.pm b/lib/WWW/StrawViewer/CommentThreads.pm index 499d930..1eba143 100644 --- a/lib/WWW/StrawViewer/CommentThreads.pm +++ b/lib/WWW/StrawViewer/CommentThreads.pm @@ -36,15 +36,10 @@ Retrieve comments from a video ID. sub comments_from_video_id { my ($self, $video_id) = @_; - return - $self->_get_results( - $self->_make_commentThreads_url( - videoId => $video_id, - textFormat => 'plainText', - order => $self->get_comments_order, - part => 'snippet,replies' - ), - simple => 1, + $self->_get_results( + $self->_make_feed_url("comments/$video_id", + sort_by => $self->get_comments_order, + ), ); } diff --git a/lib/WWW/StrawViewer/Utils.pm b/lib/WWW/StrawViewer/Utils.pm index 87a7ac0..062bbe1 100644 --- a/lib/WWW/StrawViewer/Utils.pm +++ b/lib/WWW/StrawViewer/Utils.pm @@ -222,8 +222,15 @@ Returns true if a given result has entries. sub has_entries { my ($self, $result) = @_; - if (ref($result->{results}) eq 'HASH' and $result->{results}{type} eq 'playlist') { - return $result->{results}{videoCount} > 0; + if (ref($result->{results}) eq 'HASH') { + + if (exists $result->{results}{comments}) { + return scalar @{$result->{results}{comments}} > 0; + } + + if ($result->{results}{type} eq 'playlist') { + return $result->{results}{videoCount} > 0; + } } scalar(@{$result->{results}}) > 0; @@ -424,6 +431,11 @@ sub get_playlist_id { $info->{playlistId}; } +sub get_playlist_video_count { + my ($self, $info) = @_; + $info->{videoCount}; +} + =head2 get_description($info) Get description. @@ -488,6 +500,21 @@ sub get_channel_title { $info->{author}; } +sub get_author { + my ($self, $info) = @_; + $info->{author}; +} + +sub get_comment_id { + my ($self, $info) = @_; + $info->{commentId}; +} + +sub get_comment_content { + my ($self, $info) = @_; + $info->{content}; +} + sub get_id { my ($self, $info) = @_; #$info->{id}; @@ -541,13 +568,13 @@ sub get_publication_date { sub get_publication_age { my ($self, $info) = @_; - $info->{publishedText} =~ s/\sago\z//r;; + ($info->{publishedText} // '') =~ s/\sago\z//r;; } sub get_publication_age_approx { my ($self, $info) = @_; - my $age = $self->get_publication_age($info); + my $age = $self->get_publication_age($info) // ''; if ($age =~ /hour|min|sec/) { return "0d"; @@ -650,17 +677,20 @@ sub get_views_approx { sub get_likes { my ($self, $info) = @_; - $info->{statistics}{likeCount}; + #$info->{statistics}{likeCount}; + 0; } sub get_dislikes { my ($self, $info) = @_; - $info->{statistics}{dislikeCount}; + #$info->{statistics}{dislikeCount}; + 0; } sub get_comments { my ($self, $info) = @_; - $info->{statistics}{commentCount}; + #$info->{statistics}{commentCount}; + 1; } { |