4 from .common import InfoExtractor
10 compat_urllib_request,
16 class MetacafeIE(InfoExtractor):
17 """Information Extractor for metacafe.com."""
19 _VALID_URL = r'(?:http://)?(?:www\.)?metacafe\.com/watch/([^/]+)/([^/]+)/.*'
20 _DISCLAIMER = 'http://www.metacafe.com/family_filter/'
21 _FILTER_POST = 'http://www.metacafe.com/f/index.php?inputType=filter&controllerGroup=user'
25 u"add_ie": ["Youtube"],
26 u"url": u"http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/",
27 u"file": u"_aUehQsCQtM.flv",
29 u"upload_date": u"20090102",
30 u"title": u"The Electric Company | \"Short I\" | PBS KIDS GO!",
31 u"description": u"md5:2439a8ef6d5a70e380c22f5ad323e5a8",
33 u"uploader_id": u"PBS"
38 def report_disclaimer(self):
39 """Report disclaimer retrieval."""
40 self.to_screen(u'Retrieving disclaimer')
42 def _real_initialize(self):
44 request = compat_urllib_request.Request(self._DISCLAIMER)
46 self.report_disclaimer()
47 compat_urllib_request.urlopen(request).read()
48 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
49 raise ExtractorError(u'Unable to retrieve disclaimer: %s' % compat_str(err))
54 'submit': "Continue - I'm over 18",
56 request = compat_urllib_request.Request(self._FILTER_POST, compat_urllib_parse.urlencode(disclaimer_form))
58 self.report_age_confirmation()
59 compat_urllib_request.urlopen(request).read()
60 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
61 raise ExtractorError(u'Unable to confirm age: %s' % compat_str(err))
63 def _real_extract(self, url):
64 # Extract id and simplified title from URL
65 mobj = re.match(self._VALID_URL, url)
67 raise ExtractorError(u'Invalid URL: %s' % url)
69 video_id = mobj.group(1)
71 # Check if video comes from YouTube
72 mobj2 = re.match(r'^yt-(.*)$', video_id)
74 return [self.url_result('http://www.youtube.com/watch?v=%s' % mobj2.group(1), 'Youtube')]
76 # Retrieve video webpage to extract further information
77 webpage = self._download_webpage('http://www.metacafe.com/watch/%s/' % video_id, video_id)
79 # Extract URL, uploader and title from webpage
80 self.report_extraction(video_id)
81 mobj = re.search(r'(?m)&mediaURL=([^&]+)', webpage)
83 mediaURL = compat_urllib_parse.unquote(mobj.group(1))
84 video_extension = mediaURL[-3:]
86 # Extract gdaKey if available
87 mobj = re.search(r'(?m)&gdaKey=(.*?)&', webpage)
91 gdaKey = mobj.group(1)
92 video_url = '%s?__gda__=%s' % (mediaURL, gdaKey)
94 mobj = re.search(r' name="flashvars" value="(.*?)"', webpage)
96 raise ExtractorError(u'Unable to extract media URL')
97 vardict = compat_parse_qs(mobj.group(1))
98 if 'mediaData' not in vardict:
99 raise ExtractorError(u'Unable to extract media URL')
100 mobj = re.search(r'"mediaURL":"(?P<mediaURL>http.*?)",(.*?)"key":"(?P<key>.*?)"', vardict['mediaData'][0])
102 raise ExtractorError(u'Unable to extract media URL')
103 mediaURL = mobj.group('mediaURL').replace('\\/', '/')
104 video_extension = mediaURL[-3:]
105 video_url = '%s?__gda__=%s' % (mediaURL, mobj.group('key'))
107 mobj = re.search(r'(?im)<title>(.*) - Video</title>', webpage)
109 raise ExtractorError(u'Unable to extract title')
110 video_title = mobj.group(1).decode('utf-8')
112 mobj = re.search(r'submitter=(.*?);', webpage)
114 raise ExtractorError(u'Unable to extract uploader nickname')
115 video_uploader = mobj.group(1)
118 'id': video_id.decode('utf-8'),
119 'url': video_url.decode('utf-8'),
120 'uploader': video_uploader.decode('utf-8'),
122 'title': video_title,
123 'ext': video_extension.decode('utf-8'),