1 from __future__ import unicode_literals
6 from .common import InfoExtractor
10 compat_urllib_parse_unquote,
16 get_element_by_attribute,
21 class MetacafeIE(InfoExtractor):
22 _VALID_URL = r'https?://(?:www\.)?metacafe\.com/watch/(?P<video_id>[^/]+)/(?P<display_id>[^/?#]+)'
23 _DISCLAIMER = 'http://www.metacafe.com/family_filter/'
24 _FILTER_POST = 'http://www.metacafe.com/f/index.php?inputType=filter&controllerGroup=user'
29 'add_ie': ['Youtube'],
30 'url': 'http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/',
34 'upload_date': '20090102',
35 'title': 'The Electric Company | "Short I" | PBS KIDS GO!',
36 'description': 'md5:2439a8ef6d5a70e380c22f5ad323e5a8',
41 # Normal metacafe video
43 'url': 'http://www.metacafe.com/watch/11121940/news_stuff_you_wont_do_with_your_playstation_4/',
44 'md5': '6e0bca200eaad2552e6915ed6fd4d9ad',
48 'title': 'News: Stuff You Won\'t Do with Your PlayStation 4',
50 'description': 'Sony released a massive FAQ on the PlayStation Blog detailing the PS4\'s capabilities and limitations.',
52 'skip': 'Page is temporarily unavailable.',
54 # metacafe video with family filter
56 'url': 'http://www.metacafe.com/watch/2155630/adult_art_by_david_hart_156/',
57 'md5': 'b06082c5079bbdcde677a6291fbdf376',
61 'title': 'Adult Art By David Hart 156',
63 'description': 'md5:9afac8fc885252201ad14563694040fc',
66 'skip_download': True,
71 'url': 'http://www.metacafe.com/watch/an-dVVXnuY7Jh77J/the_andromeda_strain_1971_stop_the_bomb_part_3/',
73 'id': 'an-dVVXnuY7Jh77J',
75 'title': 'The Andromeda Strain (1971): Stop the Bomb Part 3',
76 'uploader': 'AnyClip',
77 'description': 'md5:cbef0460d31e3807f6feb4e7a5952e5b',
80 # age-restricted video
82 'url': 'http://www.metacafe.com/watch/5186653/bbc_internal_christmas_tape_79_uncensored_outtakes_etc/',
83 'md5': '98dde7c1a35d02178e8ab7560fe8bd09',
87 'title': 'BBC INTERNAL Christmas Tape \'79 - UNCENSORED Outtakes, Etc.',
88 'uploader': 'Dwayne Pipe',
89 'description': 'md5:950bf4c581e2c059911fa3ffbe377e4b',
95 'url': 'http://www.metacafe.com/watch/cb-8VD4r_Zws8VP/open_this_is_face_the_nation_february_9/',
99 'title': 'Open: This is Face the Nation, February 9',
100 'description': 'md5:8a9ceec26d1f7ed6eab610834cc1a476',
102 'uploader': 'CBSI-NEW',
103 'upload_date': '20140209',
104 'timestamp': 1391959800,
108 'skip_download': True,
111 # Movieclips.com video
113 'url': 'http://www.metacafe.com/watch/mv-Wy7ZU/my_week_with_marilyn_do_you_love_me/',
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',
123 'skip_download': 'requires rtmpdump',
128 def report_disclaimer(self):
129 self.to_screen('Retrieving disclaimer')
131 def _real_extract(self, url):
132 # Extract id and simplified title from URL
133 video_id, display_id = re.match(self._VALID_URL, url).groups()
135 # the video may come from an external site
136 m_external = re.match(r'^(\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
141 return self.url_result('http://www.youtube.com/watch?v=%s' % ext_id, 'Youtube')
142 # CBS videos use theplatform.com
144 return self.url_result('theplatform:%s' % ext_id, 'ThePlatform')
147 # Disable family filter
148 'Cookie': 'user=%s; ' % compat_urllib_parse.quote(json.dumps({'ffilter': False}))
151 # AnyClip videos require the flashversion cookie so that we get the link
153 if video_id.startswith('an-'):
154 headers['Cookie'] += 'flashVersion=0; '
156 # Retrieve video webpage to extract further information
157 webpage = self._download_webpage(url, video_id, headers=headers)
159 error = get_element_by_attribute(
160 'class', 'notfound-page-title', webpage)
162 raise ExtractorError(error, expected=True)
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')
167 # Extract URL, uploader and title from webpage
168 self.report_extraction(video_id)
170 mobj = re.search(r'(?m)&(?:media|video)URL=([^&]+)', webpage)
172 mediaURL = compat_urllib_parse_unquote(mobj.group(1))
173 video_ext = determine_ext(mediaURL)
175 # Extract gdaKey if available
176 mobj = re.search(r'(?m)&gdaKey=(.*?)&', webpage)
180 gdaKey = mobj.group(1)
181 video_url = '%s?__gda__=%s' % (mediaURL, gdaKey)
182 if video_url is None:
183 mobj = re.search(r'<video src="([^"]+)"', webpage)
185 video_url = mobj.group(1)
187 if video_url is None:
188 flashvars = self._search_regex(
189 r' name="flashvars" value="(.*?)"', webpage, 'flashvars',
192 vardict = compat_parse_qs(flashvars)
193 if 'mediaData' not in vardict:
194 raise ExtractorError('Unable to extract media URL')
196 r'"mediaURL":"(?P<mediaURL>http.*?)",(.*?)"key":"(?P<key>.*?)"', vardict['mediaData'][0])
198 raise ExtractorError('Unable to extract media URL')
199 mediaURL = mobj.group('mediaURL').replace('\\/', '/')
200 video_url = '%s?__gda__=%s' % (mediaURL, mobj.group('key'))
201 video_ext = determine_ext(video_url)
202 if video_url is None:
203 player_url = self._search_regex(
204 r"swfobject\.embedSWF\('([^']+)'",
205 webpage, 'config URL', default=None)
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(
215 note='Downloading SMIL document')
216 base_url = smil_doc.find('./head/meta').attrib['base']
218 for vn in smil_doc.findall('.//video'):
219 br = int(vn.attrib['system-bitrate'])
220 play_path = vn.attrib['src']
222 'format_id': 'smil-%d' % br,
224 'play_path': play_path,
226 'player_url': player_url,
227 'ext': play_path.partition(':')[0],
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)
235 for source in flashvars.get('sources'):
236 source_url = source.get('src')
239 ext = mimetype2ext(source.get('type')) or determine_ext(source_url)
241 video_url.extend(self._extract_m3u8_formats(
242 source_url, video_id, 'mp4',
243 'm3u8_native', m3u8_id='hls', fatal=False))
250 if video_url is None:
251 raise ExtractorError('Unsupported video type')
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)
258 video_uploader = self._html_search_regex(
259 r'submitter=(.*?);|googletag\.pubads\(\)\.setTargeting\("(?:channel|submiter)","([^"]+)"\);',
260 webpage, 'uploader nickname', fatal=False)
261 duration = int_or_none(
262 self._html_search_meta('video:duration', webpage, default=None))
265 if re.search(r'(?:"contentRating":|"rating",)"restricted"', webpage)
268 if isinstance(video_url, list):
275 self._sort_formats(formats)
279 'display_id': display_id,
280 'description': description,
281 'uploader': video_uploader,
282 'title': video_title,
283 'thumbnail': thumbnail,
284 'age_limit': age_limit,
286 'duration': duration,