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