You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1183 lines
48 KiB

8 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. import json
  5. import re
  6. import itertools
  7. from .common import InfoExtractor
  8. from ..compat import (
  9. compat_HTTPError,
  10. compat_str,
  11. compat_urlparse,
  12. )
  13. from ..utils import (
  14. determine_ext,
  15. ExtractorError,
  16. js_to_json,
  17. InAdvancePagedList,
  18. int_or_none,
  19. merge_dicts,
  20. NO_DEFAULT,
  21. parse_filesize,
  22. qualities,
  23. RegexNotFoundError,
  24. sanitized_Request,
  25. smuggle_url,
  26. std_headers,
  27. try_get,
  28. unified_timestamp,
  29. unsmuggle_url,
  30. urlencode_postdata,
  31. unescapeHTML,
  32. )
  33. class VimeoBaseInfoExtractor(InfoExtractor):
  34. _NETRC_MACHINE = 'vimeo'
  35. _LOGIN_REQUIRED = False
  36. _LOGIN_URL = 'https://vimeo.com/log_in'
  37. def _login(self):
  38. username, password = self._get_login_info()
  39. if username is None:
  40. if self._LOGIN_REQUIRED:
  41. raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
  42. return
  43. webpage = self._download_webpage(
  44. self._LOGIN_URL, None, 'Downloading login page')
  45. token, vuid = self._extract_xsrft_and_vuid(webpage)
  46. data = {
  47. 'action': 'login',
  48. 'email': username,
  49. 'password': password,
  50. 'service': 'vimeo',
  51. 'token': token,
  52. }
  53. self._set_vimeo_cookie('vuid', vuid)
  54. try:
  55. self._download_webpage(
  56. self._LOGIN_URL, None, 'Logging in',
  57. data=urlencode_postdata(data), headers={
  58. 'Content-Type': 'application/x-www-form-urlencoded',
  59. 'Referer': self._LOGIN_URL,
  60. })
  61. except ExtractorError as e:
  62. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 418:
  63. raise ExtractorError(
  64. 'Unable to log in: bad username or password',
  65. expected=True)
  66. raise ExtractorError('Unable to log in')
  67. def _verify_video_password(self, url, video_id, webpage):
  68. password = self._downloader.params.get('videopassword')
  69. if password is None:
  70. raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
  71. token, vuid = self._extract_xsrft_and_vuid(webpage)
  72. data = urlencode_postdata({
  73. 'password': password,
  74. 'token': token,
  75. })
  76. if url.startswith('http://'):
  77. # vimeo only supports https now, but the user can give an http url
  78. url = url.replace('http://', 'https://')
  79. password_request = sanitized_Request(url + '/password', data)
  80. password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  81. password_request.add_header('Referer', url)
  82. self._set_vimeo_cookie('vuid', vuid)
  83. return self._download_webpage(
  84. password_request, video_id,
  85. 'Verifying the password', 'Wrong password')
  86. def _extract_xsrft_and_vuid(self, webpage):
  87. xsrft = self._search_regex(
  88. r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
  89. webpage, 'login token', group='xsrft')
  90. vuid = self._search_regex(
  91. r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
  92. webpage, 'vuid', group='vuid')
  93. return xsrft, vuid
  94. def _set_vimeo_cookie(self, name, value):
  95. self._set_cookie('vimeo.com', name, value)
  96. def _vimeo_sort_formats(self, formats):
  97. # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
  98. # at the same time without actual units specified. This lead to wrong sorting.
  99. self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'tbr', 'format_id'))
  100. def _parse_config(self, config, video_id):
  101. video_data = config['video']
  102. # Extract title
  103. video_title = video_data['title']
  104. # Extract uploader, uploader_url and uploader_id
  105. video_uploader = video_data.get('owner', {}).get('name')
  106. video_uploader_url = video_data.get('owner', {}).get('url')
  107. video_uploader_id = video_uploader_url.split('/')[-1] if video_uploader_url else None
  108. # Extract video thumbnail
  109. video_thumbnail = video_data.get('thumbnail')
  110. if video_thumbnail is None:
  111. video_thumbs = video_data.get('thumbs')
  112. if video_thumbs and isinstance(video_thumbs, dict):
  113. _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
  114. # Extract video duration
  115. video_duration = int_or_none(video_data.get('duration'))
  116. formats = []
  117. config_files = video_data.get('files') or config['request'].get('files', {})
  118. for f in config_files.get('progressive', []):
  119. video_url = f.get('url')
  120. if not video_url:
  121. continue
  122. formats.append({
  123. 'url': video_url,
  124. 'format_id': 'http-%s' % f.get('quality'),
  125. 'width': int_or_none(f.get('width')),
  126. 'height': int_or_none(f.get('height')),
  127. 'fps': int_or_none(f.get('fps')),
  128. 'tbr': int_or_none(f.get('bitrate')),
  129. })
  130. for files_type in ('hls', 'dash'):
  131. for cdn_name, cdn_data in config_files.get(files_type, {}).get('cdns', {}).items():
  132. manifest_url = cdn_data.get('url')
  133. if not manifest_url:
  134. continue
  135. format_id = '%s-%s' % (files_type, cdn_name)
  136. if files_type == 'hls':
  137. formats.extend(self._extract_m3u8_formats(
  138. manifest_url, video_id, 'mp4',
  139. 'm3u8_native', m3u8_id=format_id,
  140. note='Downloading %s m3u8 information' % cdn_name,
  141. fatal=False))
  142. elif files_type == 'dash':
  143. mpd_pattern = r'/%s/(?:sep/)?video/' % video_id
  144. mpd_manifest_urls = []
  145. if re.search(mpd_pattern, manifest_url):
  146. for suffix, repl in (('', 'video'), ('_sep', 'sep/video')):
  147. mpd_manifest_urls.append((format_id + suffix, re.sub(
  148. mpd_pattern, '/%s/%s/' % (video_id, repl), manifest_url)))
  149. else:
  150. mpd_manifest_urls = [(format_id, manifest_url)]
  151. for f_id, m_url in mpd_manifest_urls:
  152. mpd_formats = self._extract_mpd_formats(
  153. m_url.replace('/master.json', '/master.mpd'), video_id, f_id,
  154. 'Downloading %s MPD information' % cdn_name,
  155. fatal=False)
  156. for f in mpd_formats:
  157. if f.get('vcodec') == 'none':
  158. f['preference'] = -50
  159. elif f.get('acodec') == 'none':
  160. f['preference'] = -40
  161. formats.extend(mpd_formats)
  162. subtitles = {}
  163. text_tracks = config['request'].get('text_tracks')
  164. if text_tracks:
  165. for tt in text_tracks:
  166. subtitles[tt['lang']] = [{
  167. 'ext': 'vtt',
  168. 'url': 'https://vimeo.com' + tt['url'],
  169. }]
  170. return {
  171. 'title': video_title,
  172. 'uploader': video_uploader,
  173. 'uploader_id': video_uploader_id,
  174. 'uploader_url': video_uploader_url,
  175. 'thumbnail': video_thumbnail,
  176. 'duration': video_duration,
  177. 'formats': formats,
  178. 'subtitles': subtitles,
  179. }
  180. class VimeoIE(VimeoBaseInfoExtractor):
  181. """Information extractor for vimeo.com."""
  182. # _VALID_URL matches Vimeo URLs
  183. _VALID_URL = r'''(?x)
  184. https?://
  185. (?:
  186. (?:
  187. www|
  188. (?P<player>player)
  189. )
  190. \.
  191. )?
  192. vimeo(?P<pro>pro)?\.com/
  193. (?!(?:channels|album)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/)
  194. (?:.*?/)?
  195. (?:
  196. (?:
  197. play_redirect_hls|
  198. moogaloop\.swf)\?clip_id=
  199. )?
  200. (?:videos?/)?
  201. (?P<id>[0-9]+)
  202. (?:/[\da-f]+)?
  203. /?(?:[?&].*)?(?:[#].*)?$
  204. '''
  205. IE_NAME = 'vimeo'
  206. _TESTS = [
  207. {
  208. 'url': 'http://vimeo.com/56015672#at=0',
  209. 'md5': '8879b6cc097e987f02484baf890129e5',
  210. 'info_dict': {
  211. 'id': '56015672',
  212. 'ext': 'mp4',
  213. 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
  214. 'description': 'md5:509a9ad5c9bf97c60faee9203aca4479',
  215. 'timestamp': 1355990239,
  216. 'upload_date': '20121220',
  217. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user7108434',
  218. 'uploader_id': 'user7108434',
  219. 'uploader': 'Filippo Valsorda',
  220. 'duration': 10,
  221. 'license': 'by-sa',
  222. },
  223. },
  224. {
  225. 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
  226. 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
  227. 'note': 'Vimeo Pro video (#1197)',
  228. 'info_dict': {
  229. 'id': '68093876',
  230. 'ext': 'mp4',
  231. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/openstreetmapus',
  232. 'uploader_id': 'openstreetmapus',
  233. 'uploader': 'OpenStreetMap US',
  234. 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
  235. 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30',
  236. 'duration': 1595,
  237. },
  238. },
  239. {
  240. 'url': 'http://player.vimeo.com/video/54469442',
  241. 'md5': '619b811a4417aa4abe78dc653becf511',
  242. 'note': 'Videos that embed the url in the player page',
  243. 'info_dict': {
  244. 'id': '54469442',
  245. 'ext': 'mp4',
  246. 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
  247. 'uploader': 'The BLN & Business of Software',
  248. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/theblnbusinessofsoftware',
  249. 'uploader_id': 'theblnbusinessofsoftware',
  250. 'duration': 3610,
  251. 'description': None,
  252. },
  253. },
  254. {
  255. 'url': 'http://vimeo.com/68375962',
  256. 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
  257. 'note': 'Video protected with password',
  258. 'info_dict': {
  259. 'id': '68375962',
  260. 'ext': 'mp4',
  261. 'title': 'youtube-dl password protected test video',
  262. 'timestamp': 1371200155,
  263. 'upload_date': '20130614',
  264. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
  265. 'uploader_id': 'user18948128',
  266. 'uploader': 'Jaime Marquínez Ferrándiz',
  267. 'duration': 10,
  268. 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f',
  269. },
  270. 'params': {
  271. 'videopassword': 'youtube-dl',
  272. },
  273. },
  274. {
  275. 'url': 'http://vimeo.com/channels/keypeele/75629013',
  276. 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
  277. 'info_dict': {
  278. 'id': '75629013',
  279. 'ext': 'mp4',
  280. 'title': 'Key & Peele: Terrorist Interrogation',
  281. 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
  282. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/atencio',
  283. 'uploader_id': 'atencio',
  284. 'uploader': 'Peter Atencio',
  285. 'channel_id': 'keypeele',
  286. 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/keypeele',
  287. 'timestamp': 1380339469,
  288. 'upload_date': '20130928',
  289. 'duration': 187,
  290. },
  291. 'expected_warnings': ['Unable to download JSON metadata'],
  292. },
  293. {
  294. 'url': 'http://vimeo.com/76979871',
  295. 'note': 'Video with subtitles',
  296. 'info_dict': {
  297. 'id': '76979871',
  298. 'ext': 'mp4',
  299. 'title': 'The New Vimeo Player (You Know, For Videos)',
  300. 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
  301. 'timestamp': 1381846109,
  302. 'upload_date': '20131015',
  303. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/staff',
  304. 'uploader_id': 'staff',
  305. 'uploader': 'Vimeo Staff',
  306. 'duration': 62,
  307. }
  308. },
  309. {
  310. # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
  311. 'url': 'https://player.vimeo.com/video/98044508',
  312. 'note': 'The js code contains assignments to the same variable as the config',
  313. 'info_dict': {
  314. 'id': '98044508',
  315. 'ext': 'mp4',
  316. 'title': 'Pier Solar OUYA Official Trailer',
  317. 'uploader': 'Tulio Gonçalves',
  318. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user28849593',
  319. 'uploader_id': 'user28849593',
  320. },
  321. },
  322. {
  323. # contains original format
  324. 'url': 'https://vimeo.com/33951933',
  325. 'md5': '53c688fa95a55bf4b7293d37a89c5c53',
  326. 'info_dict': {
  327. 'id': '33951933',
  328. 'ext': 'mp4',
  329. 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute',
  330. 'uploader': 'The DMCI',
  331. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/dmci',
  332. 'uploader_id': 'dmci',
  333. 'timestamp': 1324343742,
  334. 'upload_date': '20111220',
  335. 'description': 'md5:ae23671e82d05415868f7ad1aec21147',
  336. },
  337. },
  338. {
  339. # only available via https://vimeo.com/channels/tributes/6213729 and
  340. # not via https://vimeo.com/6213729
  341. 'url': 'https://vimeo.com/channels/tributes/6213729',
  342. 'info_dict': {
  343. 'id': '6213729',
  344. 'ext': 'mp4',
  345. 'title': 'Vimeo Tribute: The Shining',
  346. 'uploader': 'Casey Donahue',
  347. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/caseydonahue',
  348. 'uploader_id': 'caseydonahue',
  349. 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/tributes',
  350. 'channel_id': 'tributes',
  351. 'timestamp': 1250886430,
  352. 'upload_date': '20090821',
  353. 'description': 'md5:bdbf314014e58713e6e5b66eb252f4a6',
  354. },
  355. 'params': {
  356. 'skip_download': True,
  357. },
  358. 'expected_warnings': ['Unable to download JSON metadata'],
  359. },
  360. {
  361. # redirects to ondemand extractor and should be passed through it
  362. # for successful extraction
  363. 'url': 'https://vimeo.com/73445910',
  364. 'info_dict': {
  365. 'id': '73445910',
  366. 'ext': 'mp4',
  367. 'title': 'The Reluctant Revolutionary',
  368. 'uploader': '10Ft Films',
  369. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/tenfootfilms',
  370. 'uploader_id': 'tenfootfilms',
  371. },
  372. 'params': {
  373. 'skip_download': True,
  374. },
  375. },
  376. {
  377. 'url': 'http://player.vimeo.com/video/68375962',
  378. 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
  379. 'info_dict': {
  380. 'id': '68375962',
  381. 'ext': 'mp4',
  382. 'title': 'youtube-dl password protected test video',
  383. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
  384. 'uploader_id': 'user18948128',
  385. 'uploader': 'Jaime Marquínez Ferrándiz',
  386. 'duration': 10,
  387. },
  388. 'params': {
  389. 'videopassword': 'youtube-dl',
  390. },
  391. },
  392. {
  393. 'url': 'http://vimeo.com/moogaloop.swf?clip_id=2539741',
  394. 'only_matching': True,
  395. },
  396. {
  397. 'url': 'https://vimeo.com/109815029',
  398. 'note': 'Video not completely processed, "failed" seed status',
  399. 'only_matching': True,
  400. },
  401. {
  402. 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
  403. 'only_matching': True,
  404. },
  405. {
  406. 'url': 'https://vimeo.com/album/2632481/video/79010983',
  407. 'only_matching': True,
  408. },
  409. {
  410. # source file returns 403: Forbidden
  411. 'url': 'https://vimeo.com/7809605',
  412. 'only_matching': True,
  413. },
  414. {
  415. 'url': 'https://vimeo.com/160743502/abd0e13fb4',
  416. 'only_matching': True,
  417. }
  418. # https://gettingthingsdone.com/workflowmap/
  419. # vimeo embed with check-password page protected by Referer header
  420. ]
  421. @staticmethod
  422. def _smuggle_referrer(url, referrer_url):
  423. return smuggle_url(url, {'http_headers': {'Referer': referrer_url}})
  424. @staticmethod
  425. def _extract_urls(url, webpage):
  426. urls = []
  427. # Look for embedded (iframe) Vimeo player
  428. for mobj in re.finditer(
  429. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/\d+.*?)\1',
  430. webpage):
  431. urls.append(VimeoIE._smuggle_referrer(unescapeHTML(mobj.group('url')), url))
  432. PLAIN_EMBED_RE = (
  433. # Look for embedded (swf embed) Vimeo player
  434. r'<embed[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)\1',
  435. # Look more for non-standard embedded Vimeo player
  436. r'<video[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)\1',
  437. )
  438. for embed_re in PLAIN_EMBED_RE:
  439. for mobj in re.finditer(embed_re, webpage):
  440. urls.append(mobj.group('url'))
  441. return urls
  442. @staticmethod
  443. def _extract_url(url, webpage):
  444. urls = VimeoIE._extract_urls(url, webpage)
  445. return urls[0] if urls else None
  446. def _verify_player_video_password(self, url, video_id, headers):
  447. password = self._downloader.params.get('videopassword')
  448. if password is None:
  449. raise ExtractorError('This video is protected by a password, use the --video-password option')
  450. data = urlencode_postdata({
  451. 'password': base64.b64encode(password.encode()),
  452. })
  453. headers = merge_dicts(headers, {
  454. 'Content-Type': 'application/x-www-form-urlencoded',
  455. })
  456. checked = self._download_json(
  457. url + '/check-password', video_id,
  458. 'Verifying the password', data=data, headers=headers)
  459. if checked is False:
  460. raise ExtractorError('Wrong video password', expected=True)
  461. return checked
  462. def _real_initialize(self):
  463. self._login()
  464. def _real_extract(self, url):
  465. url, data = unsmuggle_url(url, {})
  466. headers = std_headers.copy()
  467. if 'http_headers' in data:
  468. headers.update(data['http_headers'])
  469. if 'Referer' not in headers:
  470. headers['Referer'] = url
  471. channel_id = self._search_regex(
  472. r'vimeo\.com/channels/([^/]+)', url, 'channel id', default=None)
  473. # Extract ID from URL
  474. mobj = re.match(self._VALID_URL, url)
  475. video_id = mobj.group('id')
  476. orig_url = url
  477. if mobj.group('pro') or mobj.group('player'):
  478. url = 'https://player.vimeo.com/video/' + video_id
  479. elif any(p in url for p in ('play_redirect_hls', 'moogaloop.swf')):
  480. url = 'https://vimeo.com/' + video_id
  481. # Retrieve video webpage to extract further information
  482. request = sanitized_Request(url, headers=headers)
  483. try:
  484. webpage, urlh = self._download_webpage_handle(request, video_id)
  485. redirect_url = compat_str(urlh.geturl())
  486. # Some URLs redirect to ondemand can't be extracted with
  487. # this extractor right away thus should be passed through
  488. # ondemand extractor (e.g. https://vimeo.com/73445910)
  489. if VimeoOndemandIE.suitable(redirect_url):
  490. return self.url_result(redirect_url, VimeoOndemandIE.ie_key())
  491. except ExtractorError as ee:
  492. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
  493. errmsg = ee.cause.read()
  494. if b'Because of its privacy settings, this video cannot be played here' in errmsg:
  495. raise ExtractorError(
  496. 'Cannot download embed-only video without embedding '
  497. 'URL. Please call youtube-dl with the URL of the page '
  498. 'that embeds this video.',
  499. expected=True)
  500. raise
  501. # Now we begin extracting as much information as we can from what we
  502. # retrieved. First we extract the information common to all extractors,
  503. # and latter we extract those that are Vimeo specific.
  504. self.report_extraction(video_id)
  505. vimeo_config = self._search_regex(
  506. r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage,
  507. 'vimeo config', default=None)
  508. if vimeo_config:
  509. seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
  510. if seed_status.get('state') == 'failed':
  511. raise ExtractorError(
  512. '%s said: %s' % (self.IE_NAME, seed_status['title']),
  513. expected=True)
  514. cc_license = None
  515. timestamp = None
  516. # Extract the config JSON
  517. try:
  518. try:
  519. config_url = self._html_search_regex(
  520. r' data-config-url="(.+?)"', webpage,
  521. 'config URL', default=None)
  522. if not config_url:
  523. # Sometimes new react-based page is served instead of old one that require
  524. # different config URL extraction approach (see
  525. # https://github.com/rg3/youtube-dl/pull/7209)
  526. vimeo_clip_page_config = self._search_regex(
  527. r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage,
  528. 'vimeo clip page config')
  529. page_config = self._parse_json(vimeo_clip_page_config, video_id)
  530. config_url = page_config['player']['config_url']
  531. cc_license = page_config.get('cc_license')
  532. timestamp = try_get(
  533. page_config, lambda x: x['clip']['uploaded_on'],
  534. compat_str)
  535. config_json = self._download_webpage(config_url, video_id)
  536. config = json.loads(config_json)
  537. except RegexNotFoundError:
  538. # For pro videos or player.vimeo.com urls
  539. # We try to find out to which variable is assigned the config dic
  540. m_variable_name = re.search(r'(\w)\.video\.id', webpage)
  541. if m_variable_name is not None:
  542. config_re = [r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))]
  543. else:
  544. config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
  545. config_re.append(r'\bvar\s+r\s*=\s*({.+?})\s*;')
  546. config_re.append(r'\bconfig\s*=\s*({.+?})\s*;')
  547. config = self._search_regex(config_re, webpage, 'info section',
  548. flags=re.DOTALL)
  549. config = json.loads(config)
  550. except Exception as e:
  551. if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
  552. raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
  553. if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
  554. if '_video_password_verified' in data:
  555. raise ExtractorError('video password verification failed!')
  556. self._verify_video_password(redirect_url, video_id, webpage)
  557. return self._real_extract(
  558. smuggle_url(redirect_url, {'_video_password_verified': 'verified'}))
  559. else:
  560. raise ExtractorError('Unable to extract info section',
  561. cause=e)
  562. else:
  563. if config.get('view') == 4:
  564. config = self._verify_player_video_password(redirect_url, video_id, headers)
  565. vod = config.get('video', {}).get('vod', {})
  566. def is_rented():
  567. if '>You rented this title.<' in webpage:
  568. return True
  569. if config.get('user', {}).get('purchased'):
  570. return True
  571. for purchase_option in vod.get('purchase_options', []):
  572. if purchase_option.get('purchased'):
  573. return True
  574. label = purchase_option.get('label_string')
  575. if label and (label.startswith('You rented this') or label.endswith(' remaining')):
  576. return True
  577. return False
  578. if is_rented() and vod.get('is_trailer'):
  579. feature_id = vod.get('feature_id')
  580. if feature_id and not data.get('force_feature_id', False):
  581. return self.url_result(smuggle_url(
  582. 'https://player.vimeo.com/player/%s' % feature_id,
  583. {'force_feature_id': True}), 'Vimeo')
  584. # Extract video description
  585. video_description = self._html_search_regex(
  586. r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
  587. webpage, 'description', default=None)
  588. if not video_description:
  589. video_description = self._html_search_meta(
  590. 'description', webpage, default=None)
  591. if not video_description and mobj.group('pro'):
  592. orig_webpage = self._download_webpage(
  593. orig_url, video_id,
  594. note='Downloading webpage for description',
  595. fatal=False)
  596. if orig_webpage:
  597. video_description = self._html_search_meta(
  598. 'description', orig_webpage, default=None)
  599. if not video_description and not mobj.group('player'):
  600. self._downloader.report_warning('Cannot find video description')
  601. # Extract upload date
  602. if not timestamp:
  603. timestamp = self._search_regex(
  604. r'<time[^>]+datetime="([^"]+)"', webpage,
  605. 'timestamp', default=None)
  606. try:
  607. view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
  608. like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
  609. comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
  610. except RegexNotFoundError:
  611. # This info is only available in vimeo.com/{id} urls
  612. view_count = None
  613. like_count = None
  614. comment_count = None
  615. formats = []
  616. download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={
  617. 'X-Requested-With': 'XMLHttpRequest'})
  618. download_data = self._download_json(download_request, video_id, fatal=False)
  619. if download_data:
  620. source_file = download_data.get('source_file')
  621. if isinstance(source_file, dict):
  622. download_url = source_file.get('download_url')
  623. if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
  624. source_name = source_file.get('public_name', 'Original')
  625. if self._is_valid_url(download_url, video_id, '%s video' % source_name):
  626. ext = (try_get(
  627. source_file, lambda x: x['extension'],
  628. compat_str) or determine_ext(
  629. download_url, None) or 'mp4').lower()
  630. formats.append({
  631. 'url': download_url,
  632. 'ext': ext,
  633. 'width': int_or_none(source_file.get('width')),
  634. 'height': int_or_none(source_file.get('height')),
  635. 'filesize': parse_filesize(source_file.get('size')),
  636. 'format_id': source_name,
  637. 'preference': 1,
  638. })
  639. info_dict_config = self._parse_config(config, video_id)
  640. formats.extend(info_dict_config['formats'])
  641. self._vimeo_sort_formats(formats)
  642. json_ld = self._search_json_ld(webpage, video_id, default={})
  643. if not cc_license:
  644. cc_license = self._search_regex(
  645. r'<link[^>]+rel=["\']license["\'][^>]+href=(["\'])(?P<license>(?:(?!\1).)+)\1',
  646. webpage, 'license', default=None, group='license')
  647. channel_url = 'https://vimeo.com/channels/%s' % channel_id if channel_id else None
  648. info_dict = {
  649. 'id': video_id,
  650. 'formats': formats,
  651. 'timestamp': unified_timestamp(timestamp),
  652. 'description': video_description,
  653. 'webpage_url': url,
  654. 'view_count': view_count,
  655. 'like_count': like_count,
  656. 'comment_count': comment_count,
  657. 'license': cc_license,
  658. 'channel_id': channel_id,
  659. 'channel_url': channel_url,
  660. }
  661. info_dict = merge_dicts(info_dict, info_dict_config, json_ld)
  662. return info_dict
  663. class VimeoOndemandIE(VimeoBaseInfoExtractor):
  664. IE_NAME = 'vimeo:ondemand'
  665. _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?P<id>[^/?#&]+)'
  666. _TESTS = [{
  667. # ondemand video not available via https://vimeo.com/id
  668. 'url': 'https://vimeo.com/ondemand/20704',
  669. 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35',
  670. 'info_dict': {
  671. 'id': '105442900',
  672. 'ext': 'mp4',
  673. 'title': 'המעבדה - במאי יותם פלדמן',
  674. 'uploader': 'גם סרטים',
  675. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/gumfilms',
  676. 'uploader_id': 'gumfilms',
  677. },
  678. 'params': {
  679. 'format': 'best[protocol=https]',
  680. },
  681. }, {
  682. # requires Referer to be passed along with og:video:url
  683. 'url': 'https://vimeo.com/ondemand/36938/126682985',
  684. 'info_dict': {
  685. 'id': '126682985',
  686. 'ext': 'mp4',
  687. 'title': 'Rävlock, rätt läte på rätt plats',
  688. 'uploader': 'Lindroth & Norin',
  689. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user14430847',
  690. 'uploader_id': 'user14430847',
  691. },
  692. 'params': {
  693. 'skip_download': True,
  694. },
  695. }, {
  696. 'url': 'https://vimeo.com/ondemand/nazmaalik',
  697. 'only_matching': True,
  698. }, {
  699. 'url': 'https://vimeo.com/ondemand/141692381',
  700. 'only_matching': True,
  701. }, {
  702. 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832',
  703. 'only_matching': True,
  704. }]
  705. def _real_extract(self, url):
  706. video_id = self._match_id(url)
  707. webpage = self._download_webpage(url, video_id)
  708. return self.url_result(
  709. # Some videos require Referer to be passed along with og:video:url
  710. # similarly to generic vimeo embeds (e.g.
  711. # https://vimeo.com/ondemand/36938/126682985).
  712. VimeoIE._smuggle_referrer(self._og_search_video_url(webpage), url),
  713. VimeoIE.ie_key())
  714. class VimeoChannelIE(VimeoBaseInfoExtractor):
  715. IE_NAME = 'vimeo:channel'
  716. _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
  717. _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
  718. _TITLE = None
  719. _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
  720. _TESTS = [{
  721. 'url': 'https://vimeo.com/channels/tributes',
  722. 'info_dict': {
  723. 'id': 'tributes',
  724. 'title': 'Vimeo Tributes',
  725. },
  726. 'playlist_mincount': 25,
  727. }]
  728. def _page_url(self, base_url, pagenum):
  729. return '%s/videos/page:%d/' % (base_url, pagenum)
  730. def _extract_list_title(self, webpage):
  731. return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
  732. def _login_list_password(self, page_url, list_id, webpage):
  733. login_form = self._search_regex(
  734. r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
  735. webpage, 'login form', default=None)
  736. if not login_form:
  737. return webpage
  738. password = self._downloader.params.get('videopassword')
  739. if password is None:
  740. raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
  741. fields = self._hidden_inputs(login_form)
  742. token, vuid = self._extract_xsrft_and_vuid(webpage)
  743. fields['token'] = token
  744. fields['password'] = password
  745. post = urlencode_postdata(fields)
  746. password_path = self._search_regex(
  747. r'action="([^"]+)"', login_form, 'password URL')
  748. password_url = compat_urlparse.urljoin(page_url, password_path)
  749. password_request = sanitized_Request(password_url, post)
  750. password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
  751. self._set_vimeo_cookie('vuid', vuid)
  752. self._set_vimeo_cookie('xsrft', token)
  753. return self._download_webpage(
  754. password_request, list_id,
  755. 'Verifying the password', 'Wrong password')
  756. def _title_and_entries(self, list_id, base_url):
  757. for pagenum in itertools.count(1):
  758. page_url = self._page_url(base_url, pagenum)
  759. webpage = self._download_webpage(
  760. page_url, list_id,
  761. 'Downloading page %s' % pagenum)
  762. if pagenum == 1:
  763. webpage = self._login_list_password(page_url, list_id, webpage)
  764. yield self._extract_list_title(webpage)
  765. # Try extracting href first since not all videos are available via
  766. # short https://vimeo.com/id URL (e.g. https://vimeo.com/channels/tributes/6213729)
  767. clips = re.findall(
  768. r'id="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)(?:[^>]+\btitle="([^"]+)")?', webpage)
  769. if clips:
  770. for video_id, video_url, video_title in clips:
  771. yield self.url_result(
  772. compat_urlparse.urljoin(base_url, video_url),
  773. VimeoIE.ie_key(), video_id=video_id, video_title=video_title)
  774. # More relaxed fallback
  775. else:
  776. for video_id in re.findall(r'id=["\']clip_(\d+)', webpage):
  777. yield self.url_result(
  778. 'https://vimeo.com/%s' % video_id,
  779. VimeoIE.ie_key(), video_id=video_id)
  780. if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
  781. break
  782. def _extract_videos(self, list_id, base_url):
  783. title_and_entries = self._title_and_entries(list_id, base_url)
  784. list_title = next(title_and_entries)
  785. return self.playlist_result(title_and_entries, list_id, list_title)
  786. def _real_extract(self, url):
  787. mobj = re.match(self._VALID_URL, url)
  788. channel_id = mobj.group('id')
  789. return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
  790. class VimeoUserIE(VimeoChannelIE):
  791. IE_NAME = 'vimeo:user'
  792. _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
  793. _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
  794. _TESTS = [{
  795. 'url': 'https://vimeo.com/nkistudio/videos',
  796. 'info_dict': {
  797. 'title': 'Nki',
  798. 'id': 'nkistudio',
  799. },
  800. 'playlist_mincount': 66,
  801. }]
  802. def _real_extract(self, url):
  803. mobj = re.match(self._VALID_URL, url)
  804. name = mobj.group('name')
  805. return self._extract_videos(name, 'https://vimeo.com/%s' % name)
  806. class VimeoAlbumIE(VimeoChannelIE):
  807. IE_NAME = 'vimeo:album'
  808. _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)(?:$|[?#]|/(?!video))'
  809. _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
  810. _TESTS = [{
  811. 'url': 'https://vimeo.com/album/2632481',
  812. 'info_dict': {
  813. 'id': '2632481',
  814. 'title': 'Staff Favorites: November 2013',
  815. },
  816. 'playlist_mincount': 13,
  817. }, {
  818. 'note': 'Password-protected album',
  819. 'url': 'https://vimeo.com/album/3253534',
  820. 'info_dict': {
  821. 'title': 'test',
  822. 'id': '3253534',
  823. },
  824. 'playlist_count': 1,
  825. 'params': {
  826. 'videopassword': 'youtube-dl',
  827. }
  828. }, {
  829. 'url': 'https://vimeo.com/album/2632481/sort:plays/format:thumbnail',
  830. 'only_matching': True,
  831. }, {
  832. # TODO: respect page number
  833. 'url': 'https://vimeo.com/album/2632481/page:2/sort:plays/format:thumbnail',
  834. 'only_matching': True,
  835. }]
  836. def _page_url(self, base_url, pagenum):
  837. return '%s/page:%d/' % (base_url, pagenum)
  838. def _real_extract(self, url):
  839. album_id = self._match_id(url)
  840. return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
  841. class VimeoGroupsIE(VimeoAlbumIE):
  842. IE_NAME = 'vimeo:group'
  843. _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
  844. _TESTS = [{
  845. 'url': 'https://vimeo.com/groups/rolexawards',
  846. 'info_dict': {
  847. 'id': 'rolexawards',
  848. 'title': 'Rolex Awards for Enterprise',
  849. },
  850. 'playlist_mincount': 73,
  851. }]
  852. def _extract_list_title(self, webpage):
  853. return self._og_search_title(webpage)
  854. def _real_extract(self, url):
  855. mobj = re.match(self._VALID_URL, url)
  856. name = mobj.group('name')
  857. return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
  858. class VimeoReviewIE(VimeoBaseInfoExtractor):
  859. IE_NAME = 'vimeo:review'
  860. IE_DESC = 'Review pages on vimeo'
  861. _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
  862. _TESTS = [{
  863. 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
  864. 'md5': 'c507a72f780cacc12b2248bb4006d253',
  865. 'info_dict': {
  866. 'id': '75524534',
  867. 'ext': 'mp4',
  868. 'title': "DICK HARDWICK 'Comedian'",
  869. 'uploader': 'Richard Hardwick',
  870. 'uploader_id': 'user21297594',
  871. }
  872. }, {
  873. 'note': 'video player needs Referer',
  874. 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
  875. 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
  876. 'info_dict': {
  877. 'id': '91613211',
  878. 'ext': 'mp4',
  879. 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
  880. 'uploader': 'DevWeek Events',
  881. 'duration': 2773,
  882. 'thumbnail': r're:^https?://.*\.jpg$',
  883. 'uploader_id': 'user22258446',
  884. }
  885. }, {
  886. 'note': 'Password protected',
  887. 'url': 'https://vimeo.com/user37284429/review/138823582/c4d865efde',
  888. 'info_dict': {
  889. 'id': '138823582',
  890. 'ext': 'mp4',
  891. 'title': 'EFFICIENT PICKUP MASTERCLASS MODULE 1',
  892. 'uploader': 'TMB',
  893. 'uploader_id': 'user37284429',
  894. },
  895. 'params': {
  896. 'videopassword': 'holygrail',
  897. },
  898. 'skip': 'video gone',
  899. }]
  900. def _real_initialize(self):
  901. self._login()
  902. def _get_config_url(self, webpage_url, video_id, video_password_verified=False):
  903. webpage = self._download_webpage(webpage_url, video_id)
  904. config_url = self._html_search_regex(
  905. r'data-config-url=(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  906. 'config URL', default=None, group='url')
  907. if not config_url:
  908. data = self._parse_json(self._search_regex(
  909. r'window\s*=\s*_extend\(window,\s*({.+?})\);', webpage, 'data',
  910. default=NO_DEFAULT if video_password_verified else '{}'), video_id)
  911. config_url = data.get('vimeo_esi', {}).get('config', {}).get('configUrl')
  912. if config_url is None:
  913. self._verify_video_password(webpage_url, video_id, webpage)
  914. config_url = self._get_config_url(
  915. webpage_url, video_id, video_password_verified=True)
  916. return config_url
  917. def _real_extract(self, url):
  918. video_id = self._match_id(url)
  919. config_url = self._get_config_url(url, video_id)
  920. config = self._download_json(config_url, video_id)
  921. info_dict = self._parse_config(config, video_id)
  922. self._vimeo_sort_formats(info_dict['formats'])
  923. info_dict['id'] = video_id
  924. return info_dict
  925. class VimeoWatchLaterIE(VimeoChannelIE):
  926. IE_NAME = 'vimeo:watchlater'
  927. IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
  928. _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
  929. _TITLE = 'Watch Later'
  930. _LOGIN_REQUIRED = True
  931. _TESTS = [{
  932. 'url': 'https://vimeo.com/watchlater',
  933. 'only_matching': True,
  934. }]
  935. def _real_initialize(self):
  936. self._login()
  937. def _page_url(self, base_url, pagenum):
  938. url = '%s/page:%d/' % (base_url, pagenum)
  939. request = sanitized_Request(url)
  940. # Set the header to get a partial html page with the ids,
  941. # the normal page doesn't contain them.
  942. request.add_header('X-Requested-With', 'XMLHttpRequest')
  943. return request
  944. def _real_extract(self, url):
  945. return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
  946. class VimeoLikesIE(InfoExtractor):
  947. _VALID_URL = r'https://(?:www\.)?vimeo\.com/(?P<id>[^/]+)/likes/?(?:$|[?#]|sort:)'
  948. IE_NAME = 'vimeo:likes'
  949. IE_DESC = 'Vimeo user likes'
  950. _TESTS = [{
  951. 'url': 'https://vimeo.com/user755559/likes/',
  952. 'playlist_mincount': 293,
  953. 'info_dict': {
  954. 'id': 'user755559_likes',
  955. 'description': 'See all the videos urza likes',
  956. 'title': 'Videos urza likes',
  957. },
  958. }, {
  959. 'url': 'https://vimeo.com/stormlapse/likes',
  960. 'only_matching': True,
  961. }]
  962. def _real_extract(self, url):
  963. user_id = self._match_id(url)
  964. webpage = self._download_webpage(url, user_id)
  965. page_count = self._int(
  966. self._search_regex(
  967. r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
  968. .*?</a></li>\s*<li\s+class="pagination_next">
  969. ''', webpage, 'page count', default=1),
  970. 'page count', fatal=True)
  971. PAGE_SIZE = 12
  972. title = self._html_search_regex(
  973. r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
  974. description = self._html_search_meta('description', webpage)
  975. def _get_page(idx):
  976. page_url = 'https://vimeo.com/%s/likes/page:%d/sort:date' % (
  977. user_id, idx + 1)
  978. webpage = self._download_webpage(
  979. page_url, user_id,
  980. note='Downloading page %d/%d' % (idx + 1, page_count))
  981. video_list = self._search_regex(
  982. r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
  983. webpage, 'video content')
  984. paths = re.findall(
  985. r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
  986. for path in paths:
  987. yield {
  988. '_type': 'url',
  989. 'url': compat_urlparse.urljoin(page_url, path),
  990. }
  991. pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
  992. return {
  993. '_type': 'playlist',
  994. 'id': '%s_likes' % user_id,
  995. 'title': title,
  996. 'description': description,
  997. 'entries': pl,
  998. }
  999. class VHXEmbedIE(InfoExtractor):
  1000. IE_NAME = 'vhx:embed'
  1001. _VALID_URL = r'https?://embed\.vhx\.tv/videos/(?P<id>\d+)'
  1002. def _call_api(self, video_id, access_token, path='', query=None):
  1003. return self._download_json(
  1004. 'https://api.vhx.tv/videos/' + video_id + path, video_id, headers={
  1005. 'Authorization': 'Bearer ' + access_token,
  1006. }, query=query)
  1007. def _real_extract(self, url):
  1008. video_id = self._match_id(url)
  1009. webpage = self._download_webpage(url, video_id)
  1010. credentials = self._parse_json(self._search_regex(
  1011. r'(?s)credentials\s*:\s*({.+?}),', webpage,
  1012. 'config'), video_id, js_to_json)
  1013. access_token = credentials['access_token']
  1014. query = {}
  1015. for k, v in credentials.items():
  1016. if k in ('authorization', 'authUserToken', 'ticket') and v and v != 'undefined':
  1017. if k == 'authUserToken':
  1018. query['auth_user_token'] = v
  1019. else:
  1020. query[k] = v
  1021. files = self._call_api(video_id, access_token, '/files', query)
  1022. formats = []
  1023. for f in files:
  1024. href = try_get(f, lambda x: x['_links']['source']['href'])
  1025. if not href:
  1026. continue
  1027. method = f.get('method')
  1028. if method == 'hls':
  1029. formats.extend(self._extract_m3u8_formats(
  1030. href, video_id, 'mp4', 'm3u8_native',
  1031. m3u8_id='hls', fatal=False))
  1032. elif method == 'dash':
  1033. formats.extend(self._extract_mpd_formats(
  1034. href, video_id, mpd_id='dash', fatal=False))
  1035. else:
  1036. fmt = {
  1037. 'filesize': int_or_none(try_get(f, lambda x: x['size']['bytes'])),
  1038. 'format_id': 'http',
  1039. 'preference': 1,
  1040. 'url': href,
  1041. 'vcodec': f.get('codec'),
  1042. }
  1043. quality = f.get('quality')
  1044. if quality:
  1045. fmt.update({
  1046. 'format_id': 'http-' + quality,
  1047. 'height': int_or_none(self._search_regex(r'(\d+)p', quality, 'height', default=None)),
  1048. })
  1049. formats.append(fmt)
  1050. self._sort_formats(formats)
  1051. video_data = self._call_api(video_id, access_token)
  1052. title = video_data.get('title') or video_data['name']
  1053. subtitles = {}
  1054. for subtitle in try_get(video_data, lambda x: x['tracks']['subtitles'], list) or []:
  1055. lang = subtitle.get('srclang') or subtitle.get('label')
  1056. for _link in subtitle.get('_links', {}).values():
  1057. href = _link.get('href')
  1058. if not href:
  1059. continue
  1060. subtitles.setdefault(lang, []).append({
  1061. 'url': href,
  1062. })
  1063. q = qualities(['small', 'medium', 'large', 'source'])
  1064. thumbnails = []
  1065. for thumbnail_id, thumbnail_url in video_data.get('thumbnail', {}).items():
  1066. thumbnails.append({
  1067. 'id': thumbnail_id,
  1068. 'url': thumbnail_url,
  1069. 'preference': q(thumbnail_id),
  1070. })
  1071. return {
  1072. 'id': video_id,
  1073. 'title': title,
  1074. 'description': video_data.get('description'),
  1075. 'duration': int_or_none(try_get(video_data, lambda x: x['duration']['seconds'])),
  1076. 'formats': formats,
  1077. 'subtitles': subtitles,
  1078. 'thumbnails': thumbnails,
  1079. 'timestamp': unified_timestamp(video_data.get('created_at')),
  1080. 'view_count': int_or_none(video_data.get('plays_count')),
  1081. }