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