vimeo.py 49 KB

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