Skip to content

Commit

Permalink
Fixed the internal extraction of streaming URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
trizen committed May 11, 2023
1 parent 3324f40 commit 62b650e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
39 changes: 27 additions & 12 deletions lib/WWW/YoutubeViewer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1052,18 +1052,20 @@ sub _get_youtubei_content {

require Time::Piece;

my %android = (
"videoId" => $videoID,
"context" => {
"client" => {
"hl" => "en",
"gl" => "US",
"clientName" => "ANDROID",
"clientVersion" => "16.20",
%args,
},
},
);
#<<<
#~ my %android = (
#~ "videoId" => $videoID,
#~ "context" => {
#~ "client" => {
#~ "hl" => "en",
#~ "gl" => "US",
#~ "clientName" => "ANDROID",
#~ "clientVersion" => "16.20",
#~ %args,
#~ },
#~ },
#~ );
#>>>

my %web = (
"videoId" => $videoID,
Expand All @@ -1078,6 +1080,19 @@ sub _get_youtubei_content {
},
);

my %android = (
"videoId" => $videoID,
"context" => {
"client" => {
"hl" => "en",
"gl" => "US",
"clientName" => "MWEB",
"clientVersion" => sprintf("2.%s.03.00", Time::Piece->new(time)->strftime("%Y%m%d")),
%args,
}
},
);

local $self->{access_token} = undef;
my $content = $self->post_as_json($url, $endpoint eq 'next' ? \%web : \%android);

Expand Down
11 changes: 8 additions & 3 deletions lib/WWW/YoutubeViewer/GetCaption.pm
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,14 @@ sub save_caption {
return $srt_file if (-e $srt_file);

# Get XML data, then transform it to SubRip data
my $url = $info->{baseUrl} // return;
my $xml = $self->{yv_obj}->lwp_get($url, simple => 1) // return;
my $srt = $self->xml2srt($xml) // return;
my $url = $info->{baseUrl} // return;

if ($url =~ m{^/}) {
$url = "https://www.youtube.com" . $url;
}

my $xml = eval { $self->{yv_obj}->lwp_get($url, simple => 1) } // return;
my $srt = $self->xml2srt($xml) // return;

# Write the SubRib data to the $srt_file
open(my $fh, '>:utf8', $srt_file) or return;
Expand Down

0 comments on commit 62b650e

Please sign in to comment.