3 from .common import InfoExtractor
12 class DailymotionIE(InfoExtractor):
13 """Information Extractor for Dailymotion"""
15 _VALID_URL = r'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/video/([^/]+)'
16 IE_NAME = u'dailymotion'
18 def _real_extract(self, url):
19 # Extract id and simplified title from URL
20 mobj = re.match(self._VALID_URL, url)
22 video_id = mobj.group(1).split('_')[0].split('?')[0]
24 video_extension = 'mp4'
26 # Retrieve video webpage to extract further information
27 request = compat_urllib_request.Request(url)
28 request.add_header('Cookie', 'family_filter=off')
29 webpage = self._download_webpage(request, video_id)
31 # Extract URL, uploader and title from webpage
32 self.report_extraction(video_id)
33 mobj = re.search(r'\s*var flashvars = (.*)', webpage)
35 raise ExtractorError(u'Unable to extract media URL')
36 flashvars = compat_urllib_parse.unquote(mobj.group(1))
38 for key in ['hd1080URL', 'hd720URL', 'hqURL', 'sdURL', 'ldURL', 'video_url']:
41 self.to_screen(u'Using %s' % key)
44 raise ExtractorError(u'Unable to extract video URL')
46 mobj = re.search(r'"' + max_quality + r'":"(.+?)"', flashvars)
48 raise ExtractorError(u'Unable to extract video URL')
50 video_url = compat_urllib_parse.unquote(mobj.group(1)).replace('\\/', '/')
52 # TODO: support choosing qualities
54 mobj = re.search(r'<meta property="og:title" content="(?P<title>[^"]*)" />', webpage)
56 raise ExtractorError(u'Unable to extract title')
57 video_title = unescapeHTML(mobj.group('title'))
60 video_uploader = self._search_regex([r'(?im)<span class="owner[^\"]+?">[^<]+?<a [^>]+?>([^<]+?)</a>',
61 # Looking for official user
62 r'<(?:span|a) .*?rel="author".*?>([^<]+?)</'],
63 webpage, 'video uploader')
65 video_upload_date = None
66 mobj = re.search(r'<div class="[^"]*uploaded_cont[^"]*" title="[^"]*">([0-9]{2})-([0-9]{2})-([0-9]{4})</div>', webpage)
68 video_upload_date = mobj.group(3) + mobj.group(2) + mobj.group(1)
73 'uploader': video_uploader,
74 'upload_date': video_upload_date,
76 'ext': video_extension,