2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
10 from ..compat
import (
12 compat_urllib_request
,
25 class DailymotionBaseInfoExtractor(InfoExtractor
):
27 def _build_request(url
):
28 """Build a request with the family filter disabled"""
29 request
= compat_urllib_request
.Request(url
)
30 request
.add_header('Cookie', 'family_filter=off; ff=off')
33 def _download_webpage_handle_no_ff(self
, url
, *args
, **kwargs
):
34 request
= self
._build
_request
(url
)
35 return self
._download
_webpage
_handle
(request
, *args
, **kwargs
)
37 def _download_webpage_no_ff(self
, url
, *args
, **kwargs
):
38 request
= self
._build
_request
(url
)
39 return self
._download
_webpage
(request
, *args
, **kwargs
)
42 class DailymotionIE(DailymotionBaseInfoExtractor
):
43 _VALID_URL
= r
'(?i)(?:https?://)?(?:(www|touch)\.)?dailymotion\.[a-z]{2,3}/(?:(embed|#)/)?video/(?P<id>[^/?_]+)'
44 IE_NAME
= 'dailymotion'
47 ('stream_h264_ld_url', 'ld'),
48 ('stream_h264_url', 'standard'),
49 ('stream_h264_hq_url', 'hq'),
50 ('stream_h264_hd_url', 'hd'),
51 ('stream_h264_hd1080_url', 'hd180'),
56 'url': 'https://www.dailymotion.com/video/x2iuewm_steam-machine-models-pricing-listed-on-steam-store-ign-news_videogames',
57 'md5': '2137c41a8e78554bb09225b8eb322406',
61 'title': 'Steam Machine Models, Pricing Listed on Steam Store - IGN News',
62 'description': 'Several come bundled with the Steam Controller.',
63 'thumbnail': 're:^https?:.*\.(?:jpg|png)$',
65 'timestamp': 1425657362,
66 'upload_date': '20150306',
68 'uploader_id': 'xijv66',
76 'url': 'http://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musi',
78 'title': 'Roar (Official)',
81 'uploader': 'Katy Perry',
82 'upload_date': '20130905',
85 'skip_download': True,
87 'skip': 'VEVO is only available in some countries',
89 # age-restricted video
91 'url': 'http://www.dailymotion.com/video/xyh2zz_leanna-decker-cyber-girl-of-the-year-desires-nude-playboy-plus_redband',
92 'md5': '0d667a7b9cebecc3c89ee93099c4159d',
96 'title': 'Leanna Decker - Cyber Girl Of The Year Desires Nude [Playboy Plus]',
97 'uploader': 'HotWaves1012',
103 def _real_extract(self
, url
):
104 video_id
= self
._match
_id
(url
)
106 webpage
= self
._download
_webpage
_no
_ff
(
107 'https://www.dailymotion.com/video/%s' % video_id
, video_id
)
109 age_limit
= self
._rta
_search
(webpage
)
111 description
= self
._og
_search
_description
(webpage
) or self
._html
_search
_meta
(
112 'description', webpage
, 'description')
114 view_count
= str_to_int(self
._search
_regex
(
115 [r
'<meta[^>]+itemprop="interactionCount"[^>]+content="UserPlays:(\d+)"',
116 r
'video_views_count[^>]+>\s+([\d\.,]+)'],
117 webpage
, 'view count', fatal
=False))
118 comment_count
= int_or_none(self
._search
_regex
(
119 r
'<meta[^>]+itemprop="interactionCount"[^>]+content="UserComments:(\d+)"',
120 webpage
, 'comment count', fatal
=False))
122 player_v5
= self
._search
_regex
(
123 r
'playerV5\s*=\s*dmp\.create\([^,]+?,\s*({.+?})\);',
124 webpage
, 'player v5', default
=None)
126 player
= self
._parse
_json
(player_v5
, video_id
)
127 metadata
= player
['metadata']
129 for quality
, media_list
in metadata
['qualities'].items():
130 for media
in media_list
:
131 media_url
= media
.get('url')
134 type_
= media
.get('type')
135 if type_
== 'application/vnd.lumberjack.manifest':
137 if type_
== 'application/x-mpegURL' or determine_ext(media_url
) == 'm3u8':
138 formats
.extend(self
._extract
_m
3u8_formats
(
139 media_url
, video_id
, 'mp4', m3u8_id
='hls'))
143 'format_id': quality
,
145 m
= re
.search(r
'H264-(?P<width>\d+)x(?P<height>\d+)', media_url
)
148 'width': int(m
.group('width')),
149 'height': int(m
.group('height')),
152 self
._sort
_formats
(formats
)
154 title
= metadata
['title']
155 duration
= int_or_none(metadata
.get('duration'))
156 timestamp
= int_or_none(metadata
.get('created_time'))
157 thumbnail
= metadata
.get('poster_url')
158 uploader
= metadata
.get('owner', {}).get('screenname')
159 uploader_id
= metadata
.get('owner', {}).get('id')
162 for subtitle_lang
, subtitle
in metadata
.get('subtitles', {}).get('data', {}
).items():
163 subtitles
[subtitle_lang
] = [{
164 'ext': determine_ext(subtitle_url
),
166 } for subtitle_url
in subtitle
.get('urls', [])]
171 'description': description
,
172 'thumbnail': thumbnail
,
173 'duration': duration
,
174 'timestamp': timestamp
,
175 'uploader': uploader
,
176 'uploader_id': uploader_id
,
177 'age_limit': age_limit
,
178 'view_count': view_count
,
179 'comment_count': comment_count
,
181 'subtitles': subtitles
,
185 vevo_id
= self
._search
_regex
(
186 r
'<link rel="video_src" href="[^"]*?vevo.com[^"]*?video=(?P<id>[\w]*)',
187 webpage
, 'vevo embed', default
=None)
189 return self
.url_result('vevo:%s' % vevo_id
, 'Vevo')
191 # fallback old player
192 embed_page
= self
._download
_webpage
_no
_ff
(
193 'https://www.dailymotion.com/embed/video/%s' % video_id
,
194 video_id
, 'Downloading embed page')
196 timestamp
= parse_iso8601(self
._html
_search
_meta
(
197 'video:release_date', webpage
, 'upload date'))
199 info
= self
._parse
_json
(
201 r
'var info = ({.*?}),$', embed_page
,
202 'video info', flags
=re
.MULTILINE
),
205 if info
.get('error') is not None:
206 msg
= 'Couldn\'t get video, Dailymotion says: %s' % info
['error']['title']
207 raise ExtractorError(msg
, expected
=True)
210 for (key
, format_id
) in self
._FORMATS
:
211 video_url
= info
.get(key
)
212 if video_url
is not None:
213 m_size
= re
.search(r
'H264-(\d+)x(\d+)', video_url
)
214 if m_size
is not None:
215 width
, height
= map(int_or_none
, (m_size
.group(1), m_size
.group(2)))
217 width
, height
= None, None
221 'format_id': format_id
,
225 self
._sort
_formats
(formats
)
228 video_subtitles
= self
.extract_subtitles(video_id
, webpage
)
230 title
= self
._og
_search
_title
(webpage
, default
=None)
232 title
= self
._html
_search
_regex
(
233 r
'(?s)<span\s+id="video_title"[^>]*>(.*?)</span>', webpage
,
239 'uploader': info
['owner.screenname'],
240 'timestamp': timestamp
,
242 'description': description
,
243 'subtitles': video_subtitles
,
244 'thumbnail': info
['thumbnail_url'],
245 'age_limit': age_limit
,
246 'view_count': view_count
,
247 'duration': info
['duration']
250 def _get_subtitles(self
, video_id
, webpage
):
252 sub_list
= self
._download
_webpage
(
253 'https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id
,
254 video_id
, note
=False)
255 except ExtractorError
as err
:
256 self
._downloader
.report_warning('unable to download video subtitles: %s' % compat_str(err
))
258 info
= json
.loads(sub_list
)
259 if (info
['total'] > 0):
260 sub_lang_list
= dict((l
['language'], [{'url': l['url'], 'ext': 'srt'}
]) for l
in info
['list'])
262 self
._downloader
.report_warning('video doesn\'t have subtitles')
266 class DailymotionPlaylistIE(DailymotionBaseInfoExtractor
):
267 IE_NAME
= 'dailymotion:playlist'
268 _VALID_URL
= r
'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
269 _MORE_PAGES_INDICATOR
= r
'(?s)<div class="pages[^"]*">.*?<a\s+class="[^"]*?icon-arrow_right[^"]*?"'
270 _PAGE_TEMPLATE
= 'https://www.dailymotion.com/playlist/%s/%s'
272 'url': 'http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q',
275 'id': 'xv4bw_nqtv_sport',
277 'playlist_mincount': 20,
280 def _extract_entries(self
, id):
282 processed_urls
= set()
283 for pagenum
in itertools
.count(1):
284 page_url
= self
._PAGE
_TEMPLATE
% (id, pagenum
)
285 webpage
, urlh
= self
._download
_webpage
_handle
_no
_ff
(
286 page_url
, id, 'Downloading page %s' % pagenum
)
287 if urlh
.geturl() in processed_urls
:
288 self
.report_warning('Stopped at duplicated page %s, which is the same as %s' % (
289 page_url
, urlh
.geturl()), id)
292 processed_urls
.add(urlh
.geturl())
294 video_ids
.extend(re
.findall(r
'data-xid="(.+?)"', webpage
))
296 if re
.search(self
._MORE
_PAGES
_INDICATOR
, webpage
) is None:
298 return [self
.url_result('http://www.dailymotion.com/video/%s' % video_id
, 'Dailymotion')
299 for video_id
in orderedSet(video_ids
)]
301 def _real_extract(self
, url
):
302 mobj
= re
.match(self
._VALID
_URL
, url
)
303 playlist_id
= mobj
.group('id')
304 webpage
= self
._download
_webpage
(url
, playlist_id
)
309 'title': self
._og
_search
_title
(webpage
),
310 'entries': self
._extract
_entries
(playlist_id
),
314 class DailymotionUserIE(DailymotionPlaylistIE
):
315 IE_NAME
= 'dailymotion:user'
316 _VALID_URL
= r
'https?://(?:www\.)?dailymotion\.[a-z]{2,3}/(?!(?:embed|#|video|playlist)/)(?:(?:old/)?user/)?(?P<user>[^/]+)'
317 _PAGE_TEMPLATE
= 'http://www.dailymotion.com/user/%s/%s'
319 'url': 'https://www.dailymotion.com/user/nqtv',
322 'title': 'RĂ©mi Gaillard',
324 'playlist_mincount': 100,
326 'url': 'http://www.dailymotion.com/user/UnderProject',
328 'id': 'UnderProject',
329 'title': 'UnderProject',
331 'playlist_mincount': 1800,
332 'expected_warnings': [
333 'Stopped at duplicated page',
335 'skip': 'Takes too long time',
338 def _real_extract(self
, url
):
339 mobj
= re
.match(self
._VALID
_URL
, url
)
340 user
= mobj
.group('user')
341 webpage
= self
._download
_webpage
(
342 'https://www.dailymotion.com/user/%s' % user
, user
)
343 full_user
= unescapeHTML(self
._html
_search
_regex
(
344 r
'<a class="nav-image" title="([^"]+)" href="/%s">' % re
.escape(user
),
351 'entries': self
._extract
_entries
(user
),
355 class DailymotionCloudIE(DailymotionBaseInfoExtractor
):
356 _VALID_URL_PREFIX
= r
'http://api\.dmcloud\.net/(?:player/)?embed/'
357 _VALID_URL
= r
'%s[^/]+/(?P<id>[^/?]+)' % _VALID_URL_PREFIX
358 _VALID_EMBED_URL
= r
'%s[^/]+/[^\'"]+' % _VALID_URL_PREFIX
361 # From http://www.francetvinfo.fr/economie/entreprises/les-entreprises-familiales-le-secret-de-la-reussite_933271.html
362 # Tested at FranceTvInfo_2
363 'url': 'http://api.dmcloud.net/embed/4e7343f894a6f677b10006b4/556e03339473995ee145930c?auth=1464865870-0-jyhsm84b-ead4c701fb750cf9367bf4447167a3db&autoplay=1',
364 'only_matching': True,
366 # http://www.francetvinfo.fr/societe/larguez-les-amarres-le-cobaturage-se-developpe_980101.html
367 'url': 'http://api.dmcloud.net/player/embed/4e7343f894a6f677b10006b4/559545469473996d31429f06?auth=1467430263-0-90tglw2l-a3a4b64ed41efe48d7fccad85b8b8fda&autoplay=1',
368 'only_matching': True,
372 def _extract_dmcloud_url(self, webpage):
373 mobj = re.search(r'<iframe[^>]+src=[\'"](%s)[\'"]' % self._VALID_EMBED_URL, webpage)
378 r'<input[^>]+id=[\'"]dmcloudUrlEmissionSelect
[\'"][^>]+value=[\'"](%s)[\'"]' % self._VALID_EMBED_URL,
383 def _real_extract(self, url):
384 video_id = self._match_id(url)
386 webpage = self._download_webpage_no_ff(url, video_id)
388 title = self._html_search_regex(r'<title>([^>]+)</title>', webpage, 'title')
390 video_info = self._parse_json(self._search_regex(
391 r'var\s+info\s*=\s*([^;]+);', webpage, 'video info'), video_id)
393 # TODO: parse ios_url, which is in fact a manifest
394 video_url = video_info['mp4_url']
400 'thumbnail': video_info.get('thumbnail_url'),