Lines 26-31
Link Here
|
26 |
if($embed_url !~ m!youtube\.com/watch!) { |
26 |
if($embed_url !~ m!youtube\.com/watch!) { |
27 |
$browser->get($embed_url); |
27 |
$browser->get($embed_url); |
28 |
if ($browser->response->header('Location') =~ m!/swf/.*video_id=([^&]+)! |
28 |
if ($browser->response->header('Location') =~ m!/swf/.*video_id=([^&]+)! |
|
|
29 |
|| $browser->content =~ m!\<iframe[^\>]*src="http://www.youtube.com/embed/([^"]+)"!i |
29 |
|| $embed_url =~ m!/v/([-_a-z0-9]+)!i |
30 |
|| $embed_url =~ m!/v/([-_a-z0-9]+)!i |
30 |
|| $browser->uri =~ m!v%3D([-_a-z0-9]+)!i) { |
31 |
|| $browser->uri =~ m!v%3D([-_a-z0-9]+)!i) { |
31 |
# We ended up on a embedded SWF or other redirect page |
32 |
# We ended up on a embedded SWF or other redirect page |
Lines 48-59
Link Here
|
48 |
# If the page contains fmt_url_map, then process this. With this, we |
49 |
# If the page contains fmt_url_map, then process this. With this, we |
49 |
# don't require the 't' parameter. |
50 |
# don't require the 't' parameter. |
50 |
if ($browser->content =~ /["']fmt_url_map["']:\s{0,3}(["'][^"']+["'])/) { |
51 |
if ($browser->content =~ /["']fmt_url_map["']:\s{0,3}(["'][^"']+["'])/) { |
51 |
debug "Using fmt_url_map method from page ($1)"; |
52 |
my $fmt_map = $1; |
52 |
return $self->download_fmt_map($prefs, $browser, $title, {}, @{from_json $1}); |
53 |
if ($fmt_map !~ /\|/) { |
|
|
54 |
# $fmt_map is double escaped. We should unescape it here just |
55 |
# once. Be careful not to unescape ',' in the URL. |
56 |
$fmt_map = uri_unescape($fmt_map); |
57 |
} |
58 |
debug "Using fmt_url_map method from page ($fmt_map)"; |
59 |
return $self->download_fmt_map($prefs, $browser, $title, {}, @{from_json $fmt_map}); |
53 |
} |
60 |
} |
54 |
|
61 |
|
55 |
my $video_id; |
62 |
my $video_id; |
56 |
if ($browser->content =~ /(?:var pageVideoId =|(?:CFG_)?VIDEO_ID'?\s*:)\s*'(.+?)'/ |
63 |
if ($browser->content =~ /(?:var pageVideoId =|(?:CFG_)?VIDEO_ID'?\s*:)\s*'(.+?)'/ |
|
|
64 |
|| $browser->content =~ /"video_id": "([^"]+)"/ |
57 |
|| $embed_url =~ /v=([^&]+)/) { |
65 |
|| $embed_url =~ /v=([^&]+)/) { |
58 |
$video_id = $1; |
66 |
$video_id = $1; |
59 |
} else { |
67 |
} else { |
Lines 125-130
Link Here
|
125 |
} elsif($info{fmt_url_map}) { |
133 |
} elsif($info{fmt_url_map}) { |
126 |
debug "Using fmt_url_map method from info"; |
134 |
debug "Using fmt_url_map method from info"; |
127 |
return $self->download_fmt_map($prefs, $browser, $title, \%info, $info{fmt_url_map}); |
135 |
return $self->download_fmt_map($prefs, $browser, $title, \%info, $info{fmt_url_map}); |
|
|
136 |
} elsif($info{url_encoded_fmt_stream_map}) { |
137 |
debug "Using url_encoded_fmt_stream_map method from info"; |
138 |
return $self->download_url_encoded_fmt_stream_map($prefs, $browser, $title, \%info, $info{url_encoded_fmt_stream_map}); |
128 |
} |
139 |
} |
129 |
} |
140 |
} |
130 |
|
141 |
|
Lines 132-137
Link Here
|
132 |
return download_get_video($browser, $prefs, $video_id, $title, $t); |
143 |
return download_get_video($browser, $prefs, $video_id, $title, $t); |
133 |
} |
144 |
} |
134 |
|
145 |
|
|
|
146 |
sub download_url_encoded_fmt_stream_map { |
147 |
my($self, $prefs, $browser, $title, $info, $fmt_map) = @_; |
148 |
|
149 |
my $fmt_url_map = parse_youtube_url_encoded_fmt_stream_map($fmt_map); |
150 |
|
151 |
if (!$title and $browser->uri->as_string =~ m'/user/.*?#') { |
152 |
my $video_id = (split /\//, $browser->uri->fragment)[-1]; |
153 |
|
154 |
my %info = get_youtube_video_info($browser->clone, $video_id); |
155 |
|
156 |
$title = $info->{title}; |
157 |
} |
158 |
|
159 |
my $preferred_quality = $prefs->quality->choose(map { $fmt_url_map->{$_->{id}} |
160 |
? { resolution => $_->{resolution}, url => $fmt_url_map->{$_->{id}} } |
161 |
: () } @formats); |
162 |
|
163 |
$browser->allow_redirects; |
164 |
|
165 |
return $preferred_quality->{url}, title_to_filename($title, "mp4"); |
166 |
} |
167 |
|
168 |
sub parse_youtube_url_encoded_fmt_stream_map { |
169 |
my($raw_map) = @_;; |
170 |
|
171 |
my $map = {}; |
172 |
|
173 |
foreach my $params (split /,/, $raw_map) { |
174 |
|
175 |
my $format = ""; |
176 |
my $url = ""; |
177 |
|
178 |
foreach my $pair (split /&/, $params) { |
179 |
my ($name, $value) = split /=/, $pair; |
180 |
if ($name eq "itag"){ |
181 |
$format = $value; |
182 |
} elsif ($name eq "url") { |
183 |
$url = uri_unescape($value); |
184 |
} |
185 |
} |
186 |
|
187 |
$map->{$format} = $url; |
188 |
} |
189 |
|
190 |
return $map; |
191 |
} |
192 |
|
135 |
sub download_fmt_map { |
193 |
sub download_fmt_map { |
136 |
my($self, $prefs, $browser, $title, $info, $fmt_map) = @_; |
194 |
my($self, $prefs, $browser, $title, $info, $fmt_map) = @_; |
137 |
|
195 |
|