5 from .common
import InfoExtractor
6 from ..compat
import compat_HTTPError
21 class DailymotionBaseInfoExtractor(InfoExtractor
):
24 'Content-Type': 'application/json',
25 'Origin': 'https://www.dailymotion.com',
27 _NETRC_MACHINE
= 'dailymotion'
29 def _get_dailymotion_cookies(self
):
30 return self
._get
_cookies
('https://www.dailymotion.com/')
33 def _get_cookie_value(cookies
, name
):
34 cookie
= cookies
.get(name
)
38 def _set_dailymotion_cookie(self
, name
, value
):
39 self
._set
_cookie
('www.dailymotion.com', name
, value
)
41 def _real_initialize(self
):
42 cookies
= self
._get
_dailymotion
_cookies
()
43 ff
= self
._get
_cookie
_value
(cookies
, 'ff')
44 self
._FAMILY
_FILTER
= ff
== 'on' if ff
else age_restricted(18, self
.get_param('age_limit'))
45 self
._set
_dailymotion
_cookie
('ff', 'on' if self
._FAMILY
_FILTER
else 'off')
47 def _call_api(self
, object_type
, xid
, object_fields
, note
, filter_extra
=None):
48 if not self
._HEADERS
.get('Authorization'):
49 cookies
= self
._get
_dailymotion
_cookies
()
50 token
= self
._get
_cookie
_value
(cookies
, 'access_token') or self
._get
_cookie
_value
(cookies
, 'client_token')
53 'client_id': 'f1a362d288c1b98099c7',
54 'client_secret': 'eea605b96e01c796ff369935357eca920c5da4c5',
56 username
, password
= self
._get
_login
_info
()
59 'grant_type': 'password',
64 data
['grant_type'] = 'client_credentials'
66 token
= self
._download
_json
(
67 'https://graphql.api.dailymotion.com/oauth/token',
68 None, 'Downloading Access Token',
69 data
=urlencode_postdata(data
))['access_token']
70 except ExtractorError
as e
:
71 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 400:
72 raise ExtractorError(self
._parse
_json
(
73 e
.cause
.read().decode(), xid
)['error_description'], expected
=True)
75 self
._set
_dailymotion
_cookie
('access_token' if username
else 'client_token', token
)
76 self
._HEADERS
['Authorization'] = 'Bearer ' + token
78 resp
= self
._download
_json
(
79 'https://graphql.api.dailymotion.com/', xid
, note
, data
=json
.dumps({
84 }''' % (object_type
, xid
, ', ' + filter_extra
if filter_extra
else '', object_fields
),
85 }).encode(), headers
=self
._HEADERS
)
86 obj
= resp
['data'][object_type
]
88 raise ExtractorError(resp
['errors'][0]['message'], expected
=True)
92 class DailymotionIE(DailymotionBaseInfoExtractor
):
93 _VALID_URL
= r
'''(?ix)
96 (?:(?:www|touch|geo)\.)?dailymotion\.[a-z]{2,3}/(?:(?:(?:(?:embed|swf|\#)/)|player\.html\?)?video|swf)|
97 (?:www\.)?lequipe\.fr/video
99 [/=](?P<id>[^/?_&]+)(?:.+?\bplaylist=(?P<playlist_id>x[0-9a-z]+))?
101 IE_NAME
= 'dailymotion'
102 _EMBED_REGEX
= [r
'<(?:(?:embed|iframe)[^>]+?src=|input[^>]+id=[\'"]dmcloudUrlEmissionSelect[\'"][^
>]+value
=)(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/(?:embed|swf)/video/.+?)\1']
104 'url': 'http://www.dailymotion.com/video/x5kesuj_office-christmas-party-review-jason-bateman-olivia-munn-t-j-miller_news',
105 'md5': '074b95bdee76b9e3654137aee9c79dfe',
109 'title': 'Office Christmas Party Review – Jason Bateman, Olivia Munn, T.J. Miller',
110 'description': 'Office Christmas Party Review - Jason Bateman, Olivia Munn, T.J. Miller',
112 'timestamp': 1493651285,
113 'upload_date': '20170501',
114 'uploader': 'Deadline',
115 'uploader_id': 'x1xm8ri',
119 'url': 'https://geo.dailymotion.com/player.html?video=x89eyek&mute=true',
120 'md5': 'e2f9717c6604773f963f069ca53a07f8',
124 'title': "En quête d
'esprit du 27/03/2022",
125 'description
': 'md5
:66542b9f4df2eb23f314fc097488e553
',
127 'timestamp
': 1648383669,
128 'upload_date
': '20220327',
130 'uploader_id
': 'x24vth
',
134 'tags
': ['en_quete_d_esprit
'],
135 'thumbnail
': 'https
://s2
.dmcdn
.net
/v
/Tncwi1YGKdvFbDuDY
/x1080
',
138 'url
': 'https
://www
.dailymotion
.com
/video
/x2iuewm_steam
-machine
-models
-pricing
-listed
-on
-steam
-store
-ign
-news_videogames
',
139 'md5
': '2137c41a8e78554bb09225b8eb322406
',
143 'title
': 'Steam Machine Models
, Pricing Listed on Steam Store
- IGN News
',
144 'description
': 'Several come bundled
with the Steam Controller
.',
145 'thumbnail
': r're
:^https?
:.*\
.(?
:jpg|png
)$
',
147 'timestamp
': 1425657362,
148 'upload_date
': '20150306',
150 'uploader_id
': 'xijv66
',
154 'skip
': 'video gone
',
157 'url
': 'http
://www
.dailymotion
.com
/video
/x149uew_katy
-perry
-roar
-official_musi
',
159 'title
': 'Roar (Official
)',
160 'id': 'USUV71301934
',
162 'uploader
': 'Katy Perry
',
163 'upload_date
': '20130905',
166 'skip_download
': True,
168 'skip
': 'VEVO
is only available
in some countries
',
170 # age-restricted video
171 'url
': 'http
://www
.dailymotion
.com
/video
/xyh2zz_leanna
-decker
-cyber
-girl
-of
-the
-year
-desires
-nude
-playboy
-plus_redband
',
172 'md5
': '0d667a7b9cebecc3c89ee93099c4159d
',
176 'title
': 'Leanna Decker
- Cyber Girl Of The Year Desires Nude
[Playboy Plus
]',
177 'uploader
': 'HotWaves1012
',
180 'skip
': 'video gone
',
182 # geo-restricted, player v5
183 'url
': 'http
://www
.dailymotion
.com
/video
/xhza0o
',
184 'only_matching
': True,
187 'url
': 'http
://www
.dailymotion
.com
/video
/x20su5f_the
-power
-of
-nightmares
-1-the
-rise
-of
-the
-politics
-of
-fear
-bbc
-2004_news
',
188 'only_matching
': True,
190 'url
': 'http
://www
.dailymotion
.com
/swf
/video
/x3n92nf
',
191 'only_matching
': True,
193 'url
': 'http
://www
.dailymotion
.com
/swf
/x3ss1m_funny
-magic
-trick
-barry
-and-stuart_fun
',
194 'only_matching
': True,
196 'url
': 'https
://www
.lequipe
.fr
/video
/x791mem
',
197 'only_matching
': True,
199 'url
': 'https
://www
.lequipe
.fr
/video
/k7MtHciueyTcrFtFKA2
',
200 'only_matching
': True,
202 'url
': 'https
://www
.dailymotion
.com
/video
/x3z49k?playlist
=xv4bw
',
203 'only_matching
': True,
206 _COMMON_MEDIA_FIELDS = '''description
207 geoblockedCountries {
213 def _extract_embed_urls(cls, url, webpage):
214 # https://developer.dailymotion.com/player#player-parameters
215 yield from super()._extract_embed_urls(url, webpage)
216 for mobj in re.finditer(
217 r'(?s
)DM\
.player\
([^
,]+,\s
*{.*?video[\'"]?\s*:\s*["\']?(?P<id>[0-9a-zA-Z]+).+?}\s
*\
);', webpage):
218 yield from 'https
://www
.dailymotion
.com
/embed
/video
/' + mobj.group('id')
220 def _real_extract(self, url):
221 url, smuggled_data = unsmuggle_url(url)
222 video_id, playlist_id = self._match_valid_url(url).groups()
225 if self._yes_playlist(playlist_id, video_id):
226 return self.url_result(
227 'http
://www
.dailymotion
.com
/playlist
/' + playlist_id,
228 'DailymotionPlaylist
', playlist_id)
230 password = self.get_param('videopassword
')
231 media = self._call_api(
232 'media
', video_id, '''... on Video {
247 }''' % (self._COMMON_MEDIA_FIELDS, self._COMMON_MEDIA_FIELDS), 'Downloading media JSON metadata
',
248 'password
: "%s"' % self.get_param('videopassword
') if password else None)
251 metadata = self._download_json(
252 'https
://www
.dailymotion
.com
/player
/metadata
/video
/' + xid,
253 xid, 'Downloading metadata JSON
',
254 query=traverse_obj(smuggled_data, 'query
') or {'app': 'com.dailymotion.neon'})
256 error = metadata.get('error
')
258 title = error.get('title
') or error['raw_message
']
259 # See https://developer.dailymotion.com/api#access-error
260 if error.get('code
') == 'DM007
':
261 allowed_countries = try_get(media, lambda x: x['geoblockedCountries
']['allowed
'], list)
262 self.raise_geo_restricted(msg=title, countries=allowed_countries)
263 raise ExtractorError(
264 '%s said
: %s' % (self.IE_NAME, title), expected=True)
266 title = metadata['title
']
267 is_live = media.get('isOnAir
')
269 for quality, media_list in metadata['qualities
'].items():
271 media_url = m.get('url
')
272 media_type = m.get('type')
273 if not media_url or media_type == 'application
/vnd
.lumberjack
.manifest
':
275 if media_type == 'application
/x
-mpegURL
':
276 formats.extend(self._extract_m3u8_formats(
277 media_url, video_id, 'mp4
', live=is_live, m3u8_id='hls
', fatal=False))
281 'format_id
': 'http
-' + quality,
283 m = re.search(r'/H264
-(\d
+)x(\d
+)(?
:-(60)/)?
', media_url)
285 width, height, fps = map(int_or_none, m.groups())
293 f['url
'] = f['url
'].split('#')[0]
294 if not f
.get('fps') and f
['format_id'].endswith('@60'):
296 self
._sort
_formats
(formats
)
299 subtitles_data
= try_get(metadata
, lambda x
: x
['subtitles']['data'], dict) or {}
300 for subtitle_lang
, subtitle
in subtitles_data
.items():
301 subtitles
[subtitle_lang
] = [{
303 } for subtitle_url
in subtitle
.get('urls', [])]
306 for height
, poster_url
in metadata
.get('posters', {}).items():
308 'height': int_or_none(height
),
313 owner
= metadata
.get('owner') or {}
314 stats
= media
.get('stats') or {}
315 get_count
= lambda x
: int_or_none(try_get(stats
, lambda y
: y
[x
+ 's']['total']))
320 'description': clean_html(media
.get('description')),
321 'thumbnails': thumbnails
,
322 'duration': int_or_none(metadata
.get('duration')) or None,
323 'timestamp': int_or_none(metadata
.get('created_time')),
324 'uploader': owner
.get('screenname'),
325 'uploader_id': owner
.get('id') or metadata
.get('screenname'),
326 'age_limit': 18 if metadata
.get('explicit') else 0,
327 'tags': metadata
.get('tags'),
328 'view_count': get_count('view') or int_or_none(media
.get('audienceCount')),
329 'like_count': get_count('like'),
331 'subtitles': subtitles
,
336 class DailymotionPlaylistBaseIE(DailymotionBaseInfoExtractor
):
339 def _fetch_page(self
, playlist_id
, page
):
341 videos
= self
._call
_api
(
342 self
._OBJECT
_TYPE
, playlist_id
,
343 '''videos(allowExplicit: %s, first: %d, page: %d) {
350 }''' % ('false' if self
._FAMILY
_FILTER
else 'true', self
._PAGE
_SIZE
, page
),
351 'Downloading page %d' % page
)['videos']
352 for edge
in videos
['edges']:
354 yield self
.url_result(
355 node
['url'], DailymotionIE
.ie_key(), node
['xid'])
357 def _real_extract(self
, url
):
358 playlist_id
= self
._match
_id
(url
)
359 entries
= OnDemandPagedList(functools
.partial(
360 self
._fetch
_page
, playlist_id
), self
._PAGE
_SIZE
)
361 return self
.playlist_result(
362 entries
, playlist_id
)
365 class DailymotionPlaylistIE(DailymotionPlaylistBaseIE
):
366 IE_NAME
= 'dailymotion:playlist'
367 _VALID_URL
= r
'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>x[0-9a-z]+)'
369 'url': 'http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q',
373 'playlist_mincount': 20,
375 _OBJECT_TYPE
= 'collection'
378 def _extract_embed_urls(cls
, url
, webpage
):
379 # Look for embedded Dailymotion playlist player (#3822)
380 for mobj
in re
.finditer(
381 r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:www\
.)?dailymotion\
.[a
-z
]{2,3}
/widget
/jukebox
\?.+?
)\
1',
383 for p in re.findall(r'list\
[\
]=/playlist
/([^
/]+)/', unescapeHTML(mobj.group('url
'))):
384 yield '//dailymotion
.com
/playlist
/%s' % p
387 class DailymotionUserIE(DailymotionPlaylistBaseIE):
388 IE_NAME = 'dailymotion
:user
'
389 _VALID_URL = r'https?
://(?
:www\
.)?dailymotion\
.[a
-z
]{2,3}
/(?
!(?
:embed|swf|
#|video|playlist)/)(?:(?:old/)?user/)?(?P<id>[^/]+)'
391 'url': 'https://www.dailymotion.com/user/nqtv',
395 'playlist_mincount': 152,
397 'url': 'http://www.dailymotion.com/user/UnderProject',
399 'id': 'UnderProject',
401 'playlist_mincount': 1000,
402 'skip': 'Takes too long time',
404 'url': 'https://www.dailymotion.com/user/nqtv',
408 'playlist_mincount': 148,
413 _OBJECT_TYPE
= 'channel'