Gentoo Archives: gentoo-commits

From: "Markos Chandras (hwoarang)" <hwoarang@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in media-video/get_flash_videos/files: get_flash_videos-youtubefix.patch
Date: Wed, 29 Feb 2012 21:33:44
Message-Id: 20120229213332.62AA02004C@flycatcher.gentoo.org
1 hwoarang 12/02/29 21:33:32
2
3 Added: get_flash_videos-youtubefix.patch
4 Log:
5 Apply youtube fix from upstream. Bug #405761. Thanks to Peter Fox <gentoo@×××××××××××××××××.uk>
6
7 (Portage version: 2.2.0_alpha88/cvs/Linux x86_64)
8
9 Revision Changes Path
10 1.1 media-video/get_flash_videos/files/get_flash_videos-youtubefix.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/media-video/get_flash_videos/files/get_flash_videos-youtubefix.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/media-video/get_flash_videos/files/get_flash_videos-youtubefix.patch?rev=1.1&content-type=text/plain
14
15 Index: get_flash_videos-youtubefix.patch
16 ===================================================================
17 https://bugs.gentoo.org/show_bug.cgi?id=405761
18
19 https://github.com/richcollins/get-flash-videos/commit/27e0f1d214e291debfd567b1652908d0ef6b79d1#lib/FlashVideo/Site
20
21 --- lib/FlashVideo/Site/Youtube.pm~ 2010-11-30 14:34:17.000000000 +0000
22 +++ lib/FlashVideo/Site/Youtube.pm 2012-02-20 23:56:35.000000000 +0000
23 @@ -26,6 +26,7 @@
24 if($embed_url !~ m!youtube\.com/watch!) {
25 $browser->get($embed_url);
26 if ($browser->response->header('Location') =~ m!/swf/.*video_id=([^&]+)!
27 + || $browser->content =~ m!\<iframe[^\>]*src="http://www.youtube.com/embed/([^"]+)"!i
28 || $embed_url =~ m!/v/([-_a-z0-9]+)!i
29 || $browser->uri =~ m!v%3D([-_a-z0-9]+)!i) {
30 # We ended up on a embedded SWF or other redirect page
31 @@ -48,12 +49,19 @@
32 # If the page contains fmt_url_map, then process this. With this, we
33 # don't require the 't' parameter.
34 if ($browser->content =~ /["']fmt_url_map["']:\s{0,3}(["'][^"']+["'])/) {
35 - debug "Using fmt_url_map method from page ($1)";
36 - return $self->download_fmt_map($prefs, $browser, $title, {}, @{from_json $1});
37 + my $fmt_map = $1;
38 + if ($fmt_map !~ /\|/) {
39 + # $fmt_map is double escaped. We should unescape it here just
40 + # once. Be careful not to unescape ',' in the URL.
41 + $fmt_map = uri_unescape($fmt_map);
42 + }
43 + debug "Using fmt_url_map method from page ($fmt_map)";
44 + return $self->download_fmt_map($prefs, $browser, $title, {}, @{from_json $fmt_map});
45 }
46
47 my $video_id;
48 if ($browser->content =~ /(?:var pageVideoId =|(?:CFG_)?VIDEO_ID'?\s*:)\s*'(.+?)'/
49 + || $browser->content =~ /"video_id": "([^"]+)"/
50 || $embed_url =~ /v=([^&]+)/) {
51 $video_id = $1;
52 } else {
53 @@ -125,6 +133,9 @@
54 } elsif($info{fmt_url_map}) {
55 debug "Using fmt_url_map method from info";
56 return $self->download_fmt_map($prefs, $browser, $title, \%info, $info{fmt_url_map});
57 + } elsif($info{url_encoded_fmt_stream_map}) {
58 + debug "Using url_encoded_fmt_stream_map method from info";
59 + return $self->download_url_encoded_fmt_stream_map($prefs, $browser, $title, \%info, $info{url_encoded_fmt_stream_map});
60 }
61 }
62
63 @@ -132,6 +143,53 @@
64 return download_get_video($browser, $prefs, $video_id, $title, $t);
65 }
66
67 +sub download_url_encoded_fmt_stream_map {
68 + my($self, $prefs, $browser, $title, $info, $fmt_map) = @_;
69 +
70 + my $fmt_url_map = parse_youtube_url_encoded_fmt_stream_map($fmt_map);
71 +
72 + if (!$title and $browser->uri->as_string =~ m'/user/.*?#') {
73 + my $video_id = (split /\//, $browser->uri->fragment)[-1];
74 +
75 + my %info = get_youtube_video_info($browser->clone, $video_id);
76 +
77 + $title = $info->{title};
78 + }
79 +
80 + my $preferred_quality = $prefs->quality->choose(map { $fmt_url_map->{$_->{id}}
81 + ? { resolution => $_->{resolution}, url => $fmt_url_map->{$_->{id}} }
82 + : () } @formats);
83 +
84 + $browser->allow_redirects;
85 +
86 + return $preferred_quality->{url}, title_to_filename($title, "mp4");
87 +}
88 +
89 +sub parse_youtube_url_encoded_fmt_stream_map {
90 + my($raw_map) = @_;;
91 +
92 + my $map = {};
93 +
94 + foreach my $params (split /,/, $raw_map) {
95 +
96 + my $format = "";
97 + my $url = "";
98 +
99 + foreach my $pair (split /&/, $params) {
100 + my ($name, $value) = split /=/, $pair;
101 + if ($name eq "itag"){
102 + $format = $value;
103 + } elsif ($name eq "url") {
104 + $url = uri_unescape($value);
105 + }
106 + }
107 +
108 + $map->{$format} = $url;
109 + }
110 +
111 + return $map;
112 +}
113 +
114 sub download_fmt_map {
115 my($self, $prefs, $browser, $title, $info, $fmt_map) = @_;