1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
8 compat_urllib_parse_unquote
,
15 get_element_by_attribute
,
20 class MetacafeIE(InfoExtractor
):
21 _VALID_URL
= r
'https?://(?:www\.)?metacafe\.com/watch/(?P<video_id>[^/]+)/(?P<display_id>[^/?#]+)'
22 _DISCLAIMER
= 'http://www.metacafe.com/family_filter/'
23 _FILTER_POST
= 'http://www.metacafe.com/f/index.php?inputType=filter&controllerGroup=user'
28 'add_ie': ['Youtube'],
29 'url': 'http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/',
33 'upload_date': '20090102',
34 'title': 'The Electric Company | "Short I" | PBS KIDS GO!',
35 'description': 'md5:2439a8ef6d5a70e380c22f5ad323e5a8',
40 # Normal metacafe video
42 'url': 'http://www.metacafe.com/watch/11121940/news_stuff_you_wont_do_with_your_playstation_4/',
43 'md5': '6e0bca200eaad2552e6915ed6fd4d9ad',
47 'title': 'News: Stuff You Won\'t Do with Your PlayStation 4',
49 'description': 'Sony released a massive FAQ on the PlayStation Blog detailing the PS4\'s capabilities and limitations.',
51 'skip': 'Page is temporarily unavailable.',
55 'url': 'http://www.metacafe.com/watch/an-dVVXnuY7Jh77J/the_andromeda_strain_1971_stop_the_bomb_part_3/',
57 'id': 'an-dVVXnuY7Jh77J',
59 'title': 'The Andromeda Strain (1971): Stop the Bomb Part 3',
60 'uploader': 'AnyClip',
61 'description': 'md5:cbef0460d31e3807f6feb4e7a5952e5b',
64 # age-restricted video
66 'url': 'http://www.metacafe.com/watch/5186653/bbc_internal_christmas_tape_79_uncensored_outtakes_etc/',
67 'md5': '98dde7c1a35d02178e8ab7560fe8bd09',
71 'title': 'BBC INTERNAL Christmas Tape \'79 - UNCENSORED Outtakes, Etc.',
72 'uploader': 'Dwayne Pipe',
73 'description': 'md5:950bf4c581e2c059911fa3ffbe377e4b',
79 'url': 'http://www.metacafe.com/watch/cb-8VD4r_Zws8VP/open_this_is_face_the_nation_february_9/',
83 'title': 'Open: This is Face the Nation, February 9',
84 'description': 'md5:8a9ceec26d1f7ed6eab610834cc1a476',
86 'uploader': 'CBSI-NEW',
87 'upload_date': '20140209',
88 'timestamp': 1391959800,
92 'skip_download': True,
95 # Movieclips.com video
97 'url': 'http://www.metacafe.com/watch/mv-Wy7ZU/my_week_with_marilyn_do_you_love_me/',
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',
107 'skip_download': 'requires rtmpdump',
112 def report_disclaimer(self
):
113 self
.to_screen('Retrieving disclaimer')
115 def _confirm_age(self
):
116 # Retrieve disclaimer
117 self
.report_disclaimer()
118 self
._download
_webpage
(self
._DISCLAIMER
, None, False, 'Unable to retrieve disclaimer')
121 self
.report_age_confirmation()
122 self
._download
_webpage
(
123 self
._FILTER
_POST
, None, False, 'Unable to confirm age',
124 data
=urlencode_postdata({
126 'submit': "Continue - I'm over 18",
128 'Content-Type': 'application/x-www-form-urlencoded',
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')
146 # self._confirm_age()
148 # AnyClip videos require the flashversion cookie so that we get the link
151 if video_id
.startswith('an-'):
152 headers
['Cookie'] = 'flashVersion=0;'
154 # Retrieve video webpage to extract further information
155 webpage
= self
._download
_webpage
(url
, video_id
, headers
=headers
)
157 error
= get_element_by_attribute(
158 'class', 'notfound-page-title', webpage
)
160 raise ExtractorError(error
, expected
=True)
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')
165 # Extract URL, uploader and title from webpage
166 self
.report_extraction(video_id
)
168 mobj
= re
.search(r
'(?m)&(?:media|video)URL=([^&]+)', webpage
)
170 mediaURL
= compat_urllib_parse_unquote(mobj
.group(1))
171 video_ext
= determine_ext(mediaURL
)
173 # Extract gdaKey if available
174 mobj
= re
.search(r
'(?m)&gdaKey=(.*?)&', webpage
)
178 gdaKey
= mobj
.group(1)
179 video_url
= '%s?__gda__=%s' % (mediaURL
, gdaKey
)
180 if video_url
is None:
181 mobj
= re
.search(r
'<video src="([^"]+)"', webpage
)
183 video_url
= mobj
.group(1)
185 if video_url
is None:
186 flashvars
= self
._search
_regex
(
187 r
' name="flashvars" value="(.*?)"', webpage
, 'flashvars',
190 vardict
= compat_parse_qs(flashvars
)
191 if 'mediaData' not in vardict
:
192 raise ExtractorError('Unable to extract media URL')
194 r
'"mediaURL":"(?P<mediaURL>http.*?)",(.*?)"key":"(?P<key>.*?)"', vardict
['mediaData'][0])
196 raise ExtractorError('Unable to extract media URL')
197 mediaURL
= mobj
.group('mediaURL').replace('\\/', '/')
198 video_url
= '%s?__gda__=%s' % (mediaURL
, mobj
.group('key'))
199 video_ext
= determine_ext(video_url
)
200 if video_url
is None:
201 player_url
= self
._search
_regex
(
202 r
"swfobject\.embedSWF\('([^']+)'",
203 webpage
, 'config URL', default
=None)
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
(
213 note
='Downloading SMIL document')
214 base_url
= smil_doc
.find('./head/meta').attrib
['base']
216 for vn
in smil_doc
.findall('.//video'):
217 br
= int(vn
.attrib
['system-bitrate'])
218 play_path
= vn
.attrib
['src']
220 'format_id': 'smil-%d' % br
,
222 'play_path': play_path
,
224 'player_url': player_url
,
225 'ext': play_path
.partition(':')[0],
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)
233 for source
in flashvars
.get('sources'):
234 source_url
= source
.get('src')
237 ext
= mimetype2ext(source
.get('type')) or determine_ext(source_url
)
239 video_url
.extend(self
._extract
_m
3u8_formats
(
240 source_url
, video_id
, 'mp4',
241 'm3u8_native', m3u8_id
='hls', fatal
=False))
248 if video_url
is None:
249 raise ExtractorError('Unsupported video type')
251 description
= self
._html
_search
_meta
(
252 ['og:description', 'twitter:description', 'description'],
253 webpage
, 'title', fatal
=False)
254 thumbnail
= self
._html
_search
_meta
(
255 ['og:image', 'twitter:image'], webpage
, 'title', fatal
=False)
256 video_uploader
= self
._html
_search
_regex
(
257 r
'submitter=(.*?);|googletag\.pubads\(\)\.setTargeting\("(?:channel|submiter)","([^"]+)"\);',
258 webpage
, 'uploader nickname', fatal
=False)
259 duration
= int_or_none(
260 self
._html
_search
_meta
('video:duration', webpage
, default
=None))
263 if re
.search(r
'(?:"contentRating":|"rating",)"restricted"', webpage
)
266 if isinstance(video_url
, list):
273 self
._sort
_formats
(formats
)
277 'display_id': display_id
,
278 'description': description
,
279 'uploader': video_uploader
,
280 'title': video_title
,
281 'thumbnail': thumbnail
,
282 'age_limit': age_limit
,
284 'duration': duration
,