vimeo.py 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  1. import base64
  2. import functools
  3. import re
  4. import itertools
  5. import urllib.error
  6. from .common import InfoExtractor
  7. from ..compat import (
  8. compat_HTTPError,
  9. compat_str,
  10. compat_urlparse,
  11. )
  12. from ..utils import (
  13. clean_html,
  14. determine_ext,
  15. ExtractorError,
  16. get_element_by_class,
  17. HEADRequest,
  18. js_to_json,
  19. int_or_none,
  20. merge_dicts,
  21. OnDemandPagedList,
  22. parse_filesize,
  23. parse_iso8601,
  24. parse_qs,
  25. sanitized_Request,
  26. smuggle_url,
  27. str_or_none,
  28. try_get,
  29. unified_timestamp,
  30. unsmuggle_url,
  31. urlencode_postdata,
  32. urljoin,
  33. urlhandle_detect_ext,
  34. )
  35. class VimeoBaseInfoExtractor(InfoExtractor):
  36. _NETRC_MACHINE = 'vimeo'
  37. _LOGIN_REQUIRED = False
  38. _LOGIN_URL = 'https://vimeo.com/log_in'
  39. @staticmethod
  40. def _smuggle_referrer(url, referrer_url):
  41. return smuggle_url(url, {'http_headers': {'Referer': referrer_url}})
  42. def _unsmuggle_headers(self, url):
  43. """@returns (url, smuggled_data, headers)"""
  44. url, data = unsmuggle_url(url, {})
  45. headers = self.get_param('http_headers').copy()
  46. if 'http_headers' in data:
  47. headers.update(data['http_headers'])
  48. return url, data, headers
  49. def _perform_login(self, username, password):
  50. webpage = self._download_webpage(
  51. self._LOGIN_URL, None, 'Downloading login page')
  52. token, vuid = self._extract_xsrft_and_vuid(webpage)
  53. data = {
  54. 'action': 'login',
  55. 'email': username,
  56. 'password': password,
  57. 'service': 'vimeo',
  58. 'token': token,
  59. }
  60. self._set_vimeo_cookie('vuid', vuid)
  61. try:
  62. self._download_webpage(
  63. self._LOGIN_URL, None, 'Logging in',
  64. data=urlencode_postdata(data), headers={
  65. 'Content-Type': 'application/x-www-form-urlencoded',
  66. 'Referer': self._LOGIN_URL,
  67. })
  68. except ExtractorError as e:
  69. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 418:
  70. raise ExtractorError(
  71. 'Unable to log in: bad username or password',
  72. expected=True)
  73. raise ExtractorError('Unable to log in')
  74. def _real_initialize(self):
  75. if self._LOGIN_REQUIRED and not self._get_cookies('https://vimeo.com').get('vuid'):
  76. self._raise_login_required()
  77. def _get_video_password(self):
  78. password = self.get_param('videopassword')
  79. if password is None:
  80. raise ExtractorError(
  81. 'This video is protected by a password, use the --video-password option',
  82. expected=True)
  83. return password
  84. def _verify_video_password(self, url, video_id, password, token, vuid):
  85. if url.startswith('http://'):
  86. # vimeo only supports https now, but the user can give an http url
  87. url = url.replace('http://', 'https://')
  88. self._set_vimeo_cookie('vuid', vuid)
  89. return self._download_webpage(
  90. url + '/password', video_id, 'Verifying the password',
  91. 'Wrong password', data=urlencode_postdata({
  92. 'password': password,
  93. 'token': token,
  94. }), headers={
  95. 'Content-Type': 'application/x-www-form-urlencoded',
  96. 'Referer': url,
  97. })
  98. def _extract_xsrft_and_vuid(self, webpage):
  99. xsrft = self._search_regex(
  100. r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
  101. webpage, 'login token', group='xsrft')
  102. vuid = self._search_regex(
  103. r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
  104. webpage, 'vuid', group='vuid')
  105. return xsrft, vuid
  106. def _extract_vimeo_config(self, webpage, video_id, *args, **kwargs):
  107. vimeo_config = self._search_regex(
  108. r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));',
  109. webpage, 'vimeo config', *args, **kwargs)
  110. if vimeo_config:
  111. return self._parse_json(vimeo_config, video_id)
  112. def _set_vimeo_cookie(self, name, value):
  113. self._set_cookie('vimeo.com', name, value)
  114. def _parse_config(self, config, video_id):
  115. video_data = config['video']
  116. video_title = video_data.get('title')
  117. live_event = video_data.get('live_event') or {}
  118. is_live = live_event.get('status') == 'started'
  119. request = config.get('request') or {}
  120. formats = []
  121. subtitles = {}
  122. config_files = video_data.get('files') or request.get('files') or {}
  123. for f in (config_files.get('progressive') or []):
  124. video_url = f.get('url')
  125. if not video_url:
  126. continue
  127. formats.append({
  128. 'url': video_url,
  129. 'format_id': 'http-%s' % f.get('quality'),
  130. 'source_preference': 10,
  131. 'width': int_or_none(f.get('width')),
  132. 'height': int_or_none(f.get('height')),
  133. 'fps': int_or_none(f.get('fps')),
  134. 'tbr': int_or_none(f.get('bitrate')),
  135. })
  136. # TODO: fix handling of 308 status code returned for live archive manifest requests
  137. sep_pattern = r'/sep/video/'
  138. for files_type in ('hls', 'dash'):
  139. for cdn_name, cdn_data in (try_get(config_files, lambda x: x[files_type]['cdns']) or {}).items():
  140. manifest_url = cdn_data.get('url')
  141. if not manifest_url:
  142. continue
  143. format_id = '%s-%s' % (files_type, cdn_name)
  144. sep_manifest_urls = []
  145. if re.search(sep_pattern, manifest_url):
  146. for suffix, repl in (('', 'video'), ('_sep', 'sep/video')):
  147. sep_manifest_urls.append((format_id + suffix, re.sub(
  148. sep_pattern, '/%s/' % repl, manifest_url)))
  149. else:
  150. sep_manifest_urls = [(format_id, manifest_url)]
  151. for f_id, m_url in sep_manifest_urls:
  152. if files_type == 'hls':
  153. fmts, subs = self._extract_m3u8_formats_and_subtitles(
  154. m_url, video_id, 'mp4', live=is_live, m3u8_id=f_id,
  155. note='Downloading %s m3u8 information' % cdn_name,
  156. fatal=False)
  157. formats.extend(fmts)
  158. self._merge_subtitles(subs, target=subtitles)
  159. elif files_type == 'dash':
  160. if 'json=1' in m_url:
  161. real_m_url = (self._download_json(m_url, video_id, fatal=False) or {}).get('url')
  162. if real_m_url:
  163. m_url = real_m_url
  164. fmts, subs = self._extract_mpd_formats_and_subtitles(
  165. m_url.replace('/master.json', '/master.mpd'), video_id, f_id,
  166. 'Downloading %s MPD information' % cdn_name,
  167. fatal=False)
  168. formats.extend(fmts)
  169. self._merge_subtitles(subs, target=subtitles)
  170. live_archive = live_event.get('archive') or {}
  171. live_archive_source_url = live_archive.get('source_url')
  172. if live_archive_source_url and live_archive.get('status') == 'done':
  173. formats.append({
  174. 'format_id': 'live-archive-source',
  175. 'url': live_archive_source_url,
  176. 'quality': 10,
  177. })
  178. for tt in (request.get('text_tracks') or []):
  179. subtitles.setdefault(tt['lang'], []).append({
  180. 'ext': 'vtt',
  181. 'url': urljoin('https://vimeo.com', tt['url']),
  182. })
  183. thumbnails = []
  184. if not is_live:
  185. for key, thumb in (video_data.get('thumbs') or {}).items():
  186. thumbnails.append({
  187. 'id': key,
  188. 'width': int_or_none(key),
  189. 'url': thumb,
  190. })
  191. thumbnail = video_data.get('thumbnail')
  192. if thumbnail:
  193. thumbnails.append({
  194. 'url': thumbnail,
  195. })
  196. owner = video_data.get('owner') or {}
  197. video_uploader_url = owner.get('url')
  198. duration = int_or_none(video_data.get('duration'))
  199. chapter_data = try_get(config, lambda x: x['embed']['chapters']) or []
  200. chapters = [{
  201. 'title': current_chapter.get('title'),
  202. 'start_time': current_chapter.get('timecode'),
  203. 'end_time': next_chapter.get('timecode'),
  204. } for current_chapter, next_chapter in zip(chapter_data, chapter_data[1:] + [{'timecode': duration}])]
  205. if chapters and chapters[0]['start_time']: # Chapters may not start from 0
  206. chapters[:0] = [{'title': '<Untitled>', 'start_time': 0, 'end_time': chapters[0]['start_time']}]
  207. return {
  208. 'id': str_or_none(video_data.get('id')) or video_id,
  209. 'title': video_title,
  210. 'uploader': owner.get('name'),
  211. 'uploader_id': video_uploader_url.split('/')[-1] if video_uploader_url else None,
  212. 'uploader_url': video_uploader_url,
  213. 'thumbnails': thumbnails,
  214. 'duration': duration,
  215. 'chapters': chapters or None,
  216. 'formats': formats,
  217. 'subtitles': subtitles,
  218. 'is_live': is_live,
  219. # Note: Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
  220. # at the same time without actual units specified.
  221. '_format_sort_fields': ('quality', 'res', 'fps', 'hdr:12', 'source'),
  222. }
  223. def _extract_original_format(self, url, video_id, unlisted_hash=None):
  224. query = {'action': 'load_download_config'}
  225. if unlisted_hash:
  226. query['unlisted_hash'] = unlisted_hash
  227. download_data = self._download_json(
  228. url, video_id, fatal=False, query=query,
  229. headers={'X-Requested-With': 'XMLHttpRequest'},
  230. expected_status=(403, 404)) or {}
  231. source_file = download_data.get('source_file')
  232. download_url = try_get(source_file, lambda x: x['download_url'])
  233. if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
  234. source_name = source_file.get('public_name', 'Original')
  235. if self._is_valid_url(download_url, video_id, '%s video' % source_name):
  236. ext = (try_get(
  237. source_file, lambda x: x['extension'],
  238. compat_str) or determine_ext(
  239. download_url, None) or 'mp4').lower()
  240. return {
  241. 'url': download_url,
  242. 'ext': ext,
  243. 'width': int_or_none(source_file.get('width')),
  244. 'height': int_or_none(source_file.get('height')),
  245. 'filesize': parse_filesize(source_file.get('size')),
  246. 'format_id': source_name,
  247. 'quality': 1,
  248. }
  249. jwt_response = self._download_json(
  250. 'https://vimeo.com/_rv/viewer', video_id, note='Downloading jwt token', fatal=False) or {}
  251. if not jwt_response.get('jwt'):
  252. return
  253. headers = {'Authorization': 'jwt %s' % jwt_response['jwt']}
  254. original_response = self._download_json(
  255. f'https://api.vimeo.com/videos/{video_id}', video_id,
  256. headers=headers, fatal=False, expected_status=(403, 404)) or {}
  257. for download_data in original_response.get('download') or []:
  258. download_url = download_data.get('link')
  259. if not download_url or download_data.get('quality') != 'source':
  260. continue
  261. ext = determine_ext(parse_qs(download_url).get('filename', [''])[0].lower(), default_ext=None)
  262. if not ext:
  263. urlh = self._request_webpage(
  264. HEADRequest(download_url), video_id, fatal=False, note='Determining source extension')
  265. ext = urlh and urlhandle_detect_ext(urlh)
  266. return {
  267. 'url': download_url,
  268. 'ext': ext or 'unknown_video',
  269. 'format_id': download_data.get('public_name', 'Original'),
  270. 'width': int_or_none(download_data.get('width')),
  271. 'height': int_or_none(download_data.get('height')),
  272. 'fps': int_or_none(download_data.get('fps')),
  273. 'filesize': int_or_none(download_data.get('size')),
  274. 'quality': 1,
  275. }
  276. class VimeoIE(VimeoBaseInfoExtractor):
  277. """Information extractor for vimeo.com."""
  278. # _VALID_URL matches Vimeo URLs
  279. _VALID_URL = r'''(?x)
  280. https?://
  281. (?:
  282. (?:
  283. www|
  284. player
  285. )
  286. \.
  287. )?
  288. vimeo\.com/
  289. (?!(?:channels|album|showcase)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/)
  290. (?:[^/]+/)*?
  291. (?:
  292. (?:
  293. play_redirect_hls|
  294. moogaloop\.swf)\?clip_id=
  295. )?
  296. (?:videos?/)?
  297. (?P<id>[0-9]+)
  298. (?:/(?P<unlisted_hash>[\da-f]{10}))?
  299. /?(?:[?&].*)?(?:[#].*)?$
  300. '''
  301. IE_NAME = 'vimeo'
  302. _EMBED_REGEX = [
  303. # iframe
  304. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/\d+.*?)\1',
  305. # Embedded (swf embed) Vimeo player
  306. r'<embed[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)\1',
  307. # Non-standard embedded Vimeo player
  308. r'<video[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)\1',
  309. ]
  310. _TESTS = [
  311. {
  312. 'url': 'http://vimeo.com/56015672#at=0',
  313. 'md5': '8879b6cc097e987f02484baf890129e5',
  314. 'info_dict': {
  315. 'id': '56015672',
  316. 'ext': 'mp4',
  317. 'title': "youtube-dl test video '' ä↭𝕐-BaW jenozKc",
  318. 'description': 'md5:2d3305bad981a06ff79f027f19865021',
  319. 'timestamp': 1355990239,
  320. 'upload_date': '20121220',
  321. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user7108434',
  322. 'uploader_id': 'user7108434',
  323. 'uploader': 'Filippo Valsorda',
  324. 'duration': 10,
  325. 'license': 'by-sa',
  326. },
  327. 'params': {
  328. 'format': 'best[protocol=https]',
  329. },
  330. 'skip': 'No longer available'
  331. },
  332. {
  333. 'url': 'http://player.vimeo.com/video/54469442',
  334. 'md5': 'b3e7f4d2cbb53bd7dc3bb6ff4ed5cfbd',
  335. 'note': 'Videos that embed the url in the player page',
  336. 'info_dict': {
  337. 'id': '54469442',
  338. 'ext': 'mp4',
  339. 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
  340. 'uploader': 'Business of Software',
  341. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/businessofsoftware',
  342. 'uploader_id': 'businessofsoftware',
  343. 'duration': 3610,
  344. 'description': None,
  345. 'thumbnail': 'https://i.vimeocdn.com/video/376682406-f34043e7b766af6bef2af81366eacd6724f3fc3173179a11a97a1e26587c9529-d_1280',
  346. },
  347. 'params': {
  348. 'format': 'best[protocol=https]',
  349. },
  350. },
  351. {
  352. 'url': 'http://vimeo.com/68375962',
  353. 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
  354. 'note': 'Video protected with password',
  355. 'info_dict': {
  356. 'id': '68375962',
  357. 'ext': 'mp4',
  358. 'title': 'youtube-dl password protected test video',
  359. 'timestamp': 1371200155,
  360. 'upload_date': '20130614',
  361. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
  362. 'uploader_id': 'user18948128',
  363. 'uploader': 'Jaime Marquínez Ferrándiz',
  364. 'duration': 10,
  365. 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f',
  366. 'thumbnail': 'https://i.vimeocdn.com/video/440665496-b2c5aee2b61089442c794f64113a8e8f7d5763c3e6b3ebfaf696ae6413f8b1f4-d_960',
  367. 'view_count': int,
  368. 'comment_count': int,
  369. 'like_count': int,
  370. },
  371. 'params': {
  372. 'format': 'best[protocol=https]',
  373. 'videopassword': 'youtube-dl',
  374. },
  375. },
  376. {
  377. 'url': 'http://vimeo.com/channels/keypeele/75629013',
  378. 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
  379. 'info_dict': {
  380. 'id': '75629013',
  381. 'ext': 'mp4',
  382. 'title': 'Key & Peele: Terrorist Interrogation',
  383. 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
  384. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/atencio',
  385. 'uploader_id': 'atencio',
  386. 'uploader': 'Peter Atencio',
  387. 'channel_id': 'keypeele',
  388. 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/keypeele',
  389. 'timestamp': 1380339469,
  390. 'upload_date': '20130928',
  391. 'duration': 187,
  392. 'thumbnail': 'https://i.vimeocdn.com/video/450239872-a05512d9b1e55d707a7c04365c10980f327b06d966351bc403a5d5d65c95e572-d_1280',
  393. 'view_count': int,
  394. 'comment_count': int,
  395. 'like_count': int,
  396. },
  397. 'params': {'format': 'http-1080p'},
  398. },
  399. {
  400. 'url': 'http://vimeo.com/76979871',
  401. 'note': 'Video with subtitles',
  402. 'info_dict': {
  403. 'id': '76979871',
  404. 'ext': 'mov',
  405. 'title': 'The New Vimeo Player (You Know, For Videos)',
  406. 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
  407. 'timestamp': 1381846109,
  408. 'upload_date': '20131015',
  409. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/staff',
  410. 'uploader_id': 'staff',
  411. 'uploader': 'Vimeo Staff',
  412. 'duration': 62,
  413. 'subtitles': {
  414. 'de': [{'ext': 'vtt'}],
  415. 'en': [{'ext': 'vtt'}],
  416. 'es': [{'ext': 'vtt'}],
  417. 'fr': [{'ext': 'vtt'}],
  418. },
  419. },
  420. 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest'],
  421. },
  422. {
  423. # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
  424. 'url': 'https://player.vimeo.com/video/98044508',
  425. 'note': 'The js code contains assignments to the same variable as the config',
  426. 'info_dict': {
  427. 'id': '98044508',
  428. 'ext': 'mp4',
  429. 'title': 'Pier Solar OUYA Official Trailer',
  430. 'uploader': 'Tulio Gonçalves',
  431. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user28849593',
  432. 'uploader_id': 'user28849593',
  433. 'duration': 118,
  434. 'thumbnail': 'https://i.vimeocdn.com/video/478636036-c18440305ef3df9decfb6bf207a61fe39d2d17fa462a96f6f2d93d30492b037d-d_1280',
  435. },
  436. },
  437. {
  438. # contains original format
  439. 'url': 'https://vimeo.com/33951933',
  440. 'md5': '53c688fa95a55bf4b7293d37a89c5c53',
  441. 'info_dict': {
  442. 'id': '33951933',
  443. 'ext': 'mp4',
  444. 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute',
  445. 'uploader': 'The DMCI',
  446. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/dmci',
  447. 'uploader_id': 'dmci',
  448. 'timestamp': 1324343742,
  449. 'upload_date': '20111220',
  450. 'description': 'md5:ae23671e82d05415868f7ad1aec21147',
  451. 'duration': 60,
  452. 'comment_count': int,
  453. 'view_count': int,
  454. 'thumbnail': 'https://i.vimeocdn.com/video/231174622-dd07f015e9221ff529d451e1cc31c982b5d87bfafa48c4189b1da72824ee289a-d_1280',
  455. 'like_count': int,
  456. },
  457. },
  458. {
  459. 'note': 'Contains original format not accessible in webpage',
  460. 'url': 'https://vimeo.com/393756517',
  461. 'md5': 'c464af248b592190a5ffbb5d33f382b0',
  462. 'info_dict': {
  463. 'id': '393756517',
  464. 'ext': 'mov',
  465. 'timestamp': 1582642091,
  466. 'uploader_id': 'frameworkla',
  467. 'title': 'Straight To Hell - Sabrina: Netflix',
  468. 'uploader': 'Framework Studio',
  469. 'description': 'md5:f2edc61af3ea7a5592681ddbb683db73',
  470. 'upload_date': '20200225',
  471. 'duration': 176,
  472. 'thumbnail': 'https://i.vimeocdn.com/video/859377297-836494a4ef775e9d4edbace83937d9ad34dc846c688c0c419c0e87f7ab06c4b3-d_1280',
  473. 'uploader_url': 'https://vimeo.com/frameworkla',
  474. },
  475. },
  476. {
  477. # only available via https://vimeo.com/channels/tributes/6213729 and
  478. # not via https://vimeo.com/6213729
  479. 'url': 'https://vimeo.com/channels/tributes/6213729',
  480. 'info_dict': {
  481. 'id': '6213729',
  482. 'ext': 'mp4',
  483. 'title': 'Vimeo Tribute: The Shining',
  484. 'uploader': 'Casey Donahue',
  485. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/caseydonahue',
  486. 'uploader_id': 'caseydonahue',
  487. 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/tributes',
  488. 'channel_id': 'tributes',
  489. 'timestamp': 1250886430,
  490. 'upload_date': '20090821',
  491. 'description': 'md5:bdbf314014e58713e6e5b66eb252f4a6',
  492. 'duration': 321,
  493. 'comment_count': int,
  494. 'view_count': int,
  495. 'thumbnail': 'https://i.vimeocdn.com/video/22728298-bfc22146f930de7cf497821c7b0b9f168099201ecca39b00b6bd31fcedfca7a6-d_1280',
  496. 'like_count': int,
  497. },
  498. 'params': {
  499. 'skip_download': True,
  500. },
  501. },
  502. {
  503. # redirects to ondemand extractor and should be passed through it
  504. # for successful extraction
  505. 'url': 'https://vimeo.com/73445910',
  506. 'info_dict': {
  507. 'id': '73445910',
  508. 'ext': 'mp4',
  509. 'title': 'The Reluctant Revolutionary',
  510. 'uploader': '10Ft Films',
  511. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/tenfootfilms',
  512. 'uploader_id': 'tenfootfilms',
  513. 'description': 'md5:0fa704e05b04f91f40b7f3ca2e801384',
  514. 'upload_date': '20130830',
  515. 'timestamp': 1377853339,
  516. },
  517. 'params': {
  518. 'skip_download': True,
  519. },
  520. 'skip': 'this page is no longer available.',
  521. },
  522. {
  523. 'url': 'http://player.vimeo.com/video/68375962',
  524. 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
  525. 'info_dict': {
  526. 'id': '68375962',
  527. 'ext': 'mp4',
  528. 'title': 'youtube-dl password protected test video',
  529. 'timestamp': 1371200155,
  530. 'upload_date': '20130614',
  531. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
  532. 'uploader_id': 'user18948128',
  533. 'uploader': 'Jaime Marquínez Ferrándiz',
  534. 'duration': 10,
  535. 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f',
  536. 'thumbnail': 'https://i.vimeocdn.com/video/440665496-b2c5aee2b61089442c794f64113a8e8f7d5763c3e6b3ebfaf696ae6413f8b1f4-d_960',
  537. 'view_count': int,
  538. 'comment_count': int,
  539. 'like_count': int,
  540. },
  541. 'params': {
  542. 'format': 'best[protocol=https]',
  543. 'videopassword': 'youtube-dl',
  544. },
  545. },
  546. {
  547. 'url': 'http://vimeo.com/moogaloop.swf?clip_id=2539741',
  548. 'only_matching': True,
  549. },
  550. {
  551. 'url': 'https://vimeo.com/109815029',
  552. 'note': 'Video not completely processed, "failed" seed status',
  553. 'only_matching': True,
  554. },
  555. {
  556. 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
  557. 'only_matching': True,
  558. },
  559. {
  560. 'url': 'https://vimeo.com/album/2632481/video/79010983',
  561. 'only_matching': True,
  562. },
  563. {
  564. 'url': 'https://vimeo.com/showcase/3253534/video/119195465',
  565. 'note': 'A video in a password protected album (showcase)',
  566. 'info_dict': {
  567. 'id': '119195465',
  568. 'ext': 'mp4',
  569. 'title': "youtube-dl test video '' ä↭𝕐-BaW jenozKc",
  570. 'uploader': 'Philipp Hagemeister',
  571. 'uploader_id': 'user20132939',
  572. 'description': 'md5:fa7b6c6d8db0bdc353893df2f111855b',
  573. 'upload_date': '20150209',
  574. 'timestamp': 1423518307,
  575. 'thumbnail': 'https://i.vimeocdn.com/video/default_1280',
  576. 'duration': 10,
  577. 'like_count': int,
  578. 'uploader_url': 'https://vimeo.com/user20132939',
  579. 'view_count': int,
  580. 'comment_count': int,
  581. },
  582. 'params': {
  583. 'format': 'best[protocol=https]',
  584. 'videopassword': 'youtube-dl',
  585. },
  586. },
  587. {
  588. # source file returns 403: Forbidden
  589. 'url': 'https://vimeo.com/7809605',
  590. 'only_matching': True,
  591. },
  592. {
  593. 'note': 'Direct URL with hash',
  594. 'url': 'https://vimeo.com/160743502/abd0e13fb4',
  595. 'info_dict': {
  596. 'id': '160743502',
  597. 'ext': 'mp4',
  598. 'uploader': 'Julian Tryba',
  599. 'uploader_id': 'aliniamedia',
  600. 'title': 'Harrisville New Hampshire',
  601. 'timestamp': 1459259666,
  602. 'upload_date': '20160329',
  603. 'release_timestamp': 1459259666,
  604. 'license': 'by-nc',
  605. 'duration': 159,
  606. 'comment_count': int,
  607. 'thumbnail': 'https://i.vimeocdn.com/video/562802436-585eeb13b5020c6ac0f171a2234067938098f84737787df05ff0d767f6d54ee9-d_1280',
  608. 'like_count': int,
  609. 'uploader_url': 'https://vimeo.com/aliniamedia',
  610. 'release_date': '20160329',
  611. },
  612. 'params': {'skip_download': True},
  613. },
  614. {
  615. 'url': 'https://vimeo.com/138909882',
  616. 'info_dict': {
  617. 'id': '138909882',
  618. 'ext': 'mp4',
  619. 'title': 'Eastnor Castle 2015 Firework Champions - The Promo!',
  620. 'description': 'md5:5967e090768a831488f6e74b7821b3c1',
  621. 'uploader_id': 'fireworkchampions',
  622. 'uploader': 'Firework Champions',
  623. 'upload_date': '20150910',
  624. 'timestamp': 1441901895,
  625. },
  626. 'params': {
  627. 'skip_download': True,
  628. 'format': 'Original',
  629. },
  630. },
  631. {
  632. 'url': 'https://vimeo.com/channels/staffpicks/143603739',
  633. 'info_dict': {
  634. 'id': '143603739',
  635. 'ext': 'mp4',
  636. 'uploader': 'Karim Huu Do',
  637. 'timestamp': 1445846953,
  638. 'upload_date': '20151026',
  639. 'title': 'The Shoes - Submarine Feat. Blaine Harrison',
  640. 'uploader_id': 'karimhd',
  641. 'description': 'md5:8e2eea76de4504c2e8020a9bcfa1e843',
  642. 'channel_id': 'staffpicks',
  643. 'duration': 336,
  644. 'comment_count': int,
  645. 'view_count': int,
  646. 'thumbnail': 'https://i.vimeocdn.com/video/541243181-b593db36a16db2f0096f655da3f5a4dc46b8766d77b0f440df937ecb0c418347-d_1280',
  647. 'like_count': int,
  648. 'uploader_url': 'https://vimeo.com/karimhd',
  649. 'channel_url': 'https://vimeo.com/channels/staffpicks',
  650. },
  651. 'params': {'skip_download': 'm3u8'},
  652. },
  653. {
  654. # requires passing unlisted_hash(a52724358e) to load_download_config request
  655. 'url': 'https://vimeo.com/392479337/a52724358e',
  656. 'only_matching': True,
  657. },
  658. {
  659. # similar, but all numeric: ID must be 581039021, not 9603038895
  660. # issue #29690
  661. 'url': 'https://vimeo.com/581039021/9603038895',
  662. 'info_dict': {
  663. 'id': '581039021',
  664. 'ext': 'mp4',
  665. 'timestamp': 1627621014,
  666. 'release_timestamp': 1627621014,
  667. 'duration': 976,
  668. 'comment_count': int,
  669. 'thumbnail': 'https://i.vimeocdn.com/video/1202249320-4ddb2c30398c0dc0ee059172d1bd5ea481ad12f0e0e3ad01d2266f56c744b015-d_1280',
  670. 'like_count': int,
  671. 'uploader_url': 'https://vimeo.com/txwestcapital',
  672. 'release_date': '20210730',
  673. 'uploader': 'Christopher Inks',
  674. 'title': 'Thursday, July 29, 2021 BMA Evening Video Update',
  675. 'uploader_id': 'txwestcapital',
  676. 'upload_date': '20210730',
  677. },
  678. 'params': {
  679. 'skip_download': True,
  680. },
  681. }
  682. # https://gettingthingsdone.com/workflowmap/
  683. # vimeo embed with check-password page protected by Referer header
  684. ]
  685. @classmethod
  686. def _extract_embed_urls(cls, url, webpage):
  687. for embed_url in super()._extract_embed_urls(url, webpage):
  688. yield cls._smuggle_referrer(embed_url, url)
  689. @classmethod
  690. def _extract_url(cls, url, webpage):
  691. return next(cls._extract_embed_urls(url, webpage), None)
  692. def _verify_player_video_password(self, url, video_id, headers):
  693. password = self._get_video_password()
  694. data = urlencode_postdata({
  695. 'password': base64.b64encode(password.encode()),
  696. })
  697. headers = merge_dicts(headers, {
  698. 'Content-Type': 'application/x-www-form-urlencoded',
  699. })
  700. checked = self._download_json(
  701. f'{compat_urlparse.urlsplit(url)._replace(query=None).geturl()}/check-password',
  702. video_id, 'Verifying the password', data=data, headers=headers)
  703. if checked is False:
  704. raise ExtractorError('Wrong video password', expected=True)
  705. return checked
  706. def _extract_from_api(self, video_id, unlisted_hash=None):
  707. token = self._download_json(
  708. 'https://vimeo.com/_rv/jwt', video_id, headers={
  709. 'X-Requested-With': 'XMLHttpRequest'
  710. })['token']
  711. api_url = 'https://api.vimeo.com/videos/' + video_id
  712. if unlisted_hash:
  713. api_url += ':' + unlisted_hash
  714. video = self._download_json(
  715. api_url, video_id, headers={
  716. 'Authorization': 'jwt ' + token,
  717. }, query={
  718. 'fields': 'config_url,created_time,description,license,metadata.connections.comments.total,metadata.connections.likes.total,release_time,stats.plays',
  719. })
  720. info = self._parse_config(self._download_json(
  721. video['config_url'], video_id), video_id)
  722. get_timestamp = lambda x: parse_iso8601(video.get(x + '_time'))
  723. info.update({
  724. 'description': video.get('description'),
  725. 'license': video.get('license'),
  726. 'release_timestamp': get_timestamp('release'),
  727. 'timestamp': get_timestamp('created'),
  728. 'view_count': int_or_none(try_get(video, lambda x: x['stats']['plays'])),
  729. })
  730. connections = try_get(
  731. video, lambda x: x['metadata']['connections'], dict) or {}
  732. for k in ('comment', 'like'):
  733. info[k + '_count'] = int_or_none(try_get(connections, lambda x: x[k + 's']['total']))
  734. return info
  735. def _try_album_password(self, url):
  736. album_id = self._search_regex(
  737. r'vimeo\.com/(?:album|showcase)/([^/]+)', url, 'album id', default=None)
  738. if not album_id:
  739. return
  740. viewer = self._download_json(
  741. 'https://vimeo.com/_rv/viewer', album_id, fatal=False)
  742. if not viewer:
  743. webpage = self._download_webpage(url, album_id)
  744. viewer = self._parse_json(self._search_regex(
  745. r'bootstrap_data\s*=\s*({.+?})</script>',
  746. webpage, 'bootstrap data'), album_id)['viewer']
  747. jwt = viewer['jwt']
  748. album = self._download_json(
  749. 'https://api.vimeo.com/albums/' + album_id,
  750. album_id, headers={'Authorization': 'jwt ' + jwt},
  751. query={'fields': 'description,name,privacy'})
  752. if try_get(album, lambda x: x['privacy']['view']) == 'password':
  753. password = self.get_param('videopassword')
  754. if not password:
  755. raise ExtractorError(
  756. 'This album is protected by a password, use the --video-password option',
  757. expected=True)
  758. self._set_vimeo_cookie('vuid', viewer['vuid'])
  759. try:
  760. self._download_json(
  761. 'https://vimeo.com/showcase/%s/auth' % album_id,
  762. album_id, 'Verifying the password', data=urlencode_postdata({
  763. 'password': password,
  764. 'token': viewer['xsrft'],
  765. }), headers={
  766. 'X-Requested-With': 'XMLHttpRequest',
  767. })
  768. except ExtractorError as e:
  769. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
  770. raise ExtractorError('Wrong password', expected=True)
  771. raise
  772. def _real_extract(self, url):
  773. url, data, headers = self._unsmuggle_headers(url)
  774. if 'Referer' not in headers:
  775. headers['Referer'] = url
  776. # Extract ID from URL
  777. mobj = self._match_valid_url(url).groupdict()
  778. video_id, unlisted_hash = mobj['id'], mobj.get('unlisted_hash')
  779. if unlisted_hash:
  780. return self._extract_from_api(video_id, unlisted_hash)
  781. if any(p in url for p in ('play_redirect_hls', 'moogaloop.swf')):
  782. url = 'https://vimeo.com/' + video_id
  783. self._try_album_password(url)
  784. try:
  785. # Retrieve video webpage to extract further information
  786. webpage, urlh = self._download_webpage_handle(
  787. url, video_id, headers=headers)
  788. redirect_url = urlh.geturl()
  789. except ExtractorError as ee:
  790. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
  791. errmsg = ee.cause.read()
  792. if b'Because of its privacy settings, this video cannot be played here' in errmsg:
  793. raise ExtractorError(
  794. 'Cannot download embed-only video without embedding '
  795. 'URL. Please call hypervideo with the URL of the page '
  796. 'that embeds this video.',
  797. expected=True)
  798. raise
  799. if '://player.vimeo.com/video/' in url:
  800. config = self._parse_json(self._search_regex(
  801. r'\b(?:playerC|c)onfig\s*=\s*({.+?})\s*;', webpage, 'info section'), video_id)
  802. if config.get('view') == 4:
  803. config = self._verify_player_video_password(
  804. redirect_url, video_id, headers)
  805. return self._parse_config(config, video_id)
  806. if re.search(r'<form[^>]+?id="pw_form"', webpage):
  807. video_password = self._get_video_password()
  808. token, vuid = self._extract_xsrft_and_vuid(webpage)
  809. webpage = self._verify_video_password(
  810. redirect_url, video_id, video_password, token, vuid)
  811. vimeo_config = self._extract_vimeo_config(webpage, video_id, default=None)
  812. if vimeo_config:
  813. seed_status = vimeo_config.get('seed_status') or {}
  814. if seed_status.get('state') == 'failed':
  815. raise ExtractorError(
  816. '%s said: %s' % (self.IE_NAME, seed_status['title']),
  817. expected=True)
  818. cc_license = None
  819. timestamp = None
  820. video_description = None
  821. info_dict = {}
  822. config_url = None
  823. channel_id = self._search_regex(
  824. r'vimeo\.com/channels/([^/]+)', url, 'channel id', default=None)
  825. if channel_id:
  826. config_url = self._html_search_regex(
  827. r'\bdata-config-url="([^"]+)"', webpage, 'config URL', default=None)
  828. video_description = clean_html(get_element_by_class('description', webpage))
  829. info_dict.update({
  830. 'channel_id': channel_id,
  831. 'channel_url': 'https://vimeo.com/channels/' + channel_id,
  832. })
  833. if not config_url:
  834. page_config = self._parse_json(self._search_regex(
  835. r'vimeo\.(?:clip|vod_title)_page_config\s*=\s*({.+?});',
  836. webpage, 'page config', default='{}'), video_id, fatal=False)
  837. if not page_config:
  838. return self._extract_from_api(video_id)
  839. config_url = page_config['player']['config_url']
  840. cc_license = page_config.get('cc_license')
  841. clip = page_config.get('clip') or {}
  842. timestamp = clip.get('uploaded_on')
  843. video_description = clean_html(
  844. clip.get('description') or page_config.get('description_html_escaped'))
  845. config = self._download_json(config_url, video_id)
  846. video = config.get('video') or {}
  847. vod = video.get('vod') or {}
  848. def is_rented():
  849. if '>You rented this title.<' in webpage:
  850. return True
  851. if try_get(config, lambda x: x['user']['purchased']):
  852. return True
  853. for purchase_option in (vod.get('purchase_options') or []):
  854. if purchase_option.get('purchased'):
  855. return True
  856. label = purchase_option.get('label_string')
  857. if label and (label.startswith('You rented this') or label.endswith(' remaining')):
  858. return True
  859. return False
  860. if is_rented() and vod.get('is_trailer'):
  861. feature_id = vod.get('feature_id')
  862. if feature_id and not data.get('force_feature_id', False):
  863. return self.url_result(smuggle_url(
  864. 'https://player.vimeo.com/player/%s' % feature_id,
  865. {'force_feature_id': True}), 'Vimeo')
  866. if not video_description:
  867. video_description = self._html_search_regex(
  868. r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
  869. webpage, 'description', default=None)
  870. if not video_description:
  871. video_description = self._html_search_meta(
  872. ['description', 'og:description', 'twitter:description'],
  873. webpage, default=None)
  874. if not video_description:
  875. self.report_warning('Cannot find video description')
  876. if not timestamp:
  877. timestamp = self._search_regex(
  878. r'<time[^>]+datetime="([^"]+)"', webpage,
  879. 'timestamp', default=None)
  880. view_count = int_or_none(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count', default=None))
  881. like_count = int_or_none(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count', default=None))
  882. comment_count = int_or_none(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count', default=None))
  883. formats = []
  884. source_format = self._extract_original_format(
  885. 'https://vimeo.com/' + video_id, video_id, video.get('unlisted_hash'))
  886. if source_format:
  887. formats.append(source_format)
  888. info_dict_config = self._parse_config(config, video_id)
  889. formats.extend(info_dict_config['formats'])
  890. info_dict['_format_sort_fields'] = info_dict_config['_format_sort_fields']
  891. json_ld = self._search_json_ld(webpage, video_id, default={})
  892. if not cc_license:
  893. cc_license = self._search_regex(
  894. r'<link[^>]+rel=["\']license["\'][^>]+href=(["\'])(?P<license>(?:(?!\1).)+)\1',
  895. webpage, 'license', default=None, group='license')
  896. info_dict.update({
  897. 'formats': formats,
  898. 'timestamp': unified_timestamp(timestamp),
  899. 'description': video_description,
  900. 'webpage_url': url,
  901. 'view_count': view_count,
  902. 'like_count': like_count,
  903. 'comment_count': comment_count,
  904. 'license': cc_license,
  905. })
  906. return merge_dicts(info_dict, info_dict_config, json_ld)
  907. class VimeoOndemandIE(VimeoIE): # XXX: Do not subclass from concrete IE
  908. IE_NAME = 'vimeo:ondemand'
  909. _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?:[^/]+/)?(?P<id>[^/?#&]+)'
  910. _TESTS = [{
  911. # ondemand video not available via https://vimeo.com/id
  912. 'url': 'https://vimeo.com/ondemand/20704',
  913. 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35',
  914. 'info_dict': {
  915. 'id': '105442900',
  916. 'ext': 'mp4',
  917. 'title': 'המעבדה - במאי יותם פלדמן',
  918. 'uploader': 'גם סרטים',
  919. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/gumfilms',
  920. 'uploader_id': 'gumfilms',
  921. 'description': 'md5:aeeba3dbd4d04b0fa98a4fdc9c639998',
  922. 'upload_date': '20140906',
  923. 'timestamp': 1410032453,
  924. 'thumbnail': 'https://i.vimeocdn.com/video/488238335-d7bf151c364cff8d467f1b73784668fe60aae28a54573a35d53a1210ae283bd8-d_1280',
  925. 'comment_count': int,
  926. 'license': 'https://creativecommons.org/licenses/by-nc-nd/3.0/',
  927. 'duration': 53,
  928. 'view_count': int,
  929. 'like_count': int,
  930. },
  931. 'params': {
  932. 'format': 'best[protocol=https]',
  933. },
  934. 'expected_warnings': ['Unable to download JSON metadata'],
  935. }, {
  936. # requires Referer to be passed along with og:video:url
  937. 'url': 'https://vimeo.com/ondemand/36938/126682985',
  938. 'info_dict': {
  939. 'id': '126584684',
  940. 'ext': 'mp4',
  941. 'title': 'Rävlock, rätt läte på rätt plats',
  942. 'uploader': 'Lindroth & Norin',
  943. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/lindrothnorin',
  944. 'uploader_id': 'lindrothnorin',
  945. 'description': 'md5:c3c46a90529612c8279fb6af803fc0df',
  946. 'upload_date': '20150502',
  947. 'timestamp': 1430586422,
  948. 'duration': 121,
  949. 'comment_count': int,
  950. 'view_count': int,
  951. 'thumbnail': 'https://i.vimeocdn.com/video/517077723-7066ae1d9a79d3eb361334fb5d58ec13c8f04b52f8dd5eadfbd6fb0bcf11f613-d_1280',
  952. 'like_count': int,
  953. },
  954. 'params': {
  955. 'skip_download': True,
  956. },
  957. 'expected_warnings': ['Unable to download JSON metadata'],
  958. }, {
  959. 'url': 'https://vimeo.com/ondemand/nazmaalik',
  960. 'only_matching': True,
  961. }, {
  962. 'url': 'https://vimeo.com/ondemand/141692381',
  963. 'only_matching': True,
  964. }, {
  965. 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832',
  966. 'only_matching': True,
  967. }]
  968. class VimeoChannelIE(VimeoBaseInfoExtractor):
  969. IE_NAME = 'vimeo:channel'
  970. _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
  971. _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
  972. _TITLE = None
  973. _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
  974. _TESTS = [{
  975. 'url': 'https://vimeo.com/channels/tributes',
  976. 'info_dict': {
  977. 'id': 'tributes',
  978. 'title': 'Vimeo Tributes',
  979. },
  980. 'playlist_mincount': 22,
  981. }]
  982. _BASE_URL_TEMPL = 'https://vimeo.com/channels/%s'
  983. def _page_url(self, base_url, pagenum):
  984. return '%s/videos/page:%d/' % (base_url, pagenum)
  985. def _extract_list_title(self, webpage):
  986. return self._TITLE or self._html_search_regex(
  987. self._TITLE_RE, webpage, 'list title', fatal=False)
  988. def _title_and_entries(self, list_id, base_url):
  989. for pagenum in itertools.count(1):
  990. page_url = self._page_url(base_url, pagenum)
  991. webpage = self._download_webpage(
  992. page_url, list_id,
  993. 'Downloading page %s' % pagenum)
  994. if pagenum == 1:
  995. yield self._extract_list_title(webpage)
  996. # Try extracting href first since not all videos are available via
  997. # short https://vimeo.com/id URL (e.g. https://vimeo.com/channels/tributes/6213729)
  998. clips = re.findall(
  999. r'id="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)(?:[^>]+\btitle="([^"]+)")?', webpage)
  1000. if clips:
  1001. for video_id, video_url, video_title in clips:
  1002. yield self.url_result(
  1003. compat_urlparse.urljoin(base_url, video_url),
  1004. VimeoIE.ie_key(), video_id=video_id, video_title=video_title)
  1005. # More relaxed fallback
  1006. else:
  1007. for video_id in re.findall(r'id=["\']clip_(\d+)', webpage):
  1008. yield self.url_result(
  1009. 'https://vimeo.com/%s' % video_id,
  1010. VimeoIE.ie_key(), video_id=video_id)
  1011. if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
  1012. break
  1013. def _extract_videos(self, list_id, base_url):
  1014. title_and_entries = self._title_and_entries(list_id, base_url)
  1015. list_title = next(title_and_entries)
  1016. return self.playlist_result(title_and_entries, list_id, list_title)
  1017. def _real_extract(self, url):
  1018. channel_id = self._match_id(url)
  1019. return self._extract_videos(channel_id, self._BASE_URL_TEMPL % channel_id)
  1020. class VimeoUserIE(VimeoChannelIE): # XXX: Do not subclass from concrete IE
  1021. IE_NAME = 'vimeo:user'
  1022. _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<id>[^/]+)(?:/videos)?/?(?:$|[?#])'
  1023. _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
  1024. _TESTS = [{
  1025. 'url': 'https://vimeo.com/nkistudio/videos',
  1026. 'info_dict': {
  1027. 'title': 'Nki',
  1028. 'id': 'nkistudio',
  1029. },
  1030. 'playlist_mincount': 66,
  1031. }, {
  1032. 'url': 'https://vimeo.com/nkistudio/',
  1033. 'only_matching': True,
  1034. }]
  1035. _BASE_URL_TEMPL = 'https://vimeo.com/%s'
  1036. class VimeoAlbumIE(VimeoBaseInfoExtractor):
  1037. IE_NAME = 'vimeo:album'
  1038. _VALID_URL = r'https://vimeo\.com/(?:album|showcase)/(?P<id>\d+)(?:$|[?#]|/(?!video))'
  1039. _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
  1040. _TESTS = [{
  1041. 'url': 'https://vimeo.com/album/2632481',
  1042. 'info_dict': {
  1043. 'id': '2632481',
  1044. 'title': 'Staff Favorites: November 2013',
  1045. },
  1046. 'playlist_mincount': 13,
  1047. }, {
  1048. 'note': 'Password-protected album',
  1049. 'url': 'https://vimeo.com/album/3253534',
  1050. 'info_dict': {
  1051. 'title': 'test',
  1052. 'id': '3253534',
  1053. },
  1054. 'playlist_count': 1,
  1055. 'params': {
  1056. 'videopassword': 'youtube-dl',
  1057. }
  1058. }]
  1059. _PAGE_SIZE = 100
  1060. def _fetch_page(self, album_id, authorization, hashed_pass, page):
  1061. api_page = page + 1
  1062. query = {
  1063. 'fields': 'link,uri',
  1064. 'page': api_page,
  1065. 'per_page': self._PAGE_SIZE,
  1066. }
  1067. if hashed_pass:
  1068. query['_hashed_pass'] = hashed_pass
  1069. try:
  1070. videos = self._download_json(
  1071. 'https://api.vimeo.com/albums/%s/videos' % album_id,
  1072. album_id, 'Downloading page %d' % api_page, query=query, headers={
  1073. 'Authorization': 'jwt ' + authorization,
  1074. })['data']
  1075. except ExtractorError as e:
  1076. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  1077. return
  1078. for video in videos:
  1079. link = video.get('link')
  1080. if not link:
  1081. continue
  1082. uri = video.get('uri')
  1083. video_id = self._search_regex(r'/videos/(\d+)', uri, 'video_id', default=None) if uri else None
  1084. yield self.url_result(link, VimeoIE.ie_key(), video_id)
  1085. def _real_extract(self, url):
  1086. album_id = self._match_id(url)
  1087. viewer = self._download_json(
  1088. 'https://vimeo.com/_rv/viewer', album_id, fatal=False)
  1089. if not viewer:
  1090. webpage = self._download_webpage(url, album_id)
  1091. viewer = self._parse_json(self._search_regex(
  1092. r'bootstrap_data\s*=\s*({.+?})</script>',
  1093. webpage, 'bootstrap data'), album_id)['viewer']
  1094. jwt = viewer['jwt']
  1095. album = self._download_json(
  1096. 'https://api.vimeo.com/albums/' + album_id,
  1097. album_id, headers={'Authorization': 'jwt ' + jwt},
  1098. query={'fields': 'description,name,privacy'})
  1099. hashed_pass = None
  1100. if try_get(album, lambda x: x['privacy']['view']) == 'password':
  1101. password = self.get_param('videopassword')
  1102. if not password:
  1103. raise ExtractorError(
  1104. 'This album is protected by a password, use the --video-password option',
  1105. expected=True)
  1106. self._set_vimeo_cookie('vuid', viewer['vuid'])
  1107. try:
  1108. hashed_pass = self._download_json(
  1109. 'https://vimeo.com/showcase/%s/auth' % album_id,
  1110. album_id, 'Verifying the password', data=urlencode_postdata({
  1111. 'password': password,
  1112. 'token': viewer['xsrft'],
  1113. }), headers={
  1114. 'X-Requested-With': 'XMLHttpRequest',
  1115. })['hashed_pass']
  1116. except ExtractorError as e:
  1117. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
  1118. raise ExtractorError('Wrong password', expected=True)
  1119. raise
  1120. entries = OnDemandPagedList(functools.partial(
  1121. self._fetch_page, album_id, jwt, hashed_pass), self._PAGE_SIZE)
  1122. return self.playlist_result(
  1123. entries, album_id, album.get('name'), album.get('description'))
  1124. class VimeoGroupsIE(VimeoChannelIE): # XXX: Do not subclass from concrete IE
  1125. IE_NAME = 'vimeo:group'
  1126. _VALID_URL = r'https://vimeo\.com/groups/(?P<id>[^/]+)(?:/(?!videos?/\d+)|$)'
  1127. _TESTS = [{
  1128. 'url': 'https://vimeo.com/groups/meetup',
  1129. 'info_dict': {
  1130. 'id': 'meetup',
  1131. 'title': 'Vimeo Meetup!',
  1132. },
  1133. 'playlist_mincount': 27,
  1134. }]
  1135. _BASE_URL_TEMPL = 'https://vimeo.com/groups/%s'
  1136. class VimeoReviewIE(VimeoBaseInfoExtractor):
  1137. IE_NAME = 'vimeo:review'
  1138. IE_DESC = 'Review pages on vimeo'
  1139. _VALID_URL = r'(?P<url>https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)/[0-9a-f]{10})'
  1140. _TESTS = [{
  1141. 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
  1142. 'md5': 'c507a72f780cacc12b2248bb4006d253',
  1143. 'info_dict': {
  1144. 'id': '75524534',
  1145. 'ext': 'mp4',
  1146. 'title': "DICK HARDWICK 'Comedian'",
  1147. 'uploader': 'Richard Hardwick',
  1148. 'uploader_id': 'user21297594',
  1149. 'description': "Comedian Dick Hardwick's five minute demo filmed in front of a live theater audience.\nEdit by Doug Mattocks",
  1150. 'duration': 304,
  1151. 'thumbnail': 'https://i.vimeocdn.com/video/450115033-43303819d9ebe24c2630352e18b7056d25197d09b3ae901abdac4c4f1d68de71-d_1280',
  1152. 'uploader_url': 'https://vimeo.com/user21297594',
  1153. },
  1154. }, {
  1155. 'note': 'video player needs Referer',
  1156. 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
  1157. 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
  1158. 'info_dict': {
  1159. 'id': '91613211',
  1160. 'ext': 'mp4',
  1161. 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
  1162. 'uploader': 'DevWeek Events',
  1163. 'duration': 2773,
  1164. 'thumbnail': r're:^https?://.*\.jpg$',
  1165. 'uploader_id': 'user22258446',
  1166. },
  1167. 'skip': 'video gone',
  1168. }, {
  1169. 'note': 'Password protected',
  1170. 'url': 'https://vimeo.com/user37284429/review/138823582/c4d865efde',
  1171. 'info_dict': {
  1172. 'id': '138823582',
  1173. 'ext': 'mp4',
  1174. 'title': 'EFFICIENT PICKUP MASTERCLASS MODULE 1',
  1175. 'uploader': 'TMB',
  1176. 'uploader_id': 'user37284429',
  1177. },
  1178. 'params': {
  1179. 'videopassword': 'holygrail',
  1180. },
  1181. 'skip': 'video gone',
  1182. }]
  1183. def _real_extract(self, url):
  1184. page_url, video_id = self._match_valid_url(url).groups()
  1185. data = self._download_json(
  1186. page_url.replace('/review/', '/review/data/'), video_id)
  1187. if data.get('isLocked') is True:
  1188. video_password = self._get_video_password()
  1189. viewer = self._download_json(
  1190. 'https://vimeo.com/_rv/viewer', video_id)
  1191. webpage = self._verify_video_password(
  1192. 'https://vimeo.com/' + video_id, video_id,
  1193. video_password, viewer['xsrft'], viewer['vuid'])
  1194. clip_page_config = self._parse_json(self._search_regex(
  1195. r'window\.vimeo\.clip_page_config\s*=\s*({.+?});',
  1196. webpage, 'clip page config'), video_id)
  1197. config_url = clip_page_config['player']['config_url']
  1198. clip_data = clip_page_config.get('clip') or {}
  1199. else:
  1200. clip_data = data['clipData']
  1201. config_url = clip_data['configUrl']
  1202. config = self._download_json(config_url, video_id)
  1203. info_dict = self._parse_config(config, video_id)
  1204. source_format = self._extract_original_format(
  1205. page_url + '/action', video_id)
  1206. if source_format:
  1207. info_dict['formats'].append(source_format)
  1208. info_dict['description'] = clean_html(clip_data.get('description'))
  1209. return info_dict
  1210. class VimeoWatchLaterIE(VimeoChannelIE): # XXX: Do not subclass from concrete IE
  1211. IE_NAME = 'vimeo:watchlater'
  1212. IE_DESC = 'Vimeo watch later list, ":vimeowatchlater" keyword (requires authentication)'
  1213. _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
  1214. _TITLE = 'Watch Later'
  1215. _LOGIN_REQUIRED = True
  1216. _TESTS = [{
  1217. 'url': 'https://vimeo.com/watchlater',
  1218. 'only_matching': True,
  1219. }]
  1220. def _page_url(self, base_url, pagenum):
  1221. url = '%s/page:%d/' % (base_url, pagenum)
  1222. request = sanitized_Request(url)
  1223. # Set the header to get a partial html page with the ids,
  1224. # the normal page doesn't contain them.
  1225. request.add_header('X-Requested-With', 'XMLHttpRequest')
  1226. return request
  1227. def _real_extract(self, url):
  1228. return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
  1229. class VimeoLikesIE(VimeoChannelIE): # XXX: Do not subclass from concrete IE
  1230. _VALID_URL = r'https://(?:www\.)?vimeo\.com/(?P<id>[^/]+)/likes/?(?:$|[?#]|sort:)'
  1231. IE_NAME = 'vimeo:likes'
  1232. IE_DESC = 'Vimeo user likes'
  1233. _TESTS = [{
  1234. 'url': 'https://vimeo.com/user755559/likes/',
  1235. 'playlist_mincount': 293,
  1236. 'info_dict': {
  1237. 'id': 'user755559',
  1238. 'title': 'urza’s Likes',
  1239. },
  1240. }, {
  1241. 'url': 'https://vimeo.com/stormlapse/likes',
  1242. 'only_matching': True,
  1243. }]
  1244. def _page_url(self, base_url, pagenum):
  1245. return '%s/page:%d/' % (base_url, pagenum)
  1246. def _real_extract(self, url):
  1247. user_id = self._match_id(url)
  1248. return self._extract_videos(user_id, 'https://vimeo.com/%s/likes' % user_id)
  1249. class VHXEmbedIE(VimeoBaseInfoExtractor):
  1250. IE_NAME = 'vhx:embed'
  1251. _VALID_URL = r'https?://embed\.vhx\.tv/videos/(?P<id>\d+)'
  1252. _EMBED_REGEX = [r'<iframe[^>]+src="(?P<url>https?://embed\.vhx\.tv/videos/\d+[^"]*)"']
  1253. @classmethod
  1254. def _extract_embed_urls(cls, url, webpage):
  1255. for embed_url in super()._extract_embed_urls(url, webpage):
  1256. yield cls._smuggle_referrer(embed_url, url)
  1257. def _real_extract(self, url):
  1258. video_id = self._match_id(url)
  1259. url, _, headers = self._unsmuggle_headers(url)
  1260. webpage = self._download_webpage(url, video_id, headers=headers)
  1261. config_url = self._parse_json(self._search_regex(
  1262. r'window\.OTTData\s*=\s*({.+})', webpage,
  1263. 'ott data'), video_id, js_to_json)['config_url']
  1264. config = self._download_json(config_url, video_id)
  1265. info = self._parse_config(config, video_id)
  1266. info['id'] = video_id
  1267. return info
  1268. class VimeoProIE(VimeoBaseInfoExtractor):
  1269. IE_NAME = 'vimeo:pro'
  1270. _VALID_URL = r'https?://(?:www\.)?vimeopro\.com/[^/?#]+/(?P<slug>[^/?#]+)(?:(?:/videos?/(?P<id>[0-9]+)))?'
  1271. _TESTS = [{
  1272. # Vimeo URL derived from video_id
  1273. 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
  1274. 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
  1275. 'note': 'Vimeo Pro video (#1197)',
  1276. 'info_dict': {
  1277. 'id': '68093876',
  1278. 'ext': 'mp4',
  1279. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/openstreetmapus',
  1280. 'uploader_id': 'openstreetmapus',
  1281. 'uploader': 'OpenStreetMap US',
  1282. 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
  1283. 'description': 'md5:2c362968038d4499f4d79f88458590c1',
  1284. 'duration': 1595,
  1285. 'upload_date': '20130610',
  1286. 'timestamp': 1370893156,
  1287. 'license': 'by',
  1288. 'thumbnail': 'https://i.vimeocdn.com/video/440260469-19b0d92fca3bd84066623b53f1eb8aaa3980c6c809e2d67b6b39ab7b4a77a344-d_960',
  1289. 'view_count': int,
  1290. 'comment_count': int,
  1291. 'like_count': int,
  1292. 'tags': 'count:1',
  1293. },
  1294. 'params': {
  1295. 'format': 'best[protocol=https]',
  1296. },
  1297. }, {
  1298. # password-protected VimeoPro page with Vimeo player embed
  1299. 'url': 'https://vimeopro.com/cadfem/simulation-conference-mechanische-systeme-in-perfektion',
  1300. 'info_dict': {
  1301. 'id': '764543723',
  1302. 'ext': 'mp4',
  1303. 'title': 'Mechanische Systeme in Perfektion: Realität erfassen, Innovation treiben',
  1304. 'thumbnail': 'https://i.vimeocdn.com/video/1543784598-a1a750494a485e601110136b9fe11e28c2131942452b3a5d30391cb3800ca8fd-d_1280',
  1305. 'description': 'md5:2a9d195cd1b0f6f79827107dc88c2420',
  1306. 'uploader': 'CADFEM',
  1307. 'uploader_id': 'cadfem',
  1308. 'uploader_url': 'https://vimeo.com/cadfem',
  1309. 'duration': 12505,
  1310. 'chapters': 'count:10',
  1311. },
  1312. 'params': {
  1313. 'videopassword': 'Conference2022',
  1314. 'skip_download': True,
  1315. },
  1316. }]
  1317. def _real_extract(self, url):
  1318. display_id, video_id = self._match_valid_url(url).group('slug', 'id')
  1319. if video_id:
  1320. display_id = video_id
  1321. webpage = self._download_webpage(url, display_id)
  1322. password_form = self._search_regex(
  1323. r'(?is)<form[^>]+?method=["\']post["\'][^>]*>(.+?password.+?)</form>',
  1324. webpage, 'password form', default=None)
  1325. if password_form:
  1326. try:
  1327. webpage = self._download_webpage(url, display_id, data=urlencode_postdata({
  1328. 'password': self._get_video_password(),
  1329. **self._hidden_inputs(password_form),
  1330. }), note='Logging in with video password')
  1331. except ExtractorError as e:
  1332. if isinstance(e.cause, urllib.error.HTTPError) and e.cause.code == 418:
  1333. raise ExtractorError('Wrong video password', expected=True)
  1334. raise
  1335. description = None
  1336. # even if we have video_id, some videos require player URL with portfolio_id query param
  1337. # https://github.com/ytdl-org/youtube-dl/issues/20070
  1338. vimeo_url = VimeoIE._extract_url(url, webpage)
  1339. if vimeo_url:
  1340. description = self._html_search_meta('description', webpage, default=None)
  1341. elif video_id:
  1342. vimeo_url = f'https://vimeo.com/{video_id}'
  1343. else:
  1344. raise ExtractorError(
  1345. 'No Vimeo embed or video ID could be found in VimeoPro page', expected=True)
  1346. return self.url_result(vimeo_url, VimeoIE, video_id, url_transparent=True,
  1347. description=description)