aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW/FairViewer/Utils.pm
diff options
context:
space:
mode:
authortrizen <trizen@protonmail.com>2020-06-05 23:19:15 +0300
committerJesús <heckyel@hyperbola.info>2020-06-06 22:05:56 -0500
commit751dd4e0d6ac3fe6a45c51e742a2b73ba69a4eed (patch)
tree128fba638ce4d849437b139d651c63500a852a6f /lib/WWW/FairViewer/Utils.pm
parent4621e4af0b93c5654e022158122f4fb64cf12799 (diff)
downloadfair-viewer-751dd4e0d6ac3fe6a45c51e742a2b73ba69a4eed.tar.lz
fair-viewer-751dd4e0d6ac3fe6a45c51e742a2b73ba69a4eed.tar.xz
fair-viewer-751dd4e0d6ac3fe6a45c51e742a2b73ba69a4eed.zip
- Added a fallback method for extracting video information. - Decode internal YouTube URLs in description. - Various fixes and improvements.
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'lib/WWW/FairViewer/Utils.pm')
-rw-r--r--lib/WWW/FairViewer/Utils.pm14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/WWW/FairViewer/Utils.pm b/lib/WWW/FairViewer/Utils.pm
index e50bf3f..06ea9d9 100644
--- a/lib/WWW/FairViewer/Utils.pm
+++ b/lib/WWW/FairViewer/Utils.pm
@@ -230,7 +230,7 @@ sub has_entries {
}
}
- my $type = $result->{results}{type}//'';
+ my $type = $result->{results}{type} // '';
if ($type eq 'playlist') {
return $result->{results}{videoCount} > 0;
@@ -241,6 +241,10 @@ sub has_entries {
return scalar(@{$result->{results}}) > 0;
}
+ if (ref($result->{results}) eq 'HASH' and not keys %{$result->{results}}) {
+ return 0;
+ }
+
return 1; # maybe?
#ref($result) eq 'HASH' and ($result->{results}{pageInfo}{totalResults} > 0);
}
@@ -458,6 +462,7 @@ sub get_description {
require URI::Escape;
require HTML::Entities;
+ # Decode external links
$desc =~ s{<a href="/redirect\?(.*?)".*?>.*?</a>}{
my $url = $1;
if ($url =~ /(?:^|;)q=([^&]+)/) {
@@ -468,6 +473,13 @@ sub get_description {
}
}segi;
+ # Decode internal links to videos / playlists
+ $desc =~ s{<a href="/(watch\?.*?)".*?>(https://www\.youtube\.com)/watch\?.*?</a>}{
+ my $url = $2;
+ my $params = URI::Escape::uri_unescape($1);
+ "$url/$params";
+ }segi;
+
$desc =~ s{<br/?>}{\n}gi;
$desc =~ s{<a href=".*?".*?>(.*?)</a>}{$1}sgi;
$desc =~ s/<.*?>//gs;