4 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 u'url': u'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech',
19 u'file': u'x33vw9.mp4',
20 u'md5': u'392c4b85a60a90dc4792da41ce3144eb',
22 u"uploader": u"Alex and Van .",
23 u"title": u"Tutoriel de Youtubeur\"DL DES VIDEO DE YOUTUBE\""
27 def _real_extract(self, url):
28 # Extract id and simplified title from URL
29 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group(1).split('_')[0].split('?')[0]
33 video_extension = 'mp4'
35 # Retrieve video webpage to extract further information
36 request = compat_urllib_request.Request(url)
37 request.add_header('Cookie', 'family_filter=off')
38 webpage = self._download_webpage(request, video_id)
40 # Extract URL, uploader and title from webpage
41 self.report_extraction(video_id)
44 mobj = re.search(r'<meta property="og:title" content="(?P<title>[^"]*)" />', webpage)
46 raise ExtractorError(u'Unable to extract title')
47 video_title = unescapeHTML(mobj.group('title'))
50 video_uploader = self._search_regex([r'(?im)<span class="owner[^\"]+?">[^<]+?<a [^>]+?>([^<]+?)</a>',
51 # Looking for official user
52 r'<(?:span|a) .*?rel="author".*?>([^<]+?)</'],
53 webpage, 'video uploader')
55 video_upload_date = None
56 mobj = re.search(r'<div class="[^"]*uploaded_cont[^"]*" title="[^"]*">([0-9]{2})-([0-9]{2})-([0-9]{4})</div>', webpage)
58 video_upload_date = mobj.group(3) + mobj.group(2) + mobj.group(1)
60 embed_url = 'http://www.dailymotion.com/embed/video/%s' % video_id
61 embed_page = self._download_webpage(embed_url, video_id,
62 u'Downloading embed page')
63 info = self._search_regex(r'var info = ({.*?}),', embed_page, 'video info')
64 info = json.loads(info)
66 # TODO: support choosing qualities
68 for key in ['stream_h264_hd1080_url','stream_h264_hd_url',
69 'stream_h264_hq_url','stream_h264_url',
70 'stream_h264_ld_url']:
71 if info.get(key):#key in info and info[key]:
73 self.to_screen(u'Using %s' % key)
76 raise ExtractorError(u'Unable to extract video URL')
77 video_url = info[max_quality]
82 'uploader': video_uploader,
83 'upload_date': video_upload_date,
85 'ext': video_extension,