]>
Commit | Line | Data |
---|---|---|
be3b8fa3 S |
1 | from __future__ import unicode_literals |
2 | ||
38cbc40a | 3 | import re |
38cbc40a PH |
4 | |
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
38cbc40a | 7 | compat_parse_qs, |
38cbc40a PH |
8 | compat_urllib_parse, |
9 | compat_urllib_request, | |
896d5b63 | 10 | determine_ext, |
38cbc40a | 11 | ExtractorError, |
ea6e8d54 | 12 | int_or_none, |
38cbc40a PH |
13 | ) |
14 | ||
38cbc40a | 15 | |
be3b8fa3 | 16 | class MetacafeIE(InfoExtractor): |
401983c6 | 17 | _VALID_URL = r'http://(?:www\.)?metacafe\.com/watch/([^/]+)/([^/]+)/.*' |
38cbc40a PH |
18 | _DISCLAIMER = 'http://www.metacafe.com/family_filter/' |
19 | _FILTER_POST = 'http://www.metacafe.com/f/index.php?inputType=filter&controllerGroup=user' | |
be3b8fa3 | 20 | IE_NAME = 'metacafe' |
66cf3ac3 | 21 | _TESTS = [ |
be3b8fa3 S |
22 | # Youtube video |
23 | { | |
24 | 'add_ie': ['Youtube'], | |
25 | 'url': 'http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/', | |
26 | 'info_dict': { | |
27 | 'id': '_aUehQsCQtM', | |
28 | 'ext': 'mp4', | |
29 | 'upload_date': '20090102', | |
401983c6 | 30 | 'title': 'The Electric Company | "Short I" | PBS KIDS GO!', |
be3b8fa3 S |
31 | 'description': 'md5:2439a8ef6d5a70e380c22f5ad323e5a8', |
32 | 'uploader': 'PBS', | |
33 | 'uploader_id': 'PBS' | |
34 | } | |
66cf3ac3 | 35 | }, |
be3b8fa3 S |
36 | # Normal metacafe video |
37 | { | |
38 | 'url': 'http://www.metacafe.com/watch/11121940/news_stuff_you_wont_do_with_your_playstation_4/', | |
39 | 'md5': '6e0bca200eaad2552e6915ed6fd4d9ad', | |
40 | 'info_dict': { | |
41 | 'id': '11121940', | |
42 | 'ext': 'mp4', | |
43 | 'title': 'News: Stuff You Won\'t Do with Your PlayStation 4', | |
44 | 'uploader': 'ign', | |
45 | 'description': 'Sony released a massive FAQ on the PlayStation Blog detailing the PS4\'s capabilities and limitations.', | |
46 | }, | |
66cf3ac3 | 47 | }, |
be3b8fa3 S |
48 | # AnyClip video |
49 | { | |
50 | 'url': 'http://www.metacafe.com/watch/an-dVVXnuY7Jh77J/the_andromeda_strain_1971_stop_the_bomb_part_3/', | |
51 | 'info_dict': { | |
52 | 'id': 'an-dVVXnuY7Jh77J', | |
53 | 'ext': 'mp4', | |
54 | 'title': 'The Andromeda Strain (1971): Stop the Bomb Part 3', | |
55 | 'uploader': 'anyclip', | |
56 | 'description': 'md5:38c711dd98f5bb87acf973d573442e67', | |
57 | }, | |
66cf3ac3 | 58 | }, |
be3b8fa3 S |
59 | # age-restricted video |
60 | { | |
61 | 'url': 'http://www.metacafe.com/watch/5186653/bbc_internal_christmas_tape_79_uncensored_outtakes_etc/', | |
62 | 'md5': '98dde7c1a35d02178e8ab7560fe8bd09', | |
63 | 'info_dict': { | |
64 | 'id': '5186653', | |
65 | 'ext': 'mp4', | |
66 | 'title': 'BBC INTERNAL Christmas Tape \'79 - UNCENSORED Outtakes, Etc.', | |
67 | 'uploader': 'Dwayne Pipe', | |
68 | 'description': 'md5:950bf4c581e2c059911fa3ffbe377e4b', | |
69 | 'age_limit': 18, | |
70 | }, | |
b9a2c538 | 71 | }, |
be3b8fa3 S |
72 | # cbs video |
73 | { | |
391dc3ee | 74 | 'url': 'http://www.metacafe.com/watch/cb-8VD4r_Zws8VP/open_this_is_face_the_nation_february_9/', |
be3b8fa3 | 75 | 'info_dict': { |
391dc3ee | 76 | 'id': '8VD4r_Zws8VP', |
be3b8fa3 | 77 | 'ext': 'flv', |
391dc3ee S |
78 | 'title': 'Open: This is Face the Nation, February 9', |
79 | 'description': 'md5:8a9ceec26d1f7ed6eab610834cc1a476', | |
80 | 'duration': 96, | |
be3b8fa3 S |
81 | }, |
82 | 'params': { | |
83 | # rtmp download | |
84 | 'skip_download': True, | |
85 | }, | |
b9a2c538 | 86 | }, |
ea6e8d54 PH |
87 | # Movieclips.com video |
88 | { | |
89 | 'url': 'http://www.metacafe.com/watch/mv-Wy7ZU/my_week_with_marilyn_do_you_love_me/', | |
90 | 'info_dict': { | |
91 | 'id': 'mv-Wy7ZU', | |
92 | 'ext': 'mp4', | |
93 | 'title': 'My Week with Marilyn - Do You Love Me?', | |
94 | 'description': 'From the movie My Week with Marilyn - Colin (Eddie Redmayne) professes his love to Marilyn (Michelle Williams) and gets her to promise to return to set and finish the movie.', | |
95 | 'uploader': 'movie_trailers', | |
96 | 'duration': 176, | |
97 | }, | |
98 | 'params': { | |
99 | 'skip_download': 'requires rtmpdump', | |
100 | } | |
101 | } | |
66cf3ac3 | 102 | ] |
83f6f68e | 103 | |
38cbc40a | 104 | def report_disclaimer(self): |
be3b8fa3 | 105 | self.to_screen('Retrieving disclaimer') |
38cbc40a PH |
106 | |
107 | def _real_initialize(self): | |
108 | # Retrieve disclaimer | |
baa7b197 | 109 | self.report_disclaimer() |
be3b8fa3 | 110 | self._download_webpage(self._DISCLAIMER, None, False, 'Unable to retrieve disclaimer') |
38cbc40a PH |
111 | |
112 | # Confirm age | |
113 | disclaimer_form = { | |
114 | 'filters': '0', | |
115 | 'submit': "Continue - I'm over 18", | |
be3b8fa3 | 116 | } |
38cbc40a | 117 | request = compat_urllib_request.Request(self._FILTER_POST, compat_urllib_parse.urlencode(disclaimer_form)) |
66cf3ac3 | 118 | request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
baa7b197 | 119 | self.report_age_confirmation() |
be3b8fa3 | 120 | self._download_webpage(request, None, False, 'Unable to confirm age') |
2c139607 | 121 | |
38cbc40a PH |
122 | def _real_extract(self, url): |
123 | # Extract id and simplified title from URL | |
124 | mobj = re.match(self._VALID_URL, url) | |
125 | if mobj is None: | |
be3b8fa3 | 126 | raise ExtractorError('Invalid URL: %s' % url) |
38cbc40a PH |
127 | |
128 | video_id = mobj.group(1) | |
129 | ||
b9a2c538 JMF |
130 | # the video may come from an external site |
131 | m_external = re.match('^(\w{2})-(.*)$', video_id) | |
132 | if m_external is not None: | |
133 | prefix, ext_id = m_external.groups() | |
134 | # Check if video comes from YouTube | |
135 | if prefix == 'yt': | |
136 | return self.url_result('http://www.youtube.com/watch?v=%s' % ext_id, 'Youtube') | |
137 | # CBS videos use theplatform.com | |
138 | if prefix == 'cb': | |
139 | return self.url_result('theplatform:%s' % ext_id, 'ThePlatform') | |
38cbc40a PH |
140 | |
141 | # Retrieve video webpage to extract further information | |
896d5b63 | 142 | req = compat_urllib_request.Request('http://www.metacafe.com/watch/%s/' % video_id) |
66cf3ac3 JMF |
143 | |
144 | # AnyClip videos require the flashversion cookie so that we get the link | |
145 | # to the mp4 file | |
146 | mobj_an = re.match(r'^an-(.*?)$', video_id) | |
147 | if mobj_an: | |
148 | req.headers['Cookie'] = 'flashVersion=0;' | |
896d5b63 | 149 | webpage = self._download_webpage(req, video_id) |
38cbc40a PH |
150 | |
151 | # Extract URL, uploader and title from webpage | |
152 | self.report_extraction(video_id) | |
c15235cd | 153 | video_url = None |
38cbc40a PH |
154 | mobj = re.search(r'(?m)&mediaURL=([^&]+)', webpage) |
155 | if mobj is not None: | |
156 | mediaURL = compat_urllib_parse.unquote(mobj.group(1)) | |
896d5b63 | 157 | video_ext = mediaURL[-3:] |
38cbc40a PH |
158 | |
159 | # Extract gdaKey if available | |
160 | mobj = re.search(r'(?m)&gdaKey=(.*?)&', webpage) | |
161 | if mobj is None: | |
162 | video_url = mediaURL | |
163 | else: | |
164 | gdaKey = mobj.group(1) | |
165 | video_url = '%s?__gda__=%s' % (mediaURL, gdaKey) | |
c15235cd | 166 | if video_url is None: |
896d5b63 PH |
167 | mobj = re.search(r'<video src="([^"]+)"', webpage) |
168 | if mobj: | |
169 | video_url = mobj.group(1) | |
170 | video_ext = 'mp4' | |
c15235cd PH |
171 | if video_url is None: |
172 | flashvars = self._search_regex( | |
173 | r' name="flashvars" value="(.*?)"', webpage, 'flashvars', | |
174 | default=None) | |
175 | if flashvars: | |
12c3ec33 | 176 | vardict = compat_parse_qs(flashvars) |
896d5b63 | 177 | if 'mediaData' not in vardict: |
be3b8fa3 S |
178 | raise ExtractorError('Unable to extract media URL') |
179 | mobj = re.search( | |
180 | r'"mediaURL":"(?P<mediaURL>http.*?)",(.*?)"key":"(?P<key>.*?)"', vardict['mediaData'][0]) | |
896d5b63 | 181 | if mobj is None: |
be3b8fa3 | 182 | raise ExtractorError('Unable to extract media URL') |
896d5b63 PH |
183 | mediaURL = mobj.group('mediaURL').replace('\\/', '/') |
184 | video_url = '%s?__gda__=%s' % (mediaURL, mobj.group('key')) | |
185 | video_ext = determine_ext(video_url) | |
ea6e8d54 PH |
186 | if video_url is None: |
187 | player_url = self._search_regex( | |
188 | r"swfobject\.embedSWF\('([^']+)'", | |
189 | webpage, 'config URL', default=None) | |
190 | if player_url: | |
191 | config_url = self._search_regex( | |
192 | r'config=(.+)$', player_url, 'config URL') | |
193 | config_doc = self._download_xml( | |
194 | config_url, video_id, | |
195 | note='Downloading video config') | |
196 | smil_url = config_doc.find('.//properties').attrib['smil_file'] | |
197 | smil_doc = self._download_xml( | |
198 | smil_url, video_id, | |
199 | note='Downloading SMIL document') | |
200 | base_url = smil_doc.find('./head/meta').attrib['base'] | |
201 | video_url = [] | |
202 | for vn in smil_doc.findall('.//video'): | |
203 | br = int(vn.attrib['system-bitrate']) | |
204 | play_path = vn.attrib['src'] | |
205 | video_url.append({ | |
206 | 'format_id': 'smil-%d' % br, | |
207 | 'url': base_url, | |
208 | 'play_path': play_path, | |
209 | 'page_url': url, | |
210 | 'player_url': player_url, | |
211 | 'ext': play_path.partition(':')[0], | |
212 | }) | |
38cbc40a | 213 | |
ea6e8d54 PH |
214 | if video_url is None: |
215 | raise ExtractorError('Unsupported video type') | |
c15235cd | 216 | |
12c3ec33 PH |
217 | video_title = self._html_search_regex( |
218 | r'(?im)<title>(.*) - Video</title>', webpage, 'title') | |
7e24b09d | 219 | description = self._og_search_description(webpage) |
54ab1939 | 220 | thumbnail = self._og_search_thumbnail(webpage) |
f085f960 | 221 | video_uploader = self._html_search_regex( |
6c758d79 | 222 | r'submitter=(.*?);|googletag\.pubads\(\)\.setTargeting\("(?:channel|submiter)","([^"]+)"\);', |
be3b8fa3 | 223 | webpage, 'uploader nickname', fatal=False) |
ea6e8d54 PH |
224 | duration = int_or_none( |
225 | self._html_search_meta('video:duration', webpage)) | |
226 | ||
227 | age_limit = ( | |
228 | 18 | |
229 | if re.search(r'"contentRating":"restricted"', webpage) | |
230 | else 0) | |
38cbc40a | 231 | |
ea6e8d54 PH |
232 | if isinstance(video_url, list): |
233 | formats = video_url | |
66cf3ac3 | 234 | else: |
ea6e8d54 PH |
235 | formats = [{ |
236 | 'url': video_url, | |
237 | 'ext': video_ext, | |
238 | }] | |
66cf3ac3 | 239 | |
ea6e8d54 | 240 | self._sort_formats(formats) |
5910724b | 241 | return { |
be3b8fa3 | 242 | 'id': video_id, |
7e24b09d | 243 | 'description': description, |
896d5b63 | 244 | 'uploader': video_uploader, |
be3b8fa3 | 245 | 'title': video_title, |
12c3ec33 | 246 | 'thumbnail': thumbnail, |
66cf3ac3 | 247 | 'age_limit': age_limit, |
ea6e8d54 PH |
248 | 'formats': formats, |
249 | 'duration': duration, | |
5910724b | 250 | } |