diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/WWW/FairViewer.pm | 16 | ||||
-rw-r--r-- | lib/WWW/FairViewer/Utils.pm | 25 |
2 files changed, 36 insertions, 5 deletions
diff --git a/lib/WWW/FairViewer.pm b/lib/WWW/FairViewer.pm index d117b95..4b57f68 100644 --- a/lib/WWW/FairViewer.pm +++ b/lib/WWW/FairViewer.pm @@ -92,8 +92,8 @@ my %valid_options = ( access_token => {valid => [qr/^.{15}/], default => undef}, refresh_token => {valid => [qr/^.{15}/], default => undef}, - authentication_file => {valid => [qr/^./], default => undef}, - api_host => {valid => [qr{^https?://}], default => "https://invidio.us"}, + authentication_file => {valid => [qr/^./], default => undef}, + api_host => {valid => [qr{[-\w]+\.[-\w]+}], default => "https://invidio.us"}, # No input value allowed api_path => {valid => q[], default => '/api/v1/'}, @@ -135,6 +135,7 @@ sub basic_video_info_fields { title videoId description + descriptionHtml published publishedText viewCount @@ -493,7 +494,16 @@ sub _append_url_args { sub get_api_url { my ($self) = @_; - join('', $self->get_api_host, $self->get_api_path); + + my $host = $self->get_api_host; + + $host =~ s{/+\z}{}; # remove trailing '/' + + if ($host =~ m{^[-\w]+(?>\.[-\w]+)+\z}) { # no protocol specified + $host = 'https://' . $host; # default to HTTPS + } + + join('', $host, $self->get_api_path); } sub _simple_feeds_url { diff --git a/lib/WWW/FairViewer/Utils.pm b/lib/WWW/FairViewer/Utils.pm index 5ca1106..09c0174 100644 --- a/lib/WWW/FairViewer/Utils.pm +++ b/lib/WWW/FairViewer/Utils.pm @@ -452,8 +452,29 @@ Get description. sub get_description { my ($self, $info) = @_; - my $desc = $info->{description}; - (defined($desc) and $desc =~ /\S/) ? $desc : 'No description available...'; + + my $desc = $info->{descriptionHtml} // ''; + + require URI::Escape; + require HTML::Entities; + + $desc =~ s{<a href="/redirect\?(.*?)".*?>.*?</a>}{ + my $url = $1; + if ($url =~ /(?:^|;)q=([^&]+)/) { + URI::Escape::uri_unescape($1); + } + else { + $url; + } + }segi; + + $desc =~ s/<br>/\n/gi; + $desc =~ s{<a href=".*?".*?>(.*?)</a>}{$1}sgi; + $desc =~ s/<.*?>//gs; + + $desc = HTML::Entities::decode_entities($desc); + + ($desc =~ /\S/) ? $desc : 'No description available...'; } =head2 get_title($info) |