aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortrizen <trizen@protonmail.com>2020-09-15 22:31:01 +0300
committerJesús <heckyel@hyperbola.info>2020-09-28 21:44:05 -0500
commit1f3b2b85a1ea6a1b523469bf4cb0a8089ab4f84d (patch)
treedf354eb5915803c9bc1487613518c2404bf96b98
parent192dd6d100f070a95be6868aa7ab7c3992859c1a (diff)
downloadfair-viewer-1f3b2b85a1ea6a1b523469bf4cb0a8089ab4f84d.tar.lz
fair-viewer-1f3b2b85a1ea6a1b523469bf4cb0a8089ab4f84d.tar.xz
fair-viewer-1f3b2b85a1ea6a1b523469bf4cb0a8089ab4f84d.zip
- Added instance-caching for `_get_video_info()`, `_extract_from_ytdl()` and `_extract_from_invidious()`.
Too many requests to `_get_video_info()` and/or `hypervideo` may lead to a "429 - Too Many Requests" issue. Caching these functions may help to prevent this a little bit. Also playing the same video twice, the second time it will load much faster, since `_get_video_info()` is cached. Signed-off-by: Jesús <heckyel@hyperbola.info>
-rwxr-xr-xBuild.PL1
-rw-r--r--META.json1
-rw-r--r--META.yml1
-rw-r--r--Makefile.PL1
-rwxr-xr-xbin/fair-viewer14
-rw-r--r--lib/WWW/FairViewer.pm9
-rw-r--r--lib/WWW/FairViewer/Videos.pm1
7 files changed, 20 insertions, 8 deletions
diff --git a/Build.PL b/Build.PL
index a77b075..d60b4e8 100755
--- a/Build.PL
+++ b/Build.PL
@@ -41,6 +41,7 @@ my $builder = Module::Build->new(
'HTTP::Request' => 0,
'JSON' => 0,
'Encode' => 0,
+ 'Memoize' => 0,
'MIME::Base64' => 0,
'List::Util' => 0,
'LWP::UserAgent' => 0,
diff --git a/META.json b/META.json
index 224bdc0..75980cc 100644
--- a/META.json
+++ b/META.json
@@ -45,6 +45,7 @@
"LWP::UserAgent" : "0",
"List::Util" : "0",
"MIME::Base64" : "0",
+ "Memoize" : "0",
"Term::ANSIColor" : "0",
"Term::ReadLine" : "0",
"Text::ParseWords" : "0",
diff --git a/META.yml b/META.yml
index 40de07e..268bf53 100644
--- a/META.yml
+++ b/META.yml
@@ -70,6 +70,7 @@ requires:
LWP::UserAgent: '0'
List::Util: '0'
MIME::Base64: '0'
+ Memoize: '0'
Term::ANSIColor: '0'
Term::ReadLine: '0'
Text::ParseWords: '0'
diff --git a/Makefile.PL b/Makefile.PL
index a3826d8..1bbc7c0 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -18,6 +18,7 @@ WriteMakefile
'LWP::UserAgent' => 0,
'List::Util' => 0,
'MIME::Base64' => 0,
+ 'Memoize' => 0,
'Term::ANSIColor' => 0,
'Term::ReadLine' => 0,
'Test::More' => 0,
diff --git a/bin/fair-viewer b/bin/fair-viewer
index 0414696..ab84393 100755
--- a/bin/fair-viewer
+++ b/bin/fair-viewer
@@ -3568,11 +3568,10 @@ sub print_video_info {
$rep = 0 if $rep < 0;
- print "\n$hr\n", q{ } x $rep => (_bold_color("=>> $title <<=") . "\n\n"),
- map(sprintf(q{-> } . "%-*s: %s\n", $opt{_colors} ? 18 : 10, _bold_color($_->[0]), $_->[1]),
- grep {
- defined($_->[1]) and $_->[1] !~ /^(0|unknown)\z/i
- } (
+ print("\n$hr\n", q{ } x $rep => (_bold_color("=>> $title <<=") . "\n\n"),
+ (
+ map { sprintf(q{-> } . "%-*s: %s\n", $opt{_colors} ? 18 : 10, _bold_color($_->[0]), $_->[1]) }
+ grep { defined($_->[1]) and $_->[1] !~ /^(0|unknown)\z/i } (
['Channel' => $yv_utils->get_channel_title($video)],
['ChannelID' => $yv_utils->get_channel_id($video)],
['VideoID' => $yv_utils->get_video_id($video)],
@@ -3583,8 +3582,9 @@ sub print_video_info {
['Dislikes' => $yv_utils->set_thousands($yv_utils->get_dislikes($video))],
['Views' => $yv_utils->set_thousands($yv_utils->get_views($video))],
['Published' => $yv_utils->get_publication_date($video)],
- )),
- "$hr\n";
+ )
+ ),
+ "$hr\n");
return 1;
}
diff --git a/lib/WWW/FairViewer.pm b/lib/WWW/FairViewer.pm
index 11a8bba..a82c8ae 100644
--- a/lib/WWW/FairViewer.pm
+++ b/lib/WWW/FairViewer.pm
@@ -4,6 +4,12 @@ use utf8;
use 5.016;
use warnings;
+use Memoize;
+
+memoize('_get_video_info');
+memoize('_extract_from_ytdl');
+memoize('_extract_from_invidious');
+
use parent qw(
WWW::FairViewer::Search
WWW::FairViewer::Videos
@@ -686,7 +692,8 @@ sub _extract_from_invidious {
if (@instances) {
require List::Util;
@instances = List::Util::shuffle(map { $_->[0] } @instances);
- #push @instances, 'invidious.13ad.de';
+ push @instances, 'invidious.snopyta.org';
+ push @instances, 'invidious.13ad.de';
}
else {
@instances = qw(
diff --git a/lib/WWW/FairViewer/Videos.pm b/lib/WWW/FairViewer/Videos.pm
index b29d1f7..da6af0b 100644
--- a/lib/WWW/FairViewer/Videos.pm
+++ b/lib/WWW/FairViewer/Videos.pm
@@ -225,6 +225,7 @@ sub video_details {
} @{$video->{thumbnail}{thumbnails}}
],
+ liveNow => $video->{isLiveContent},
description => $video->{shortDescription},
lengthSeconds => $video->{lengthSeconds},