2 from __future__ import unicode_literals
8 from .common import InfoExtractor
22 class DailymotionBaseInfoExtractor(InfoExtractor):
24 def _build_request(url):
25 """Build a request with the family filter disabled"""
26 request = sanitized_Request(url)
27 request.add_header('Cookie', 'family_filter=off; ff=off')
30 def _download_webpage_handle_no_ff(self, url, *args, **kwargs):
31 request = self._build_request(url)
32 return self._download_webpage_handle(request, *args, **kwargs)
34 def _download_webpage_no_ff(self, url, *args, **kwargs):
35 request = self._build_request(url)
36 return self._download_webpage(request, *args, **kwargs)
39 class DailymotionIE(DailymotionBaseInfoExtractor):
40 _VALID_URL = r'(?i)(?:https?://)?(?:(www|touch)\.)?dailymotion\.[a-z]{2,3}/(?:(?:embed|swf|#)/)?video/(?P<id>[^/?_]+)'
41 IE_NAME = 'dailymotion'
44 ('stream_h264_ld_url', 'ld'),
45 ('stream_h264_url', 'standard'),
46 ('stream_h264_hq_url', 'hq'),
47 ('stream_h264_hd_url', 'hd'),
48 ('stream_h264_hd1080_url', 'hd180'),
53 'url': 'https://www.dailymotion.com/video/x2iuewm_steam-machine-models-pricing-listed-on-steam-store-ign-news_videogames',
54 'md5': '2137c41a8e78554bb09225b8eb322406',
58 'title': 'Steam Machine Models, Pricing Listed on Steam Store - IGN News',
59 'description': 'Several come bundled with the Steam Controller.',
60 'thumbnail': 're:^https?:.*\.(?:jpg|png)$',
62 'timestamp': 1425657362,
63 'upload_date': '20150306',
65 'uploader_id': 'xijv66',
73 'url': 'http://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musi',
75 'title': 'Roar (Official)',
78 'uploader': 'Katy Perry',
79 'upload_date': '20130905',
82 'skip_download': True,
84 'skip': 'VEVO is only available in some countries',
86 # age-restricted video
88 'url': 'http://www.dailymotion.com/video/xyh2zz_leanna-decker-cyber-girl-of-the-year-desires-nude-playboy-plus_redband',
89 'md5': '0d667a7b9cebecc3c89ee93099c4159d',
93 'title': 'Leanna Decker - Cyber Girl Of The Year Desires Nude [Playboy Plus]',
94 'uploader': 'HotWaves1012',
98 # geo-restricted, player v5
100 'url': 'http://www.dailymotion.com/video/xhza0o',
101 'only_matching': True,
105 'url': 'http://www.dailymotion.com/video/x20su5f_the-power-of-nightmares-1-the-rise-of-the-politics-of-fear-bbc-2004_news',
106 'only_matching': True,
109 'url': 'http://www.dailymotion.com/swf/video/x3n92nf',
110 'only_matching': True,
114 def _real_extract(self, url):
115 video_id = self._match_id(url)
117 webpage = self._download_webpage_no_ff(
118 'https://www.dailymotion.com/video/%s' % video_id, video_id)
120 age_limit = self._rta_search(webpage)
122 description = self._og_search_description(webpage) or self._html_search_meta(
123 'description', webpage, 'description')
125 view_count_str = self._search_regex(
126 (r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserPlays:([\s\d,.]+)"',
127 r'video_views_count[^>]+>\s+([\s\d\,.]+)'),
128 webpage, 'view count', fatal=False)
130 view_count_str = re.sub(r'\s', '', view_count_str)
131 view_count = str_to_int(view_count_str)
132 comment_count = int_or_none(self._search_regex(
133 r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserComments:(\d+)"',
134 webpage, 'comment count', fatal=False))
136 player_v5 = self._search_regex(
137 [r'buildPlayer\(({.+?})\);\n', # See https://github.com/rg3/youtube-dl/issues/7826
138 r'playerV5\s*=\s*dmp\.create\([^,]+?,\s*({.+?})\);',
139 r'buildPlayer\(({.+?})\);'],
140 webpage, 'player v5', default=None)
142 player = self._parse_json(player_v5, video_id)
143 metadata = player['metadata']
145 self._check_error(metadata)
148 for quality, media_list in metadata['qualities'].items():
149 for media in media_list:
150 media_url = media.get('url')
153 type_ = media.get('type')
154 if type_ == 'application/vnd.lumberjack.manifest':
156 ext = determine_ext(media_url)
157 if type_ == 'application/x-mpegURL' or ext == 'm3u8':
158 formats.extend(self._extract_m3u8_formats(
159 media_url, video_id, 'mp4', preference=-1,
160 m3u8_id='hls', fatal=False))
161 elif type_ == 'application/f4m' or ext == 'f4m':
162 formats.extend(self._extract_f4m_formats(
163 media_url, video_id, preference=-1, f4m_id='hds', fatal=False))
167 'format_id': 'http-%s' % quality,
169 m = re.search(r'H264-(?P<width>\d+)x(?P<height>\d+)', media_url)
172 'width': int(m.group('width')),
173 'height': int(m.group('height')),
176 self._sort_formats(formats)
178 title = metadata['title']
179 duration = int_or_none(metadata.get('duration'))
180 timestamp = int_or_none(metadata.get('created_time'))
181 thumbnail = metadata.get('poster_url')
182 uploader = metadata.get('owner', {}).get('screenname')
183 uploader_id = metadata.get('owner', {}).get('id')
186 subtitles_data = metadata.get('subtitles', {}).get('data', {})
187 if subtitles_data and isinstance(subtitles_data, dict):
188 for subtitle_lang, subtitle in subtitles_data.items():
189 subtitles[subtitle_lang] = [{
190 'ext': determine_ext(subtitle_url),
192 } for subtitle_url in subtitle.get('urls', [])]
197 'description': description,
198 'thumbnail': thumbnail,
199 'duration': duration,
200 'timestamp': timestamp,
201 'uploader': uploader,
202 'uploader_id': uploader_id,
203 'age_limit': age_limit,
204 'view_count': view_count,
205 'comment_count': comment_count,
207 'subtitles': subtitles,
211 vevo_id = self._search_regex(
212 r'<link rel="video_src" href="[^"]*?vevo.com[^"]*?video=(?P<id>[\w]*)',
213 webpage, 'vevo embed', default=None)
215 return self.url_result('vevo:%s' % vevo_id, 'Vevo')
217 # fallback old player
218 embed_page = self._download_webpage_no_ff(
219 'https://www.dailymotion.com/embed/video/%s' % video_id,
220 video_id, 'Downloading embed page')
222 timestamp = parse_iso8601(self._html_search_meta(
223 'video:release_date', webpage, 'upload date'))
225 info = self._parse_json(
227 r'var info = ({.*?}),$', embed_page,
228 'video info', flags=re.MULTILINE),
231 self._check_error(info)
234 for (key, format_id) in self._FORMATS:
235 video_url = info.get(key)
236 if video_url is not None:
237 m_size = re.search(r'H264-(\d+)x(\d+)', video_url)
238 if m_size is not None:
239 width, height = map(int_or_none, (m_size.group(1), m_size.group(2)))
241 width, height = None, None
245 'format_id': format_id,
249 self._sort_formats(formats)
252 video_subtitles = self.extract_subtitles(video_id, webpage)
254 title = self._og_search_title(webpage, default=None)
256 title = self._html_search_regex(
257 r'(?s)<span\s+id="video_title"[^>]*>(.*?)</span>', webpage,
263 'uploader': info['owner.screenname'],
264 'timestamp': timestamp,
266 'description': description,
267 'subtitles': video_subtitles,
268 'thumbnail': info['thumbnail_url'],
269 'age_limit': age_limit,
270 'view_count': view_count,
271 'duration': info['duration']
274 def _check_error(self, info):
275 if info.get('error') is not None:
276 raise ExtractorError(
277 '%s said: %s' % (self.IE_NAME, info['error']['title']), expected=True)
279 def _get_subtitles(self, video_id, webpage):
281 sub_list = self._download_webpage(
282 'https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id,
283 video_id, note=False)
284 except ExtractorError as err:
285 self._downloader.report_warning('unable to download video subtitles: %s' % error_to_compat_str(err))
287 info = json.loads(sub_list)
288 if (info['total'] > 0):
289 sub_lang_list = dict((l['language'], [{'url': l['url'], 'ext': 'srt'}]) for l in info['list'])
291 self._downloader.report_warning('video doesn\'t have subtitles')
295 class DailymotionPlaylistIE(DailymotionBaseInfoExtractor):
296 IE_NAME = 'dailymotion:playlist'
297 _VALID_URL = r'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
298 _MORE_PAGES_INDICATOR = r'(?s)<div class="pages[^"]*">.*?<a\s+class="[^"]*?icon-arrow_right[^"]*?"'
299 _PAGE_TEMPLATE = 'https://www.dailymotion.com/playlist/%s/%s'
301 'url': 'http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q',
304 'id': 'xv4bw_nqtv_sport',
306 'playlist_mincount': 20,
309 def _extract_entries(self, id):
311 processed_urls = set()
312 for pagenum in itertools.count(1):
313 page_url = self._PAGE_TEMPLATE % (id, pagenum)
314 webpage, urlh = self._download_webpage_handle_no_ff(
315 page_url, id, 'Downloading page %s' % pagenum)
316 if urlh.geturl() in processed_urls:
317 self.report_warning('Stopped at duplicated page %s, which is the same as %s' % (
318 page_url, urlh.geturl()), id)
321 processed_urls.add(urlh.geturl())
323 for video_id in re.findall(r'data-xid="(.+?)"', webpage):
324 if video_id not in video_ids:
325 yield self.url_result('http://www.dailymotion.com/video/%s' % video_id, 'Dailymotion')
326 video_ids.add(video_id)
328 if re.search(self._MORE_PAGES_INDICATOR, webpage) is None:
331 def _real_extract(self, url):
332 mobj = re.match(self._VALID_URL, url)
333 playlist_id = mobj.group('id')
334 webpage = self._download_webpage(url, playlist_id)
339 'title': self._og_search_title(webpage),
340 'entries': self._extract_entries(playlist_id),
344 class DailymotionUserIE(DailymotionPlaylistIE):
345 IE_NAME = 'dailymotion:user'
346 _VALID_URL = r'https?://(?:www\.)?dailymotion\.[a-z]{2,3}/(?!(?:embed|swf|#|video|playlist)/)(?:(?:old/)?user/)?(?P<user>[^/]+)'
347 _PAGE_TEMPLATE = 'http://www.dailymotion.com/user/%s/%s'
349 'url': 'https://www.dailymotion.com/user/nqtv',
352 'title': 'RĂ©mi Gaillard',
354 'playlist_mincount': 100,
356 'url': 'http://www.dailymotion.com/user/UnderProject',
358 'id': 'UnderProject',
359 'title': 'UnderProject',
361 'playlist_mincount': 1800,
362 'expected_warnings': [
363 'Stopped at duplicated page',
365 'skip': 'Takes too long time',
368 def _real_extract(self, url):
369 mobj = re.match(self._VALID_URL, url)
370 user = mobj.group('user')
371 webpage = self._download_webpage(
372 'https://www.dailymotion.com/user/%s' % user, user)
373 full_user = unescapeHTML(self._html_search_regex(
374 r'<a class="nav-image" title="([^"]+)" href="/%s">' % re.escape(user),
381 'entries': self._extract_entries(user),
385 class DailymotionCloudIE(DailymotionBaseInfoExtractor):
386 _VALID_URL_PREFIX = r'http://api\.dmcloud\.net/(?:player/)?embed/'
387 _VALID_URL = r'%s[^/]+/(?P<id>[^/?]+)' % _VALID_URL_PREFIX
388 _VALID_EMBED_URL = r'%s[^/]+/[^\'"]+' % _VALID_URL_PREFIX
391 # From http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html
392 # Tested at FranceTvInfo_2
393 'url': 'http://api.dmcloud.net/embed/4e7343f894a6f677b10006b4/556e03339473995ee145930c?auth=1464865870-0-jyhsm84b-ead4c701fb750cf9367bf4447167a3db&autoplay=1',
394 'only_matching': True,
396 # http://www.francetvinfo.fr/societe/larguez-les-amarres-le-cobaturage-se-developpe_980101.html
397 'url': 'http://api.dmcloud.net/player/embed/4e7343f894a6f677b10006b4/559545469473996d31429f06?auth=1467430263-0-90tglw2l-a3a4b64ed41efe48d7fccad85b8b8fda&autoplay=1',
398 'only_matching': True,
402 def _extract_dmcloud_url(cls, webpage):
403 mobj = re.search(r'<iframe[^>]+src=[\'"](%s)[\'"]' % cls._VALID_EMBED_URL, webpage)
408 r'<input[^>]+id=[\'"]dmcloudUrlEmissionSelect[\'"][^>]+value=[\'"](%s)[\'"]' % cls._VALID_EMBED_URL,
413 def _real_extract(self, url):
414 video_id = self._match_id(url)
416 webpage = self._download_webpage_no_ff(url, video_id)
418 title = self._html_search_regex(r'<title>([^>]+)</title>', webpage, 'title')
420 video_info = self._parse_json(self._search_regex(
421 r'var\s+info\s*=\s*([^;]+);', webpage, 'video info'), video_id)
423 # TODO: parse ios_url, which is in fact a manifest
424 video_url = video_info['mp4_url']
430 'thumbnail': video_info.get('thumbnail_url'),