3 from .common import InfoExtractor
13 class MetacafeIE(InfoExtractor):
14 """Information Extractor for metacafe.com."""
16 _VALID_URL = r'(?:http://)?(?:www\.)?metacafe\.com/watch/([^/]+)/([^/]+)/.*'
17 _DISCLAIMER = 'http://www.metacafe.com/family_filter/'
18 _FILTER_POST = 'http://www.metacafe.com/f/index.php?inputType=filter&controllerGroup=user'
23 u"add_ie": ["Youtube"],
24 u"url": u"http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/",
25 u"file": u"_aUehQsCQtM.mp4",
27 u"upload_date": u"20090102",
28 u"title": u"The Electric Company | \"Short I\" | PBS KIDS GO!",
29 u"description": u"md5:2439a8ef6d5a70e380c22f5ad323e5a8",
31 u"uploader_id": u"PBS"
34 # Normal metacafe video
36 u'url': u'http://www.metacafe.com/watch/11121940/news_stuff_you_wont_do_with_your_playstation_4/',
37 u'md5': u'6e0bca200eaad2552e6915ed6fd4d9ad',
41 u'title': u'News: Stuff You Won\'t Do with Your PlayStation 4',
43 u'description': u'Sony released a massive FAQ on the PlayStation Blog detailing the PS4\'s capabilities and limitations.',
48 u"url": u"http://www.metacafe.com/watch/an-dVVXnuY7Jh77J/the_andromeda_strain_1971_stop_the_bomb_part_3/",
49 u"file": u"an-dVVXnuY7Jh77J.mp4",
51 u"title": u"The Andromeda Strain (1971): Stop the Bomb Part 3",
52 u"uploader": u"anyclip",
53 u"description": u"md5:38c711dd98f5bb87acf973d573442e67",
56 # age-restricted video
58 u'url': u'http://www.metacafe.com/watch/5186653/bbc_internal_christmas_tape_79_uncensored_outtakes_etc/',
59 u'md5': u'98dde7c1a35d02178e8ab7560fe8bd09',
63 u'title': u'BBC INTERNAL Christmas Tape \'79 - UNCENSORED Outtakes, Etc.',
64 u'uploader': u'Dwayne Pipe',
65 u'description': u'md5:950bf4c581e2c059911fa3ffbe377e4b',
71 u'url': u'http://www.metacafe.com/watch/cb-0rOxMBabDXN6/samsung_galaxy_note_2_samsungs_next_generation_phablet/',
73 u'id': u'0rOxMBabDXN6',
75 u'title': u'Samsung Galaxy Note 2: Samsung\'s next-generation phablet',
76 u'description': u'md5:54d49fac53d26d5a0aaeccd061ada09d',
81 u'skip_download': True,
87 def report_disclaimer(self):
88 """Report disclaimer retrieval."""
89 self.to_screen(u'Retrieving disclaimer')
91 def _real_initialize(self):
93 self.report_disclaimer()
94 self._download_webpage(self._DISCLAIMER, None, False, u'Unable to retrieve disclaimer')
99 'submit': "Continue - I'm over 18",
101 request = compat_urllib_request.Request(self._FILTER_POST, compat_urllib_parse.urlencode(disclaimer_form))
102 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
103 self.report_age_confirmation()
104 self._download_webpage(request, None, False, u'Unable to confirm age')
106 def _real_extract(self, url):
107 # Extract id and simplified title from URL
108 mobj = re.match(self._VALID_URL, url)
110 raise ExtractorError(u'Invalid URL: %s' % url)
112 video_id = mobj.group(1)
114 # the video may come from an external site
115 m_external = re.match('^(\w{2})-(.*)$', video_id)
116 if m_external is not None:
117 prefix, ext_id = m_external.groups()
118 # Check if video comes from YouTube
120 return self.url_result('http://www.youtube.com/watch?v=%s' % ext_id, 'Youtube')
121 # CBS videos use theplatform.com
123 return self.url_result('theplatform:%s' % ext_id, 'ThePlatform')
125 # Retrieve video webpage to extract further information
126 req = compat_urllib_request.Request('http://www.metacafe.com/watch/%s/' % video_id)
128 # AnyClip videos require the flashversion cookie so that we get the link
130 mobj_an = re.match(r'^an-(.*?)$', video_id)
132 req.headers['Cookie'] = 'flashVersion=0;'
133 webpage = self._download_webpage(req, video_id)
135 # Extract URL, uploader and title from webpage
136 self.report_extraction(video_id)
137 mobj = re.search(r'(?m)&mediaURL=([^&]+)', webpage)
139 mediaURL = compat_urllib_parse.unquote(mobj.group(1))
140 video_ext = mediaURL[-3:]
142 # Extract gdaKey if available
143 mobj = re.search(r'(?m)&gdaKey=(.*?)&', webpage)
147 gdaKey = mobj.group(1)
148 video_url = '%s?__gda__=%s' % (mediaURL, gdaKey)
150 mobj = re.search(r'<video src="([^"]+)"', webpage)
152 video_url = mobj.group(1)
155 mobj = re.search(r' name="flashvars" value="(.*?)"', webpage)
157 raise ExtractorError(u'Unable to extract media URL')
158 vardict = compat_parse_qs(mobj.group(1))
159 if 'mediaData' not in vardict:
160 raise ExtractorError(u'Unable to extract media URL')
161 mobj = re.search(r'"mediaURL":"(?P<mediaURL>http.*?)",(.*?)"key":"(?P<key>.*?)"', vardict['mediaData'][0])
163 raise ExtractorError(u'Unable to extract media URL')
164 mediaURL = mobj.group('mediaURL').replace('\\/', '/')
165 video_url = '%s?__gda__=%s' % (mediaURL, mobj.group('key'))
166 video_ext = determine_ext(video_url)
168 video_title = self._html_search_regex(r'(?im)<title>(.*) - Video</title>', webpage, u'title')
169 description = self._og_search_description(webpage)
170 video_uploader = self._html_search_regex(
171 r'submitter=(.*?);|googletag\.pubads\(\)\.setTargeting\("(?:channel|submiter)","([^"]+)"\);',
172 webpage, u'uploader nickname', fatal=False)
174 if re.search(r'"contentRating":"restricted"', webpage) is not None:
183 'description': description,
184 'uploader': video_uploader,
186 'title': video_title,
188 'age_limit': age_limit,