| 1 | package WWW::YouTube::Info::Simple; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | require Exporter; | |||||||||||||||||||||||||||
| 8 | 8 | require WWW::YouTube::Info; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 8 | our @ISA = qw( | |||||||||||||||||||||||||||
| 11 | Exporter | ||||||||||||||||||||||||||||
| 12 | WWW::YouTube::Info | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 8 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 8 | our $VERSION = '0.11'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 8 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 NAME | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | WWW::YouTube::Info::Simple - simple interface to WWW::YouTube::Info | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head2 Perhaps a little code snippet? | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | use strict; | ||||||||||||||||||||||||||||
| 34 | use warnings; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | use WWW::YouTube::Info::Simple; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # id taken from YouTube video URL | ||||||||||||||||||||||||||||
| 39 | my $id = 'foobar'; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | my $yt = WWW::YouTube::Info::Simple->new($id); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # hash reference holds values gained via https://youtube.com/get_video_info?video_id=foobar | ||||||||||||||||||||||||||||
| 44 | my $info = $yt->get_info(); | ||||||||||||||||||||||||||||
| 45 | # this is basically an inheritance to get_info() at WWW::YouTube::Info | ||||||||||||||||||||||||||||
| 46 | # $info->{title} # e.g.: Foo+bar+-+%27Foobar%27 | ||||||||||||||||||||||||||||
| 47 | # $info->{author} # e.g.: foobar | ||||||||||||||||||||||||||||
| 48 | # $info->{keywords} # e.g.: Foo%2Cbar%2CFoobar | ||||||||||||||||||||||||||||
| 49 | # $info->{length_seconds} # e.g.: 60 | ||||||||||||||||||||||||||||
| 50 | # $info->{fmt_map} # e.g.: 22%2F1280x720%2F9%2F0%2F115%2C35%2F854x480%2F9%2F0%2F115%2C34%2F640x360%2F9%2 .. | ||||||||||||||||||||||||||||
| 51 | # $info->{fmt_url_map} # e.g.: 22%7Chttps%3A%2F%2Fv14.lscache1.c.youtube.com%2Fvideoplayback%3Fip%3D131.0.0. .. | ||||||||||||||||||||||||||||
| 52 | # $info->{fmt_stream_map} # e.g.: 22%7Chttps%3A%2F%2Fv14.lscache1.c.youtube.com%2Fvideoplayback%3Fip%3D131.0.0. .. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # array reference holds values keywords | ||||||||||||||||||||||||||||
| 55 | my $keys = $yt->get_keywords(); | ||||||||||||||||||||||||||||
| 56 | # $keys->[0] # e.g.: Foo | ||||||||||||||||||||||||||||
| 57 | # $keys->[1] # e.g.: bar | ||||||||||||||||||||||||||||
| 58 | # .. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # hash reference holds values quality -> resolution | ||||||||||||||||||||||||||||
| 61 | my $res = $yt->get_resolution(); | ||||||||||||||||||||||||||||
| 62 | # $res->{35} # e.g.: 854x480 | ||||||||||||||||||||||||||||
| 63 | # $res->{22} # e.g.: 1280x720 | ||||||||||||||||||||||||||||
| 64 | # .. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # URL and masquerading decoded title | ||||||||||||||||||||||||||||
| 67 | my $title = $yt->get_title(); # e.g.: Foo bar - 'Foobar' | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # hash reference holds values quality -> url | ||||||||||||||||||||||||||||
| 70 | my $url = $yt->get_url(); | ||||||||||||||||||||||||||||
| 71 | # $url->{35} e.g.: https://v14.lscache1.c.youtube.com/videoplayback?ip=131.0.0.0 .. | ||||||||||||||||||||||||||||
| 72 | # $url->{22} e.g.: https://v14.lscache1.c.youtube.com/videoplayback?ip=131.0.0.0 .. | ||||||||||||||||||||||||||||
| 73 | # .. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # URL decoded RTMPE URL | ||||||||||||||||||||||||||||
| 76 | my $conn = $yt->get_conn(); # e.g.: rtmpe://cp59009.edgefcs.net/youtube?auth=daEcaboc8dvawbcbxazdobDcZajcDdgcfae .. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Remark: | ||||||||||||||||||||||||||||
| 79 | # You might want to check $info->{status} before further workout, | ||||||||||||||||||||||||||||
| 80 | # as some videos have copyright issues indicated, for instance, by | ||||||||||||||||||||||||||||
| 81 | # $info->{status} ne 'ok'. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | I guess its pretty much self-explanatory .. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 METHODS | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head2 get_keywords | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Returns undef if status ne 'ok'. | ||||||||||||||||||||||||||||
| 94 | Croaks if not available. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | sub get_keywords { | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_keywords: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $self->get_info() unless exists($self->{info}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return if ( $self->{info}->{status} ne 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my $keywords = $self->{info}->{'keywords'}; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | croak "no keywords found!" unless $keywords; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | my @keywords_parts = split /%2C/, $keywords; | |||||||||||||||||||||||||||
| 108 | 0 | foreach my $item ( @keywords_parts ) { | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | next unless $item; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $item = _url_decode($item); | |||||||||||||||||||||||||||
| 111 | 0 | push @{$self->{keywords}}, $item; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | return $self->{keywords}; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head2 get_resolution | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Returns undef if status ne 'ok'. | ||||||||||||||||||||||||||||
| 120 | Croaks if not available. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub get_resolution { | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_resolution: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $self->get_info() unless exists($self->{info}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return if ( $self->{info}->{status} ne 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # quality and resolution | ||||||||||||||||||||||||||||
| 131 | 0 | my $fmt_map = $self->{info}->{'fmt_map'}; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | unless ( $fmt_map ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | # fallback to fmt_list | ||||||||||||||||||||||||||||
| 134 | # as fmt_map doesnt't seem to be supported any more | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | croak "no resolutions found!" unless $self->_fmt_list(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||
| 138 | # process fmt_map | ||||||||||||||||||||||||||||
| 139 | 0 | my @fmt_map_parts = split /%2F9%2F0%2F115%2C/, $fmt_map; | |||||||||||||||||||||||||||
| 140 | 0 | foreach my $item ( @fmt_map_parts ) { | |||||||||||||||||||||||||||
| 141 | 0 | my ($quality, $resolution) = split /%2F/, $item; | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | next unless $quality and $resolution; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$quality and $resolution
MC/DC0%0/2
$quality and $resolution
$quality
$resolution
Truth table0%0/3
A and B
A= $qualityB= $resolution
| |||||||||||||||||||||||||||||
| 143 | 0 | $self->{resolution}->{$quality} = $resolution; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | return $self->{resolution}; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head2 get_title | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Returns undef if status ne 'ok'. | ||||||||||||||||||||||||||||
| 153 | Croaks if not available. | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub get_title { | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_title: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $self->get_info() unless exists($self->{info}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return if ( $self->{info}->{status} ne 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | my $title = $self->{info}->{'title'}; | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | croak "no title found!" unless $title; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | $title = _url_decode($title); | |||||||||||||||||||||||||||
| 167 | 0 | $title =~ s/\+/ /g; | |||||||||||||||||||||||||||
| 168 | 0 | $self->{title} = $title; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | return $self->{title}; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head2 get_url | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Returns undef if status ne 'ok'. | ||||||||||||||||||||||||||||
| 176 | Croaks if not available. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | use WWW::YouTube::Info::Simple; | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # id taken from YouTube video URL | ||||||||||||||||||||||||||||
| 181 | my $id = 'foobar'; | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | my $yt = WWW::YouTube::Info::Simple->new($id); | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # hash reference holds values quality -> url | ||||||||||||||||||||||||||||
| 186 | my $url = $yt->get_url(); | ||||||||||||||||||||||||||||
| 187 | # $url->{35} e.g.: https://v14.lscache1.c.youtube.com/videoplayback?ip=131.0.0.0 .. | ||||||||||||||||||||||||||||
| 188 | # $url->{22} e.g.: https://v14.lscache1.c.youtube.com/videoplayback?ip=131.0.0.0 .. | ||||||||||||||||||||||||||||
| 189 | # .. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | YouTube videos can be downloaded in given qualities by means of these URLs and the usual suspects (C<wget>, ..). | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | sub get_url { | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_url: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | $self->get_info() unless exists($self->{info}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | return if ( $self->{info}->{status} ne 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # quality and URL | ||||||||||||||||||||||||||||
| 202 | 0 | my $fmt_url_map = $self->{info}->{'fmt_url_map'}; | |||||||||||||||||||||||||||
| 203 | 0 | ▶ | unless ( $fmt_url_map ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | # fallback to url_encoded_fmt_stream_map | ||||||||||||||||||||||||||||
| 205 | # as fmt_url_map doesnt't seem to be supported any more | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | croak "no URLs found!" unless $self->_url_encoded_fmt_stream_map(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||
| 209 | # process fmt_url_map | ||||||||||||||||||||||||||||
| 210 | 0 | my @fmt_url_map_parts = split /%2C/, $fmt_url_map; | |||||||||||||||||||||||||||
| 211 | 0 | foreach my $item ( @fmt_url_map_parts ) { | |||||||||||||||||||||||||||
| 212 | 0 | my ($quality, $url) = split /%7C/, $item; | |||||||||||||||||||||||||||
| 213 | 0 | ▶ | next unless $quality and $url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$quality and $url
MC/DC0%0/2
$quality and $url
$quality
$url
Truth table0%0/3
A and B
A= $qualityB= $url
| |||||||||||||||||||||||||||||
| 214 | 0 | $url = _url_decode($url); | |||||||||||||||||||||||||||
| 215 | 0 | $self->{url}->{$quality} = $url; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | return $self->{url}; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =head2 get_conn | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | Returns undef if status ne 'ok'. | ||||||||||||||||||||||||||||
| 225 | Croaks if not available. | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | use WWW::YouTube::Info::Simple; | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # id taken from YouTube video URL | ||||||||||||||||||||||||||||
| 230 | my $id = 'foobar'; | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | my $yt = WWW::YouTube::Info::Simple->new($id); | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # URL decoded RTMPE URL | ||||||||||||||||||||||||||||
| 235 | my $conn = $yt->get_conn(); # e.g.: rtmpe://cp59009.edgefcs.net/youtube?auth=daEcaboc8dvawbcbxazdobDcZajcDdgcfae .. | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | A YouTube RTMPE stream can be accessed via this URL and downloaded by | ||||||||||||||||||||||||||||
| 238 | means of the usual suspects (C<rtmpdump>, ..). | ||||||||||||||||||||||||||||
| 239 | The URL looses its validity after approx. 30 seconds (experimental value). | ||||||||||||||||||||||||||||
| 240 | Gathering a fresh RTMPE URL regarding the same VIDEO_ID and the | ||||||||||||||||||||||||||||
| 241 | C<rtmpdump .. --resume> capability might circumvent this inconvenience. | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | =cut | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | sub get_conn { | ||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_conn: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 0 | ▶ | $self->get_info() unless exists($self->{info}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | return if ( $self->{info}->{status} ne 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | my $conn = $self->{info}->{'conn'}; | |||||||||||||||||||||||||||
| 252 | 0 | ▶ | croak "no conn found!" unless $conn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | $self->{conn} = _url_decode($conn); | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | return $self->{conn}; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | sub _url_encoded_fmt_stream_map { | ||||||||||||||||||||||||||||
| 261 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_url_encoded_fmt_stream_map: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | ▶ | $self->get_info() unless exists($self->{info}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | return if ( $self->{info}->{status} ne 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # quality and URL | ||||||||||||||||||||||||||||
| 267 | 0 | my $url_encoded_fmt_stream_map = $self->{info}->{'url_encoded_fmt_stream_map'}; | |||||||||||||||||||||||||||
| 268 | 0 | ▶ | return unless $url_encoded_fmt_stream_map; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | my @url_encoded_fmt_stream_map_parts = split /%2C/, $url_encoded_fmt_stream_map; | |||||||||||||||||||||||||||
| 271 | 0 | foreach my $item ( @url_encoded_fmt_stream_map_parts ) { | |||||||||||||||||||||||||||
| 272 | 0 | $item = _url_decode($item); | |||||||||||||||||||||||||||
| 273 | 0 | (my $url = $item) =~ s/.*url=(.*)(?:&.*|$)/$1/; | |||||||||||||||||||||||||||
| 274 | 0 | $url = _url_decode($url); | |||||||||||||||||||||||||||
| 275 | 0 | (my $quality = $url) =~ s/.*&itag=(\d+)&.*/$1/; | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | # fix multiple occurrences of parameters | ||||||||||||||||||||||||||||
| 278 | 0 | my ($url_base, $params) = split /\?/, $url; | |||||||||||||||||||||||||||
| 279 | 0 | my %params_uniq = map { $_ => 1 } split /&/, $params; | |||||||||||||||||||||||||||
| 280 | 0 | my $params_uniq = join('&', keys %params_uniq); | |||||||||||||||||||||||||||
| 281 | 0 | $url = $url_base . '?' . $params_uniq; | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 0 | ▶ | next unless $quality and $url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$quality and $url
MC/DC0%0/2
$quality and $url
$quality
$url
Truth table0%0/3
A and B
A= $qualityB= $url
| |||||||||||||||||||||||||||||
| 284 | 0 | $self->{url}->{$quality} = $url; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | return $self->{url}; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | sub _fmt_list { | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_fmt_list: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 0 | ▶ | $self->get_info() unless exists($self->{info}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | return if ( $self->{info}->{status} ne 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | # quality and resolution | ||||||||||||||||||||||||||||
| 297 | 0 | my $fmt_list = $self->{info}->{'fmt_list'}; | |||||||||||||||||||||||||||
| 298 | 0 | ▶ | return unless $fmt_list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 0 | my @fmt_list_parts = split /%2C/, $fmt_list; | |||||||||||||||||||||||||||
| 301 | 0 | foreach my $item ( @fmt_list_parts ) { | |||||||||||||||||||||||||||
| 302 | 0 | my ($quality, $resolution, @rest) = split /%2F/, $item; | |||||||||||||||||||||||||||
| 303 | 0 | ▶ | next unless $quality and $resolution; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$quality and $resolution
MC/DC0%0/2
$quality and $resolution
$quality
$resolution
Truth table0%0/3
A and B
A= $qualityB= $resolution
| |||||||||||||||||||||||||||||
| 304 | 0 | $self->{resolution}->{$quality} = $resolution; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | return $self->{resolution}; | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | sub _url_encode { | ||||||||||||||||||||||||||||
| 311 | 0 | ▶ | my $string = shift; | ||||||||||||||||||||||||||
|
Subroutine
_url_encode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | # URLencode | ||||||||||||||||||||||||||||
| 314 | 0 | $string =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 0 | return $string; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | sub _url_decode { | ||||||||||||||||||||||||||||
| 320 | 0 | ▶ | my $string = shift; | ||||||||||||||||||||||||||
|
Subroutine
_url_decode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | # URLdecode | ||||||||||||||||||||||||||||
| 323 | 0 | $string =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 0 | return $string; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 8 | 1; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | __END__ | ||||||||||||||||||||||||||||