Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
- Added instance-caching for _get_video_info(), `_extract_from_ytdl…
Browse files Browse the repository at this point in the history
…()` and `_extract_from_invidious()`.

Too many requests to `_get_video_info()` and/or `youtube-dl` 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.
  • Loading branch information
trizen committed Sep 15, 2020
1 parent 0647e5f commit 802d056
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"LWP::UserAgent" : "0",
"List::Util" : "0",
"MIME::Base64" : "0",
"Memoize" : "0",
"Term::ANSIColor" : "0",
"Term::ReadLine" : "0",
"Text::ParseWords" : "0",
Expand Down
1 change: 1 addition & 0 deletions META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ requires:
LWP::UserAgent: '0'
List::Util: '0'
MIME::Base64: '0'
Memoize: '0'
Term::ANSIColor: '0'
Term::ReadLine: '0'
Text::ParseWords: '0'
Expand Down
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions bin/straw-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -3565,11 +3565,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)],
Expand All @@ -3580,8 +3579,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;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/WWW/StrawViewer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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::StrawViewer::Search
WWW::StrawViewer::Videos
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions lib/WWW/StrawViewer/Videos.pm
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ sub video_details {
} @{$video->{thumbnail}{thumbnails}}
],

liveNow => $video->{isLiveContent},
description => $video->{shortDescription},
lengthSeconds => $video->{lengthSeconds},

Expand Down

0 comments on commit 802d056

Please sign in to comment.