aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/fair-viewer13
-rw-r--r--lib/WWW/FairViewer.pm16
-rw-r--r--lib/WWW/FairViewer/Utils.pm25
3 files changed, 43 insertions, 11 deletions
diff --git a/bin/fair-viewer b/bin/fair-viewer
index bbd18fc..f6159bc 100755
--- a/bin/fair-viewer
+++ b/bin/fair-viewer
@@ -796,7 +796,7 @@ usage: $execname [options] ([url] | [keywords])
--use-colors! : enable or disable the ANSI colors for text
* Other
- --invidious! : use the API of invidio.us to get the streaming URLs
+ --api-host=s : set an API host from https://instances.invidio.us/
--proxy=s : set HTTP(S)/SOCKS proxy: 'proto://domain.tld:port/'
If authentication required,
use 'proto://user:pass\@domain.tld:port/'
@@ -1593,7 +1593,8 @@ sub parse_arguments {
'merge-into-mkv|mkv-merge!' => \$opt{merge_into_mkv},
'merge-with-captions|merge-captions!' => \$opt{merge_with_captions},
- 'invidious!' => \$opt{use_invidious_api},
+ 'api-host=s' => \$opt{api_host},
+
'convert-command|convert-cmd=s' => \$opt{convert_cmd},
'dash-m4a|dash-mp4-audio|dash-mp4a!' => \$opt{dash_mp4_audio},
'dash-segmented!' => \$opt{dash_segmented},
@@ -2127,7 +2128,7 @@ sub get_and_print_video_info {
if ($yv_utils->has_entries($info)) {
local $opt{show_video_info} = 1;
- print_video_info($info->{results}{items}[0]);
+ print_video_info($info->{results});
}
else {
warn_cant_do('get info for', $videoID);
@@ -2279,7 +2280,7 @@ sub general_options {
$callback->($request);
}
elsif ($option =~ /^(?:R|refresh)\z/ and defined $url) {
- @{$results} = @{$yv_obj->_get_results($url)->{results}{items}};
+ @{$results} = @{$yv_obj->_get_results($url)->{results}};
}
elsif ($option eq 'login') {
authenticate();
@@ -3374,7 +3375,7 @@ sub autoplay {
while (1) {
get_and_play_video_ids($video_id) || return;
my $related = $yv_obj->related_to_videoID($video_id);
- (my @video_ids = grep { !$seen{$_}++ } map { $yv_utils->get_video_id($_) } @{$related->{results}{items}}) || return;
+ (my @video_ids = grep { !$seen{$_}++ } map { $yv_utils->get_video_id($_) } @{$related->{results}}) || return;
$video_id = $opt{shuffle} ? $video_ids[rand @video_ids] : $video_ids[0];
}
@@ -3878,7 +3879,7 @@ sub print_videos {
#}
}
elsif ($opt =~ /^(?:R|refresh)\z/) {
- @{$videos} = @{$yv_obj->_get_results($url)->{results}{items}};
+ @{$videos} = @{$yv_obj->_get_results($url)->{results}};
$results->{has_extra_info} = 0;
}
elsif ($opt =~ /^(?:r|return)\z/) {
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)