vimeo.py 46 KB

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