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