Skip to content

Commit

Permalink
- Extract livestream URL with the fallback method only when our code …
Browse files Browse the repository at this point in the history
…fails.

- Removed some old code.
  • Loading branch information
trizen committed Nov 8, 2022
1 parent 4713a4c commit a085b01
Showing 1 changed file with 4 additions and 58 deletions.
62 changes: 4 additions & 58 deletions lib/WWW/YoutubeViewer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ my %valid_options = (
video_info_url => {valid => q[], default => 'https://www.youtube.com/get_video_info'},
#oauth_url => {valid => q[], default => 'https://accounts.google.com/o/oauth2/'},
oauth_url => {valid => q[], default => 'https://oauth2.googleapis.com'},
video_info_args => {valid => q[], default => '?video_id=%s&el=detailpage&ps=default&eurl=&gl=US&hl=en&html5=1&c=TVHTML5&cver=6.20180913'},
www_content_type => {valid => q[], default => 'application/x-www-form-urlencoded'},
youtubei_url => {valid => q[], default => 'https://youtubei.googleapis.com/youtubei/v1/%s?key=' . reverse("8Wcq11_9Y_wliCGLHETS4Q8UqlS2JF_OAySazIA")},
#>>>
Expand Down Expand Up @@ -973,51 +972,6 @@ sub _check_streaming_urls {
return 1;
}

sub _old_extract_streaming_urls {
my ($self, $info, $videoID) = @_;

if ($self->get_debug) {
say STDERR ":: Using `url_encoded_fmt_stream_map` to extract the streaming URLs...";
}

my %stream_map = $self->parse_query_string($info->{url_encoded_fmt_stream_map}, multi => 1);
my %adaptive_fmts = $self->parse_query_string($info->{adaptive_fmts}, multi => 1);

if ($self->get_debug >= 2) {
require Data::Dump;
Data::Dump::pp(\%stream_map);
Data::Dump::pp(\%adaptive_fmts);
}

my @results;

push @results, $self->_group_keys_with_values(%stream_map);
push @results, $self->_group_keys_with_values(%adaptive_fmts);

$self->_check_streaming_urls($videoID, \@results);

if ($info->{livestream} or $info->{live_playback}) {

if ($self->get_debug) {
say STDERR ":: Live stream detected...";
}

if (my @formats = $self->_fallback_extract_urls($videoID)) {
@results = @formats;
}
elsif (exists $info->{hlsvp}) {
push @results,
{
itag => 38,
type => 'video/ts',
url => $info->{hlsvp},
};
}
}

return @results;
}

sub _extract_streaming_urls {
my ($self, $json, $videoID) = @_;

Expand Down Expand Up @@ -1066,8 +1020,6 @@ sub _extract_streaming_urls {
say STDERR ":: Live stream detected...";
}

@results = $self->_fallback_extract_urls($videoID);

if (!@results) {
push @results,
{
Expand All @@ -1078,6 +1030,10 @@ sub _extract_streaming_urls {
}
}

if (!@results) {
@results = $self->_fallback_extract_urls($videoID);
}

return @results;
}

Expand Down Expand Up @@ -1122,16 +1078,6 @@ sub _get_youtubei_content {
return $content;
}

sub _old_get_video_info {
my ($self, $videoID) = @_;

my $url = $self->get_video_info_url() . sprintf($self->get_video_info_args(), $videoID);
my $content = $self->lwp_get($url, simple => 1) // return;
my %info = $self->parse_query_string($content);

return %info;
}

sub _get_video_info {
my ($self, $videoID, %args) = @_;

Expand Down

0 comments on commit a085b01

Please sign in to comment.