logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

dailymotion.py (23372B)


  1. import functools
  2. import json
  3. import re
  4. import urllib.parse
  5. from .common import InfoExtractor
  6. from ..networking.exceptions import HTTPError
  7. from ..utils import (
  8. ExtractorError,
  9. OnDemandPagedList,
  10. age_restricted,
  11. clean_html,
  12. extract_attributes,
  13. int_or_none,
  14. traverse_obj,
  15. try_get,
  16. unescapeHTML,
  17. unsmuggle_url,
  18. update_url,
  19. url_or_none,
  20. urlencode_postdata,
  21. )
  22. class DailymotionBaseInfoExtractor(InfoExtractor):
  23. _FAMILY_FILTER = None
  24. _HEADERS = {
  25. 'Content-Type': 'application/json',
  26. 'Origin': 'https://www.dailymotion.com',
  27. }
  28. _NETRC_MACHINE = 'dailymotion'
  29. def _get_dailymotion_cookies(self):
  30. return self._get_cookies('https://www.dailymotion.com/')
  31. @staticmethod
  32. def _get_cookie_value(cookies, name):
  33. cookie = cookies.get(name)
  34. if cookie:
  35. return cookie.value
  36. def _set_dailymotion_cookie(self, name, value):
  37. self._set_cookie('www.dailymotion.com', name, value)
  38. def _real_initialize(self):
  39. cookies = self._get_dailymotion_cookies()
  40. ff = self._get_cookie_value(cookies, 'ff')
  41. self._FAMILY_FILTER = ff == 'on' if ff else age_restricted(18, self.get_param('age_limit'))
  42. self._set_dailymotion_cookie('ff', 'on' if self._FAMILY_FILTER else 'off')
  43. def _get_token(self, xid):
  44. cookies = self._get_dailymotion_cookies()
  45. token = self._get_cookie_value(cookies, 'access_token') or self._get_cookie_value(cookies, 'client_token')
  46. if token:
  47. return token
  48. data = {
  49. 'client_id': 'f1a362d288c1b98099c7',
  50. 'client_secret': 'eea605b96e01c796ff369935357eca920c5da4c5',
  51. }
  52. username, password = self._get_login_info()
  53. if username:
  54. data.update({
  55. 'grant_type': 'password',
  56. 'password': password,
  57. 'username': username,
  58. })
  59. else:
  60. data['grant_type'] = 'client_credentials'
  61. try:
  62. token = self._download_json(
  63. 'https://graphql.api.dailymotion.com/oauth/token',
  64. None, 'Downloading Access Token',
  65. data=urlencode_postdata(data))['access_token']
  66. except ExtractorError as e:
  67. if isinstance(e.cause, HTTPError) and e.cause.status == 400:
  68. raise ExtractorError(self._parse_json(
  69. e.cause.response.read().decode(), xid)['error_description'], expected=True)
  70. raise
  71. self._set_dailymotion_cookie('access_token' if username else 'client_token', token)
  72. return token
  73. def _call_api(self, object_type, xid, object_fields, note, filter_extra=None):
  74. if not self._HEADERS.get('Authorization'):
  75. self._HEADERS['Authorization'] = f'Bearer {self._get_token(xid)}'
  76. resp = self._download_json(
  77. 'https://graphql.api.dailymotion.com/', xid, note, data=json.dumps({
  78. 'query': '''{
  79. %s(xid: "%s"%s) {
  80. %s
  81. }
  82. }''' % (object_type, xid, ', ' + filter_extra if filter_extra else '', object_fields), # noqa: UP031
  83. }).encode(), headers=self._HEADERS)
  84. obj = resp['data'][object_type]
  85. if not obj:
  86. raise ExtractorError(resp['errors'][0]['message'], expected=True)
  87. return obj
  88. class DailymotionIE(DailymotionBaseInfoExtractor):
  89. _VALID_URL = r'''(?ix)
  90. https?://
  91. (?:
  92. dai\.ly/|
  93. (?:
  94. (?:(?:www|touch|geo)\.)?dailymotion\.[a-z]{2,3}|
  95. (?:www\.)?lequipe\.fr
  96. )/
  97. (?:
  98. swf/(?!video)|
  99. (?:(?:crawler|embed|swf)/)?video/|
  100. player(?:/[\da-z]+)?\.html\?(?:video|(?P<is_playlist>playlist))=
  101. )
  102. )
  103. (?P<id>[^/?_&#]+)(?:[\w-]*\?playlist=(?P<playlist_id>x[0-9a-z]+))?
  104. '''
  105. IE_NAME = 'dailymotion'
  106. _EMBED_REGEX = [r'<(?:(?:embed|iframe)[^>]+?src=|input[^>]+id=[\'"]dmcloudUrlEmissionSelect[\'"][^>]+value=)(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.com/(?:embed|swf)/video/.+?)\1']
  107. _TESTS = [{
  108. 'url': 'http://www.dailymotion.com/video/x5kesuj_office-christmas-party-review-jason-bateman-olivia-munn-t-j-miller_news',
  109. 'md5': '074b95bdee76b9e3654137aee9c79dfe',
  110. 'info_dict': {
  111. 'id': 'x5kesuj',
  112. 'ext': 'mp4',
  113. 'title': 'Office Christmas Party Review – Jason Bateman, Olivia Munn, T.J. Miller',
  114. 'description': 'Office Christmas Party Review - Jason Bateman, Olivia Munn, T.J. Miller',
  115. 'duration': 187,
  116. 'timestamp': 1493651285,
  117. 'upload_date': '20170501',
  118. 'uploader': 'Deadline',
  119. 'uploader_id': 'x1xm8ri',
  120. 'age_limit': 0,
  121. 'view_count': int,
  122. 'like_count': int,
  123. 'tags': ['hollywood', 'celeb', 'celebrity', 'movies', 'red carpet'],
  124. 'thumbnail': r're:https://(?:s[12]\.)dmcdn\.net/v/K456B1cmt4ZcZ9KiM/x1080',
  125. },
  126. }, {
  127. 'url': 'https://geo.dailymotion.com/player.html?video=x89eyek&mute=true',
  128. 'md5': 'e2f9717c6604773f963f069ca53a07f8',
  129. 'info_dict': {
  130. 'id': 'x89eyek',
  131. 'ext': 'mp4',
  132. 'title': "En quête d'esprit du 27/03/2022",
  133. 'description': 'md5:66542b9f4df2eb23f314fc097488e553',
  134. 'duration': 2756,
  135. 'timestamp': 1648383669,
  136. 'upload_date': '20220327',
  137. 'uploader': 'CNEWS',
  138. 'uploader_id': 'x24vth',
  139. 'age_limit': 0,
  140. 'view_count': int,
  141. 'like_count': int,
  142. 'tags': ['en_quete_d_esprit'],
  143. 'thumbnail': r're:https://(?:s[12]\.)dmcdn\.net/v/Tncwi1clTH6StrxMP/x1080',
  144. },
  145. }, {
  146. 'url': 'https://www.dailymotion.com/video/x2iuewm_steam-machine-models-pricing-listed-on-steam-store-ign-news_videogames',
  147. 'md5': '2137c41a8e78554bb09225b8eb322406',
  148. 'info_dict': {
  149. 'id': 'x2iuewm',
  150. 'ext': 'mp4',
  151. 'title': 'Steam Machine Models, Pricing Listed on Steam Store - IGN News',
  152. 'description': 'Several come bundled with the Steam Controller.',
  153. 'thumbnail': r're:^https?:.*\.(?:jpg|png)$',
  154. 'duration': 74,
  155. 'timestamp': 1425657362,
  156. 'upload_date': '20150306',
  157. 'uploader': 'IGN',
  158. 'uploader_id': 'xijv66',
  159. 'age_limit': 0,
  160. 'view_count': int,
  161. },
  162. 'skip': 'video gone',
  163. }, {
  164. # Vevo video
  165. 'url': 'http://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musi',
  166. 'info_dict': {
  167. 'title': 'Roar (Official)',
  168. 'id': 'USUV71301934',
  169. 'ext': 'mp4',
  170. 'uploader': 'Katy Perry',
  171. 'upload_date': '20130905',
  172. },
  173. 'params': {
  174. 'skip_download': True,
  175. },
  176. 'skip': 'VEVO is only available in some countries',
  177. }, {
  178. # age-restricted video
  179. 'url': 'http://www.dailymotion.com/video/xyh2zz_leanna-decker-cyber-girl-of-the-year-desires-nude-playboy-plus_redband',
  180. 'md5': '0d667a7b9cebecc3c89ee93099c4159d',
  181. 'info_dict': {
  182. 'id': 'xyh2zz',
  183. 'ext': 'mp4',
  184. 'title': 'Leanna Decker - Cyber Girl Of The Year Desires Nude [Playboy Plus]',
  185. 'uploader': 'HotWaves1012',
  186. 'age_limit': 18,
  187. },
  188. 'skip': 'video gone',
  189. }, {
  190. # geo-restricted, player v5
  191. 'url': 'http://www.dailymotion.com/video/xhza0o',
  192. 'only_matching': True,
  193. }, {
  194. # with subtitles
  195. 'url': 'http://www.dailymotion.com/video/x20su5f_the-power-of-nightmares-1-the-rise-of-the-politics-of-fear-bbc-2004_news',
  196. 'only_matching': True,
  197. }, {
  198. 'url': 'http://www.dailymotion.com/swf/video/x3n92nf',
  199. 'only_matching': True,
  200. }, {
  201. 'url': 'http://www.dailymotion.com/swf/x3ss1m_funny-magic-trick-barry-and-stuart_fun',
  202. 'only_matching': True,
  203. }, {
  204. 'url': 'https://www.lequipe.fr/video/x791mem',
  205. 'only_matching': True,
  206. }, {
  207. 'url': 'https://www.lequipe.fr/video/k7MtHciueyTcrFtFKA2',
  208. 'only_matching': True,
  209. }, {
  210. 'url': 'https://www.dailymotion.com/video/x3z49k?playlist=xv4bw',
  211. 'only_matching': True,
  212. }, {
  213. 'url': 'https://geo.dailymotion.com/player/x86gw.html?video=k46oCapRs4iikoz9DWy',
  214. 'only_matching': True,
  215. }, {
  216. 'url': 'https://geo.dailymotion.com/player/xakln.html?video=x8mjju4&customConfig%5BcustomParams%5D=%2Ffr-fr%2Ftennis%2Fwimbledon-mens-singles%2Farticles-video',
  217. 'only_matching': True,
  218. }, { # playlist-only
  219. 'url': 'https://geo.dailymotion.com/player/xf7zn.html?playlist=x7wdsj',
  220. 'only_matching': True,
  221. }, {
  222. 'url': 'https://geo.dailymotion.com/player/xmyye.html?video=x93blhi',
  223. 'only_matching': True,
  224. }, {
  225. 'url': 'https://www.dailymotion.com/crawler/video/x8u4owg',
  226. 'only_matching': True,
  227. }, {
  228. 'url': 'https://www.dailymotion.com/embed/video/x8u4owg',
  229. 'only_matching': True,
  230. }, {
  231. 'url': 'https://dai.ly/x94cnnk',
  232. 'only_matching': True,
  233. }]
  234. _WEBPAGE_TESTS = [{
  235. # https://geo.dailymotion.com/player/xmyye.html?video=x93blhi
  236. 'url': 'https://www.financialounge.com/video/2024/08/01/borse-europee-in-rosso-dopo-la-fed-a-milano-volano-mediobanca-e-tim-edizione-del-1-agosto/',
  237. 'info_dict': {
  238. 'id': 'x93blhi',
  239. 'ext': 'mp4',
  240. 'title': 'OnAir - 01/08/24',
  241. 'description': '',
  242. 'duration': 217,
  243. 'timestamp': 1722505658,
  244. 'upload_date': '20240801',
  245. 'uploader': 'Financialounge',
  246. 'uploader_id': 'x2vtgmm',
  247. 'age_limit': 0,
  248. 'tags': [],
  249. 'view_count': int,
  250. 'like_count': int,
  251. 'thumbnail': r're:https://\w+.dmcdn.net/v/WnEY61cmvMxt2Fi6d/x1080',
  252. },
  253. }, {
  254. # https://geo.dailymotion.com/player/xf7zn.html?playlist=x7wdsj
  255. 'url': 'https://www.cycleworld.com/blogs/ask-kevin/ducati-continues-to-evolve-with-v4/',
  256. 'info_dict': {
  257. 'id': 'x7wdsj',
  258. },
  259. 'playlist_mincount': 50,
  260. }, {
  261. # https://www.dailymotion.com/crawler/video/x8u4owg
  262. 'url': 'https://www.leparisien.fr/environnement/video-le-veloto-la-voiture-a-pedales-qui-aimerait-se-faire-une-place-sur-les-routes-09-03-2024-KCYMCPM4WFHJXMSKBUI66UNFPU.php',
  263. 'info_dict': {
  264. 'id': 'x8u4owg',
  265. 'ext': 'mp4',
  266. 'like_count': int,
  267. 'uploader': 'Le Parisien',
  268. 'thumbnail': 'https://www.leparisien.fr/resizer/ho_GwveeYftNkLwg_cEta--5Bv4=/1200x675/cloudfront-eu-central-1.images.arcpublishing.com/leparisien/BFXJNEBN75EUNHGYJLORUC3TX4.jpg',
  269. 'upload_date': '20240309',
  270. 'view_count': int,
  271. 'timestamp': 1709997866,
  272. 'age_limit': 0,
  273. 'uploader_id': 'x32f7b',
  274. 'title': 'VIDÉO. Le «\xa0véloto\xa0», la voiture à pédales qui aimerait se faire une place sur les routes',
  275. 'duration': 428.0,
  276. 'description': 'À bord du « véloto », l’alternative à la voiture pour la campagne',
  277. 'tags': ['biclou', 'vélo', 'véloto', 'campagne', 'voiture', 'environnement', 'véhicules intermédiaires'],
  278. },
  279. }, {
  280. # https://geo.dailymotion.com/player/xry80.html?video=x8vu47w
  281. 'url': 'https://www.metatube.com/en/videos/546765/This-frogs-decorates-Christmas-tree/',
  282. 'info_dict': {
  283. 'id': 'x8vu47w',
  284. 'ext': 'mp4',
  285. 'like_count': int,
  286. 'uploader': 'Metatube',
  287. 'thumbnail': r're:https://\w+.dmcdn.net/v/W1G_S1coGSFTfkTeR/x1080',
  288. 'upload_date': '20240326',
  289. 'view_count': int,
  290. 'timestamp': 1711496732,
  291. 'age_limit': 0,
  292. 'uploader_id': 'x2xpy74',
  293. 'title': 'Está lindas ranitas ponen su arbolito',
  294. 'duration': 28,
  295. 'description': 'Que lindura',
  296. 'tags': [],
  297. },
  298. }]
  299. _GEO_BYPASS = False
  300. _COMMON_MEDIA_FIELDS = '''description
  301. geoblockedCountries {
  302. allowed
  303. }
  304. xid'''
  305. @classmethod
  306. def _extract_embed_urls(cls, url, webpage):
  307. # https://developer.dailymotion.com/player#player-parameters
  308. yield from super()._extract_embed_urls(url, webpage)
  309. for mobj in re.finditer(
  310. r'(?s)DM\.player\([^,]+,\s*{.*?video[\'"]?\s*:\s*["\']?(?P<id>[0-9a-zA-Z]+).+?}\s*\);', webpage):
  311. yield 'https://www.dailymotion.com/embed/video/' + mobj.group('id')
  312. for mobj in re.finditer(
  313. r'(?s)<script [^>]*\bsrc=(["\'])(?:https?:)?//[\w-]+\.dailymotion\.com/player/(?:(?!\1).)+\1[^>]*>', webpage):
  314. attrs = extract_attributes(mobj.group(0))
  315. player_url = url_or_none(attrs.get('src'))
  316. if not player_url:
  317. continue
  318. player_url = player_url.replace('.js', '.html')
  319. if player_url.startswith('//'):
  320. player_url = f'https:{player_url}'
  321. if video_id := attrs.get('data-video'):
  322. query_string = f'video={video_id}'
  323. elif playlist_id := attrs.get('data-playlist'):
  324. query_string = f'playlist={playlist_id}'
  325. else:
  326. continue
  327. yield update_url(player_url, query=query_string)
  328. def _real_extract(self, url):
  329. url, smuggled_data = unsmuggle_url(url)
  330. video_id, is_playlist, playlist_id = self._match_valid_url(url).group('id', 'is_playlist', 'playlist_id')
  331. if is_playlist: # We matched the playlist query param as video_id
  332. playlist_id = video_id
  333. video_id = None
  334. if self._yes_playlist(playlist_id, video_id):
  335. return self.url_result(
  336. f'http://www.dailymotion.com/playlist/{playlist_id}',
  337. 'DailymotionPlaylist', playlist_id)
  338. password = self.get_param('videopassword')
  339. media = self._call_api(
  340. 'media', video_id, '''... on Video {
  341. %s
  342. stats {
  343. likes {
  344. total
  345. }
  346. views {
  347. total
  348. }
  349. }
  350. }
  351. ... on Live {
  352. %s
  353. audienceCount
  354. isOnAir
  355. }''' % (self._COMMON_MEDIA_FIELDS, self._COMMON_MEDIA_FIELDS), 'Downloading media JSON metadata', # noqa: UP031
  356. 'password: "{}"'.format(self.get_param('videopassword')) if password else None)
  357. xid = media['xid']
  358. metadata = self._download_json(
  359. 'https://www.dailymotion.com/player/metadata/video/' + xid,
  360. xid, 'Downloading metadata JSON',
  361. query=traverse_obj(smuggled_data, 'query') or {'app': 'com.dailymotion.neon'})
  362. error = metadata.get('error')
  363. if error:
  364. title = error.get('title') or error['raw_message']
  365. # See https://developer.dailymotion.com/api#access-error
  366. if error.get('code') == 'DM007':
  367. allowed_countries = try_get(media, lambda x: x['geoblockedCountries']['allowed'], list)
  368. self.raise_geo_restricted(msg=title, countries=allowed_countries)
  369. raise ExtractorError(
  370. f'{self.IE_NAME} said: {title}', expected=True)
  371. title = metadata['title']
  372. is_live = media.get('isOnAir')
  373. formats = []
  374. subtitles = {}
  375. for quality, media_list in metadata['qualities'].items():
  376. for m in media_list:
  377. media_url = m.get('url')
  378. media_type = m.get('type')
  379. if not media_url or media_type == 'application/vnd.lumberjack.manifest':
  380. continue
  381. if media_type == 'application/x-mpegURL':
  382. fmt, subs = self._extract_m3u8_formats_and_subtitles(
  383. media_url, video_id, 'mp4', live=is_live, m3u8_id='hls', fatal=False)
  384. formats.extend(fmt)
  385. self._merge_subtitles(subs, target=subtitles)
  386. else:
  387. f = {
  388. 'url': media_url,
  389. 'format_id': 'http-' + quality,
  390. }
  391. m = re.search(r'/H264-(\d+)x(\d+)(?:-(60)/)?', media_url)
  392. if m:
  393. width, height, fps = map(int_or_none, m.groups())
  394. f.update({
  395. 'fps': fps,
  396. 'height': height,
  397. 'width': width,
  398. })
  399. formats.append(f)
  400. for f in formats:
  401. f['url'] = f['url'].split('#')[0]
  402. if not f.get('fps') and f['format_id'].endswith('@60'):
  403. f['fps'] = 60
  404. subtitles_data = try_get(metadata, lambda x: x['subtitles']['data'], dict) or {}
  405. for subtitle_lang, subtitle in subtitles_data.items():
  406. subtitles[subtitle_lang] = [{
  407. 'url': subtitle_url,
  408. } for subtitle_url in subtitle.get('urls', [])]
  409. thumbnails = traverse_obj(metadata, (
  410. ('posters', 'thumbnails'), {dict.items}, lambda _, v: url_or_none(v[1]), {
  411. 'height': (0, {int_or_none}),
  412. 'id': (0, {str}),
  413. 'url': 1,
  414. }))
  415. owner = metadata.get('owner') or {}
  416. stats = media.get('stats') or {}
  417. get_count = lambda x: int_or_none(try_get(stats, lambda y: y[x + 's']['total']))
  418. return {
  419. 'id': video_id,
  420. 'title': title,
  421. 'description': clean_html(media.get('description')),
  422. 'thumbnails': thumbnails,
  423. 'duration': int_or_none(metadata.get('duration')) or None,
  424. 'timestamp': int_or_none(metadata.get('created_time')),
  425. 'uploader': owner.get('screenname'),
  426. 'uploader_id': owner.get('id') or metadata.get('screenname'),
  427. 'age_limit': 18 if metadata.get('explicit') else 0,
  428. 'tags': metadata.get('tags'),
  429. 'view_count': get_count('view') or int_or_none(media.get('audienceCount')),
  430. 'like_count': get_count('like'),
  431. 'formats': formats,
  432. 'subtitles': subtitles,
  433. 'is_live': is_live,
  434. }
  435. class DailymotionPlaylistBaseIE(DailymotionBaseInfoExtractor):
  436. _PAGE_SIZE = 100
  437. def _fetch_page(self, playlist_id, page):
  438. page += 1
  439. videos = self._call_api(
  440. self._OBJECT_TYPE, playlist_id,
  441. '''videos(allowExplicit: %s, first: %d, page: %d) {
  442. edges {
  443. node {
  444. xid
  445. url
  446. }
  447. }
  448. }''' % ('false' if self._FAMILY_FILTER else 'true', self._PAGE_SIZE, page),
  449. f'Downloading page {page}')['videos']
  450. for edge in videos['edges']:
  451. node = edge['node']
  452. yield self.url_result(
  453. node['url'], DailymotionIE.ie_key(), node['xid'])
  454. def _real_extract(self, url):
  455. playlist_id = self._match_id(url)
  456. entries = OnDemandPagedList(functools.partial(
  457. self._fetch_page, playlist_id), self._PAGE_SIZE)
  458. return self.playlist_result(
  459. entries, playlist_id)
  460. class DailymotionPlaylistIE(DailymotionPlaylistBaseIE):
  461. IE_NAME = 'dailymotion:playlist'
  462. _VALID_URL = r'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>x[0-9a-z]+)'
  463. _TESTS = [{
  464. 'url': 'http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q',
  465. 'info_dict': {
  466. 'id': 'xv4bw',
  467. },
  468. 'playlist_mincount': 20,
  469. }]
  470. _OBJECT_TYPE = 'collection'
  471. @classmethod
  472. def _extract_embed_urls(cls, url, webpage):
  473. # Look for embedded Dailymotion playlist player (#3822)
  474. for mobj in re.finditer(
  475. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?dailymotion\.[a-z]{2,3}/widget/jukebox\?.+?)\1',
  476. webpage):
  477. for p in re.findall(r'list\[\]=/playlist/([^/]+)/', unescapeHTML(mobj.group('url'))):
  478. yield f'//dailymotion.com/playlist/{p}'
  479. class DailymotionSearchIE(DailymotionPlaylistBaseIE):
  480. IE_NAME = 'dailymotion:search'
  481. _VALID_URL = r'https?://(?:www\.)?dailymotion\.[a-z]{2,3}/search/(?P<id>[^/?#]+)/videos'
  482. _PAGE_SIZE = 20
  483. _TESTS = [{
  484. 'url': 'http://www.dailymotion.com/search/king of turtles/videos',
  485. 'info_dict': {
  486. 'id': 'king of turtles',
  487. 'title': 'king of turtles',
  488. },
  489. 'playlist_mincount': 90,
  490. }]
  491. _SEARCH_QUERY = 'query SEARCH_QUERY( $query: String! $page: Int $limit: Int ) { search { videos( query: $query first: $limit page: $page ) { edges { node { xid } } } } } '
  492. def _call_search_api(self, term, page, note):
  493. if not self._HEADERS.get('Authorization'):
  494. self._HEADERS['Authorization'] = f'Bearer {self._get_token(term)}'
  495. resp = self._download_json(
  496. 'https://graphql.api.dailymotion.com/', None, note, data=json.dumps({
  497. 'operationName': 'SEARCH_QUERY',
  498. 'query': self._SEARCH_QUERY,
  499. 'variables': {
  500. 'limit': 20,
  501. 'page': page,
  502. 'query': term,
  503. },
  504. }).encode(), headers=self._HEADERS)
  505. obj = traverse_obj(resp, ('data', 'search', {dict}))
  506. if not obj:
  507. raise ExtractorError(
  508. traverse_obj(resp, ('errors', 0, 'message', {str})) or 'Could not fetch search data')
  509. return obj
  510. def _fetch_page(self, term, page):
  511. page += 1
  512. response = self._call_search_api(term, page, f'Searching "{term}" page {page}')
  513. for xid in traverse_obj(response, ('videos', 'edges', ..., 'node', 'xid')):
  514. yield self.url_result(f'https://www.dailymotion.com/video/{xid}', DailymotionIE, xid)
  515. def _real_extract(self, url):
  516. term = urllib.parse.unquote_plus(self._match_id(url))
  517. return self.playlist_result(
  518. OnDemandPagedList(functools.partial(self._fetch_page, term), self._PAGE_SIZE), term, term)
  519. class DailymotionUserIE(DailymotionPlaylistBaseIE):
  520. IE_NAME = 'dailymotion:user'
  521. _VALID_URL = r'https?://(?:www\.)?dailymotion\.[a-z]{2,3}/(?!(?:embed|swf|#|video|playlist|search|crawler)/)(?:(?:old/)?user/)?(?P<id>[^/?#]+)'
  522. _TESTS = [{
  523. 'url': 'https://www.dailymotion.com/user/nqtv',
  524. 'info_dict': {
  525. 'id': 'nqtv',
  526. },
  527. 'playlist_mincount': 152,
  528. }, {
  529. 'url': 'http://www.dailymotion.com/user/UnderProject',
  530. 'info_dict': {
  531. 'id': 'UnderProject',
  532. },
  533. 'playlist_mincount': 1000,
  534. 'skip': 'Takes too long time',
  535. }, {
  536. 'url': 'https://www.dailymotion.com/user/nqtv',
  537. 'info_dict': {
  538. 'id': 'nqtv',
  539. },
  540. 'playlist_mincount': 148,
  541. 'params': {
  542. 'age_limit': 0,
  543. },
  544. }]
  545. _OBJECT_TYPE = 'channel'