6 from .common import InfoExtractor
7 from .subtitles import NoAutoSubtitlesIE
12 compat_urllib_request,
14 get_element_by_attribute,
21 class DailyMotionSubtitlesIE(NoAutoSubtitlesIE):
23 def _get_available_subtitles(self, video_id):
24 request = compat_urllib_request.Request('https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id)
26 sub_list = compat_urllib_request.urlopen(request).read().decode('utf-8')
27 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
28 self._downloader.report_warning(u'unable to download video subtitles: %s' % compat_str(err))
30 info = json.loads(sub_list)
31 if (info['total'] > 0):
32 sub_lang_list = dict((l['language'], l['url']) for l in info['list'])
34 self._downloader.report_warning(u'video doesn\'t have subtitles')
37 class DailymotionIE(DailyMotionSubtitlesIE, InfoExtractor):
38 """Information Extractor for Dailymotion"""
40 _VALID_URL = r'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/(?:embed/)?video/([^/]+)'
41 IE_NAME = u'dailymotion'
43 u'url': u'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech',
44 u'file': u'x33vw9.mp4',
45 u'md5': u'392c4b85a60a90dc4792da41ce3144eb',
47 u"uploader": u"Amphora Alex and Van .",
48 u"title": u"Tutoriel de Youtubeur\"DL DES VIDEO DE YOUTUBE\""
52 def _real_extract(self, url):
53 # Extract id and simplified title from URL
54 mobj = re.match(self._VALID_URL, url)
56 video_id = mobj.group(1).split('_')[0].split('?')[0]
58 video_extension = 'mp4'
59 url = 'http://www.dailymotion.com/video/%s' % video_id
61 # Retrieve video webpage to extract further information
62 request = compat_urllib_request.Request(url)
63 request.add_header('Cookie', 'family_filter=off')
64 webpage = self._download_webpage(request, video_id)
66 # Extract URL, uploader and title from webpage
67 self.report_extraction(video_id)
69 video_uploader = self._search_regex([r'(?im)<span class="owner[^\"]+?">[^<]+?<a [^>]+?>([^<]+?)</a>',
70 # Looking for official user
71 r'<(?:span|a) .*?rel="author".*?>([^<]+?)</'],
72 webpage, 'video uploader')
74 video_upload_date = None
75 mobj = re.search(r'<div class="[^"]*uploaded_cont[^"]*" title="[^"]*">([0-9]{2})-([0-9]{2})-([0-9]{4})</div>', webpage)
77 video_upload_date = mobj.group(3) + mobj.group(2) + mobj.group(1)
79 embed_url = 'http://www.dailymotion.com/embed/video/%s' % video_id
80 embed_page = self._download_webpage(embed_url, video_id,
81 u'Downloading embed page')
82 info = self._search_regex(r'var info = ({.*?}),$', embed_page,
83 'video info', flags=re.MULTILINE)
84 info = json.loads(info)
86 # TODO: support choosing qualities
88 for key in ['stream_h264_hd1080_url','stream_h264_hd_url',
89 'stream_h264_hq_url','stream_h264_url',
90 'stream_h264_ld_url']:
91 if info.get(key):#key in info and info[key]:
93 self.to_screen(u'Using %s' % key)
96 raise ExtractorError(u'Unable to extract video URL')
97 video_url = info[max_quality]
100 video_subtitles = None
103 if self._downloader.params.get('writesubtitles', False) or self._downloader.params.get('allsubtitles', False):
104 video_subtitles = self._extract_subtitles(video_id)
105 elif self._downloader.params.get('writeautomaticsub', False):
106 video_subtitles = self._request_automatic_caption(video_id, video_webpage)
108 if self._downloader.params.get('listsubtitles', False):
109 self._list_available_subtitles(video_id)
115 'uploader': video_uploader,
116 'upload_date': video_upload_date,
117 'title': self._og_search_title(webpage),
118 'ext': video_extension,
119 'subtitles': video_subtitles,
120 'thumbnail': info['thumbnail_url']
124 class DailymotionPlaylistIE(InfoExtractor):
125 _VALID_URL = r'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
126 _MORE_PAGES_INDICATOR = r'<div class="next">.*?<a.*?href="/playlist/.+?".*?>.*?</a>.*?</div>'
128 def _real_extract(self, url):
129 mobj = re.match(self._VALID_URL, url)
130 playlist_id = mobj.group('id')
133 for pagenum in itertools.count(1):
134 webpage = self._download_webpage('https://www.dailymotion.com/playlist/%s/%s' % (playlist_id, pagenum),
135 playlist_id, u'Downloading page %s' % pagenum)
137 playlist_el = get_element_by_attribute(u'class', u'video_list', webpage)
138 video_ids.extend(re.findall(r'data-id="(.+?)" data-ext-id', playlist_el))
140 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
143 entries = [self.url_result('http://www.dailymotion.com/video/%s' % video_id, 'Dailymotion')
144 for video_id in video_ids]
145 return {'_type': 'playlist',
147 'title': get_element_by_id(u'playlist_name', webpage),