vimeo.py 49 KB

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