5 from .common
import InfoExtractor
6 from ..networking
.exceptions
import 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
, HTTPError
) and e
.cause
.status
== 400:
72 raise ExtractorError(self
._parse
_json
(
73 e
.cause
.response
.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(?:/\w+)?\.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 'tags': ['hollywood', 'celeb', 'celebrity', 'movies', 'red carpet'],
120 'thumbnail': r're:https://(?:s[12]\.)dmcdn\.net/v/K456B1aXqIx58LKWQ/x1080',
123 'url': 'https://geo.dailymotion.com/player.html?video=x89eyek&mute=true',
124 'md5': 'e2f9717c6604773f963f069ca53a07f8',
128 'title': "En quête d
'esprit du 27/03/2022",
129 'description
': 'md5
:66542b9f4df2eb23f314fc097488e553
',
131 'timestamp
': 1648383669,
132 'upload_date
': '20220327',
134 'uploader_id
': 'x24vth
',
138 'tags
': ['en_quete_d_esprit
'],
139 'thumbnail
': r're
:https
://(?
:s
[12]\
.)dmcdn\
.net
/v
/Tncwi1YNg_RUl7ueu
/x1080
',
142 'url
': 'https
://www
.dailymotion
.com
/video
/x2iuewm_steam
-machine
-models
-pricing
-listed
-on
-steam
-store
-ign
-news_videogames
',
143 'md5
': '2137c41a8e78554bb09225b8eb322406
',
147 'title
': 'Steam Machine Models
, Pricing Listed on Steam Store
- IGN News
',
148 'description
': 'Several come bundled
with the Steam Controller
.',
149 'thumbnail
': r're
:^https?
:.*\
.(?
:jpg|png
)$
',
151 'timestamp
': 1425657362,
152 'upload_date
': '20150306',
154 'uploader_id
': 'xijv66
',
158 'skip
': 'video gone
',
161 'url
': 'http
://www
.dailymotion
.com
/video
/x149uew_katy
-perry
-roar
-official_musi
',
163 'title
': 'Roar (Official
)',
164 'id': 'USUV71301934
',
166 'uploader
': 'Katy Perry
',
167 'upload_date
': '20130905',
170 'skip_download
': True,
172 'skip
': 'VEVO
is only available
in some countries
',
174 # age-restricted video
175 'url
': 'http
://www
.dailymotion
.com
/video
/xyh2zz_leanna
-decker
-cyber
-girl
-of
-the
-year
-desires
-nude
-playboy
-plus_redband
',
176 'md5
': '0d667a7b9cebecc3c89ee93099c4159d
',
180 'title
': 'Leanna Decker
- Cyber Girl Of The Year Desires Nude
[Playboy Plus
]',
181 'uploader
': 'HotWaves1012
',
184 'skip
': 'video gone
',
186 # geo-restricted, player v5
187 'url
': 'http
://www
.dailymotion
.com
/video
/xhza0o
',
188 'only_matching
': True,
191 'url
': 'http
://www
.dailymotion
.com
/video
/x20su5f_the
-power
-of
-nightmares
-1-the
-rise
-of
-the
-politics
-of
-fear
-bbc
-2004_news
',
192 'only_matching
': True,
194 'url
': 'http
://www
.dailymotion
.com
/swf
/video
/x3n92nf
',
195 'only_matching
': True,
197 'url
': 'http
://www
.dailymotion
.com
/swf
/x3ss1m_funny
-magic
-trick
-barry
-and-stuart_fun
',
198 'only_matching
': True,
200 'url
': 'https
://www
.lequipe
.fr
/video
/x791mem
',
201 'only_matching
': True,
203 'url
': 'https
://www
.lequipe
.fr
/video
/k7MtHciueyTcrFtFKA2
',
204 'only_matching
': True,
206 'url
': 'https
://www
.dailymotion
.com
/video
/x3z49k?playlist
=xv4bw
',
207 'only_matching
': True,
209 'url
': 'https
://geo
.dailymotion
.com
/player
/x86gw
.html?video
=k46oCapRs4iikoz9DWy
',
210 'only_matching
': True,
212 'url
': 'https
://geo
.dailymotion
.com
/player
/xakln
.html?video
=x8mjju4
&customConfig
%5BcustomParams
%5D
=%2Ffr
-fr
%2Ftennis
%2Fwimbledon
-mens
-singles
%2Farticles
-video
',
213 'only_matching
': True,
216 _COMMON_MEDIA_FIELDS = '''description
217 geoblockedCountries {
223 def _extract_embed_urls(cls, url, webpage):
224 # https://developer.dailymotion.com/player#player-parameters
225 yield from super()._extract_embed_urls(url, webpage)
226 for mobj in re.finditer(
227 r'(?s
)DM\
.player\
([^
,]+,\s
*{.*?video[\'"]?\s*:\s*["\']?(?P<id>[0-9a-zA-Z]+).+?}\s
*\
);', webpage):
228 yield from 'https
://www
.dailymotion
.com
/embed
/video
/' + mobj.group('id')
230 def _real_extract(self, url):
231 url, smuggled_data = unsmuggle_url(url)
232 video_id, playlist_id = self._match_valid_url(url).groups()
235 if self._yes_playlist(playlist_id, video_id):
236 return self.url_result(
237 'http
://www
.dailymotion
.com
/playlist
/' + playlist_id,
238 'DailymotionPlaylist
', playlist_id)
240 password = self.get_param('videopassword
')
241 media = self._call_api(
242 'media
', video_id, '''... on Video {
257 }''' % (self._COMMON_MEDIA_FIELDS, self._COMMON_MEDIA_FIELDS), 'Downloading media JSON metadata
',
258 'password
: "%s"' % self.get_param('videopassword
') if password else None)
261 metadata = self._download_json(
262 'https
://www
.dailymotion
.com
/player
/metadata
/video
/' + xid,
263 xid, 'Downloading metadata JSON
',
264 query=traverse_obj(smuggled_data, 'query
') or {'app': 'com.dailymotion.neon'})
266 error = metadata.get('error
')
268 title = error.get('title
') or error['raw_message
']
269 # See https://developer.dailymotion.com/api#access-error
270 if error.get('code
') == 'DM007
':
271 allowed_countries = try_get(media, lambda x: x['geoblockedCountries
']['allowed
'], list)
272 self.raise_geo_restricted(msg=title, countries=allowed_countries)
273 raise ExtractorError(
274 '%s said
: %s' % (self.IE_NAME, title), expected=True)
276 title = metadata['title
']
277 is_live = media.get('isOnAir
')
279 for quality, media_list in metadata['qualities
'].items():
281 media_url = m.get('url
')
282 media_type = m.get('type')
283 if not media_url or media_type == 'application
/vnd
.lumberjack
.manifest
':
285 if media_type == 'application
/x
-mpegURL
':
286 formats.extend(self._extract_m3u8_formats(
287 media_url, video_id, 'mp4
', live=is_live, m3u8_id='hls
', fatal=False))
291 'format_id
': 'http
-' + quality,
293 m = re.search(r'/H264
-(\d
+)x(\d
+)(?
:-(60)/)?
', media_url)
295 width, height, fps = map(int_or_none, m.groups())
303 f['url
'] = f['url
'].split('#')[0]
304 if not f
.get('fps') and f
['format_id'].endswith('@60'):
308 subtitles_data
= try_get(metadata
, lambda x
: x
['subtitles']['data'], dict) or {}
309 for subtitle_lang
, subtitle
in subtitles_data
.items():
310 subtitles
[subtitle_lang
] = [{
312 } for subtitle_url
in subtitle
.get('urls', [])]
315 for height
, poster_url
in metadata
.get('posters', {}).items():
317 'height': int_or_none(height
),
322 owner
= metadata
.get('owner') or {}
323 stats
= media
.get('stats') or {}
324 get_count
= lambda x
: int_or_none(try_get(stats
, lambda y
: y
[x
+ 's']['total']))
329 'description': clean_html(media
.get('description')),
330 'thumbnails': thumbnails
,
331 'duration': int_or_none(metadata
.get('duration')) or None,
332 'timestamp': int_or_none(metadata
.get('created_time')),
333 'uploader': owner
.get('screenname'),
334 'uploader_id': owner
.get('id') or metadata
.get('screenname'),
335 'age_limit': 18 if metadata
.get('explicit') else 0,
336 'tags': metadata
.get('tags'),
337 'view_count': get_count('view') or int_or_none(media
.get('audienceCount')),
338 'like_count': get_count('like'),
340 'subtitles': subtitles
,
345 class DailymotionPlaylistBaseIE(DailymotionBaseInfoExtractor
):
348 def _fetch_page(self
, playlist_id
, page
):
350 videos
= self
._call
_api
(
351 self
._OBJECT
_TYPE
, playlist_id
,
352 '''videos(allowExplicit: %s, first: %d, page: %d) {
359 }''' % ('false' if self
._FAMILY
_FILTER
else 'true', self
._PAGE
_SIZE
, page
),
360 'Downloading page %d' % page
)['videos']
361 for edge
in videos
['edges']:
363 yield self
.url_result(
364 node
['url'], DailymotionIE
.ie_key(), node
['xid'])
366 def _real_extract(self
, url
):
367 playlist_id
= self
._match
_id
(url
)
368 entries
= OnDemandPagedList(functools
.partial(
369 self
._fetch
_page
, playlist_id
), self
._PAGE
_SIZE
)
370 return self
.playlist_result(
371 entries
, playlist_id
)
374 class DailymotionPlaylistIE(DailymotionPlaylistBaseIE
):
375 IE_NAME
= 'dailymotion:playlist'
376 _VALID_URL
= r
'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>x[0-9a-z]+)'
378 'url': 'http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q',
382 'playlist_mincount': 20,
384 _OBJECT_TYPE
= 'collection'
387 def _extract_embed_urls(cls
, url
, webpage
):
388 # Look for embedded Dailymotion playlist player (#3822)
389 for mobj
in re
.finditer(
390 r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:www\
.)?dailymotion\
.[a
-z
]{2,3}
/widget
/jukebox
\?.+?
)\
1',
392 for p in re.findall(r'list\
[\
]=/playlist
/([^
/]+)/', unescapeHTML(mobj.group('url
'))):
393 yield '//dailymotion
.com
/playlist
/%s' % p
396 class DailymotionUserIE(DailymotionPlaylistBaseIE):
397 IE_NAME = 'dailymotion
:user
'
398 _VALID_URL = r'https?
://(?
:www\
.)?dailymotion\
.[a
-z
]{2,3}
/(?
!(?
:embed|swf|
#|video|playlist)/)(?:(?:old/)?user/)?(?P<id>[^/]+)'
400 'url': 'https://www.dailymotion.com/user/nqtv',
404 'playlist_mincount': 152,
406 'url': 'http://www.dailymotion.com/user/UnderProject',
408 'id': 'UnderProject',
410 'playlist_mincount': 1000,
411 'skip': 'Takes too long time',
413 'url': 'https://www.dailymotion.com/user/nqtv',
417 'playlist_mincount': 148,
422 _OBJECT_TYPE
= 'channel'