Skip to content

Commit 762e49a

Browse files
committed
- Fixed the "400 Bad Request" error.
By updating the Android version in the user-agent. Fix from yt-dlp: https://github.com/yt-dlp/yt-dlp/blob/413d3675804599bc8fe419c19e36490fd8f0b30f/yt_dlp/extractor/youtube.py#L119 - bin/youtube-viewer: show the executed `yt-dlp` command with `--debug`.
1 parent 2d266b4 commit 762e49a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

bin/youtube-viewer

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4038,8 +4038,14 @@ sub download_from_url {
40384038

40394039
# Download with yt-dlp / youtube-dl
40404040
if ($opt{ytdl} and $opt{download_with_ytdl} and defined($info->{_youtube_url}) and defined($info->{itag})) {
4041+
40414042
my $cmd =
40424043
join(' ', $opt{ytdl_cmd}, ($info->{wkad} ? () : ('-f', $info->{itag})), quotemeta($info->{_youtube_url}), '-o', quotemeta("$output_filename.part"));
4044+
4045+
if ($yv_obj->get_debug) {
4046+
say "-> Command: $cmd";
4047+
}
4048+
40434049
$yv_obj->proxy_system($cmd);
40444050
return if $?;
40454051
rename("$output_filename.part", $output_filename) or return undef;

lib/WWW/YoutubeViewer.pm

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use utf8;
44
use 5.016;
55
use warnings;
66

7-
use Memoize;
8-
use Memoize::Expire;
7+
use Memoize qw(memoize);
98

109
#<<<
10+
#~ use Memoize::Expire;
1111
#~ tie my %youtubei_cache => 'Memoize::Expire',
1212
#~ LIFETIME => 600, # in seconds
1313
#~ NUM_USES => 2;
@@ -1056,7 +1056,7 @@ sub _get_youtubei_content {
10561056

10571057
require Time::Piece;
10581058

1059-
my $android_useragent = 'com.google.android.youtube/17.31.35 (Linux; U; Android 11) gzip';
1059+
my $android_useragent = 'com.google.android.youtube/18.11.34 (Linux; U; Android 11) gzip';
10601060

10611061
my %android = (
10621062
"videoId" => $videoID,
@@ -1065,7 +1065,7 @@ sub _get_youtubei_content {
10651065
'hl' => 'en',
10661066
'gl' => 'US',
10671067
'clientName' => 'ANDROID',
1068-
'clientVersion' => '17.31.35',
1068+
'clientVersion' => '18.11.34',
10691069
'androidSdkVersion' => 30,
10701070
'userAgent' => $android_useragent,
10711071
%args,
@@ -1114,7 +1114,13 @@ sub _get_youtubei_content {
11141114
}
11151115

11161116
local $self->{access_token} = undef;
1117-
my $content = $self->post_as_json($url, $endpoint eq 'next' ? \%mweb : \%android);
1117+
1118+
my $content;
1119+
for (1 .. 3) {
1120+
$content = $self->post_as_json($url, $endpoint eq 'next' ? \%mweb : \%android);
1121+
last if defined $content;
1122+
}
1123+
11181124
$self->{lwp}->agent($agent);
11191125
return $content;
11201126
}

0 commit comments

Comments
 (0)