vimeo.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. import itertools
  6. from .common import InfoExtractor
  7. from ..compat import (
  8. compat_HTTPError,
  9. compat_urlparse,
  10. )
  11. from ..utils import (
  12. encode_dict,
  13. ExtractorError,
  14. InAdvancePagedList,
  15. int_or_none,
  16. RegexNotFoundError,
  17. sanitized_Request,
  18. smuggle_url,
  19. std_headers,
  20. unified_strdate,
  21. unsmuggle_url,
  22. urlencode_postdata,
  23. unescapeHTML,
  24. parse_filesize,
  25. )
  26. class VimeoBaseInfoExtractor(InfoExtractor):
  27. _NETRC_MACHINE = 'vimeo'
  28. _LOGIN_REQUIRED = False
  29. _LOGIN_URL = 'https://vimeo.com/log_in'
  30. def _login(self):
  31. (username, password) = self._get_login_info()
  32. if username is None:
  33. if self._LOGIN_REQUIRED:
  34. raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
  35. return
  36. self.report_login()
  37. webpage = self._download_webpage(self._LOGIN_URL, None, False)
  38. token, vuid = self._extract_xsrft_and_vuid(webpage)
  39. data = urlencode_postdata(encode_dict({
  40. 'action': 'login',
  41. 'email': username,
  42. 'password': password,
  43. 'service': 'vimeo',
  44. 'token': token,
  45. }))
  46. login_request = sanitized_Request(self._LOGIN_URL, data)
  47. login_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  48. login_request.add_header('Referer', self._LOGIN_URL)
  49. self._set_vimeo_cookie('vuid', vuid)
  50. self._download_webpage(login_request, None, False, 'Wrong login info')
  51. def _extract_xsrft_and_vuid(self, webpage):
  52. xsrft = self._search_regex(
  53. r'xsrft\s*[=:]\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
  54. webpage, 'login token', group='xsrft')
  55. vuid = self._search_regex(
  56. r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
  57. webpage, 'vuid', group='vuid')
  58. return xsrft, vuid
  59. def _set_vimeo_cookie(self, name, value):
  60. self._set_cookie('vimeo.com', name, value)
  61. class VimeoIE(VimeoBaseInfoExtractor):
  62. """Information extractor for vimeo.com."""
  63. # _VALID_URL matches Vimeo URLs
  64. _VALID_URL = r'''(?x)
  65. https?://
  66. (?:(?:www|(?P<player>player))\.)?
  67. vimeo(?P<pro>pro)?\.com/
  68. (?!channels/[^/?#]+/?(?:$|[?#])|album/)
  69. (?:.*?/)?
  70. (?:(?:play_redirect_hls|moogaloop\.swf)\?clip_id=)?
  71. (?:videos?/)?
  72. (?P<id>[0-9]+)
  73. /?(?:[?&].*)?(?:[#].*)?$'''
  74. IE_NAME = 'vimeo'
  75. _TESTS = [
  76. {
  77. 'url': 'http://vimeo.com/56015672#at=0',
  78. 'md5': '8879b6cc097e987f02484baf890129e5',
  79. 'info_dict': {
  80. 'id': '56015672',
  81. 'ext': 'mp4',
  82. 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
  83. 'description': 'md5:2d3305bad981a06ff79f027f19865021',
  84. 'upload_date': '20121220',
  85. 'uploader_id': 'user7108434',
  86. 'uploader': 'Filippo Valsorda',
  87. 'duration': 10,
  88. },
  89. },
  90. {
  91. 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
  92. 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
  93. 'note': 'Vimeo Pro video (#1197)',
  94. 'info_dict': {
  95. 'id': '68093876',
  96. 'ext': 'mp4',
  97. 'uploader_id': 'openstreetmapus',
  98. 'uploader': 'OpenStreetMap US',
  99. 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
  100. 'description': 'md5:fd69a7b8d8c34a4e1d2ec2e4afd6ec30',
  101. 'duration': 1595,
  102. },
  103. },
  104. {
  105. 'url': 'http://player.vimeo.com/video/54469442',
  106. 'md5': '619b811a4417aa4abe78dc653becf511',
  107. 'note': 'Videos that embed the url in the player page',
  108. 'info_dict': {
  109. 'id': '54469442',
  110. 'ext': 'mp4',
  111. 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
  112. 'uploader': 'The BLN & Business of Software',
  113. 'uploader_id': 'theblnbusinessofsoftware',
  114. 'duration': 3610,
  115. 'description': None,
  116. },
  117. },
  118. {
  119. 'url': 'http://vimeo.com/68375962',
  120. 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
  121. 'note': 'Video protected with password',
  122. 'info_dict': {
  123. 'id': '68375962',
  124. 'ext': 'mp4',
  125. 'title': 'youtube-dl password protected test video',
  126. 'upload_date': '20130614',
  127. 'uploader_id': 'user18948128',
  128. 'uploader': 'Jaime Marquínez Ferrándiz',
  129. 'duration': 10,
  130. 'description': 'This is "youtube-dl password protected test video" by Jaime Marquínez Ferrándiz on Vimeo, the home for high quality videos and the people\u2026',
  131. },
  132. 'params': {
  133. 'videopassword': 'youtube-dl',
  134. },
  135. },
  136. {
  137. 'url': 'http://vimeo.com/channels/keypeele/75629013',
  138. 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
  139. 'note': 'Video is freely available via original URL '
  140. 'and protected with password when accessed via http://vimeo.com/75629013',
  141. 'info_dict': {
  142. 'id': '75629013',
  143. 'ext': 'mp4',
  144. 'title': 'Key & Peele: Terrorist Interrogation',
  145. 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
  146. 'uploader_id': 'atencio',
  147. 'uploader': 'Peter Atencio',
  148. 'upload_date': '20130927',
  149. 'duration': 187,
  150. },
  151. },
  152. {
  153. 'url': 'http://vimeo.com/76979871',
  154. 'note': 'Video with subtitles',
  155. 'info_dict': {
  156. 'id': '76979871',
  157. 'ext': 'mp4',
  158. 'title': 'The New Vimeo Player (You Know, For Videos)',
  159. 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
  160. 'upload_date': '20131015',
  161. 'uploader_id': 'staff',
  162. 'uploader': 'Vimeo Staff',
  163. 'duration': 62,
  164. }
  165. },
  166. {
  167. # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
  168. 'url': 'https://player.vimeo.com/video/98044508',
  169. 'note': 'The js code contains assignments to the same variable as the config',
  170. 'info_dict': {
  171. 'id': '98044508',
  172. 'ext': 'mp4',
  173. 'title': 'Pier Solar OUYA Official Trailer',
  174. 'uploader': 'Tulio Gonçalves',
  175. 'uploader_id': 'user28849593',
  176. },
  177. },
  178. {
  179. 'url': 'https://vimeo.com/109815029',
  180. 'note': 'Video not completely processed, "failed" seed status',
  181. 'only_matching': True,
  182. },
  183. {
  184. 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
  185. 'only_matching': True,
  186. },
  187. ]
  188. @staticmethod
  189. def _extract_vimeo_url(url, webpage):
  190. # Look for embedded (iframe) Vimeo player
  191. mobj = re.search(
  192. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/.+?)\1', webpage)
  193. if mobj:
  194. player_url = unescapeHTML(mobj.group('url'))
  195. surl = smuggle_url(player_url, {'Referer': url})
  196. return surl
  197. # Look for embedded (swf embed) Vimeo player
  198. mobj = re.search(
  199. r'<embed[^>]+?src="((?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)"', webpage)
  200. if mobj:
  201. return mobj.group(1)
  202. def _verify_video_password(self, url, video_id, webpage):
  203. password = self._downloader.params.get('videopassword', None)
  204. if password is None:
  205. raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True)
  206. token, vuid = self._extract_xsrft_and_vuid(webpage)
  207. data = urlencode_postdata(encode_dict({
  208. 'password': password,
  209. 'token': token,
  210. }))
  211. if url.startswith('http://'):
  212. # vimeo only supports https now, but the user can give an http url
  213. url = url.replace('http://', 'https://')
  214. password_request = sanitized_Request(url + '/password', data)
  215. password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  216. password_request.add_header('Referer', url)
  217. self._set_vimeo_cookie('vuid', vuid)
  218. return self._download_webpage(
  219. password_request, video_id,
  220. 'Verifying the password', 'Wrong password')
  221. def _verify_player_video_password(self, url, video_id):
  222. password = self._downloader.params.get('videopassword', None)
  223. if password is None:
  224. raise ExtractorError('This video is protected by a password, use the --video-password option')
  225. data = urlencode_postdata(encode_dict({'password': password}))
  226. pass_url = url + '/check-password'
  227. password_request = sanitized_Request(pass_url, data)
  228. password_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  229. return self._download_json(
  230. password_request, video_id,
  231. 'Verifying the password',
  232. 'Wrong password')
  233. def _real_initialize(self):
  234. self._login()
  235. def _real_extract(self, url):
  236. url, data = unsmuggle_url(url)
  237. headers = std_headers
  238. if data is not None:
  239. headers = headers.copy()
  240. headers.update(data)
  241. if 'Referer' not in headers:
  242. headers['Referer'] = url
  243. # Extract ID from URL
  244. mobj = re.match(self._VALID_URL, url)
  245. video_id = mobj.group('id')
  246. orig_url = url
  247. if mobj.group('pro') or mobj.group('player'):
  248. url = 'https://player.vimeo.com/video/' + video_id
  249. else:
  250. url = 'https://vimeo.com/' + video_id
  251. # Retrieve video webpage to extract further information
  252. request = sanitized_Request(url, None, headers)
  253. try:
  254. webpage = self._download_webpage(request, video_id)
  255. except ExtractorError as ee:
  256. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
  257. errmsg = ee.cause.read()
  258. if b'Because of its privacy settings, this video cannot be played here' in errmsg:
  259. raise ExtractorError(
  260. 'Cannot download embed-only video without embedding '
  261. 'URL. Please call youtube-dl with the URL of the page '
  262. 'that embeds this video.',
  263. expected=True)
  264. raise
  265. # Now we begin extracting as much information as we can from what we
  266. # retrieved. First we extract the information common to all extractors,
  267. # and latter we extract those that are Vimeo specific.
  268. self.report_extraction(video_id)
  269. vimeo_config = self._search_regex(
  270. r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));', webpage,
  271. 'vimeo config', default=None)
  272. if vimeo_config:
  273. seed_status = self._parse_json(vimeo_config, video_id).get('seed_status', {})
  274. if seed_status.get('state') == 'failed':
  275. raise ExtractorError(
  276. '%s said: %s' % (self.IE_NAME, seed_status['title']),
  277. expected=True)
  278. # Extract the config JSON
  279. try:
  280. try:
  281. config_url = self._html_search_regex(
  282. r' data-config-url="(.+?)"', webpage,
  283. 'config URL', default=None)
  284. if not config_url:
  285. # Sometimes new react-based page is served instead of old one that require
  286. # different config URL extraction approach (see
  287. # https://github.com/rg3/youtube-dl/pull/7209)
  288. vimeo_clip_page_config = self._search_regex(
  289. r'vimeo\.clip_page_config\s*=\s*({.+?});', webpage,
  290. 'vimeo clip page config')
  291. config_url = self._parse_json(
  292. vimeo_clip_page_config, video_id)['player']['config_url']
  293. config_json = self._download_webpage(config_url, video_id)
  294. config = json.loads(config_json)
  295. except RegexNotFoundError:
  296. # For pro videos or player.vimeo.com urls
  297. # We try to find out to which variable is assigned the config dic
  298. m_variable_name = re.search('(\w)\.video\.id', webpage)
  299. if m_variable_name is not None:
  300. config_re = r'%s=({[^}].+?});' % re.escape(m_variable_name.group(1))
  301. else:
  302. config_re = [r' = {config:({.+?}),assets:', r'(?:[abc])=({.+?});']
  303. config = self._search_regex(config_re, webpage, 'info section',
  304. flags=re.DOTALL)
  305. config = json.loads(config)
  306. except Exception as e:
  307. if re.search('The creator of this video has not given you permission to embed it on this domain.', webpage):
  308. raise ExtractorError('The author has restricted the access to this video, try with the "--referer" option')
  309. if re.search(r'<form[^>]+?id="pw_form"', webpage) is not None:
  310. if data and '_video_password_verified' in data:
  311. raise ExtractorError('video password verification failed!')
  312. self._verify_video_password(url, video_id, webpage)
  313. return self._real_extract(
  314. smuggle_url(url, {'_video_password_verified': 'verified'}))
  315. else:
  316. raise ExtractorError('Unable to extract info section',
  317. cause=e)
  318. else:
  319. if config.get('view') == 4:
  320. config = self._verify_player_video_password(url, video_id)
  321. # Extract title
  322. video_title = config["video"]["title"]
  323. # Extract uploader and uploader_id
  324. video_uploader = config["video"]["owner"]["name"]
  325. video_uploader_id = config["video"]["owner"]["url"].split('/')[-1] if config["video"]["owner"]["url"] else None
  326. # Extract video thumbnail
  327. video_thumbnail = config["video"].get("thumbnail")
  328. if video_thumbnail is None:
  329. video_thumbs = config["video"].get("thumbs")
  330. if video_thumbs and isinstance(video_thumbs, dict):
  331. _, video_thumbnail = sorted((int(width if width.isdigit() else 0), t_url) for (width, t_url) in video_thumbs.items())[-1]
  332. # Extract video description
  333. video_description = self._html_search_regex(
  334. r'(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>',
  335. webpage, 'description', default=None)
  336. if not video_description:
  337. video_description = self._html_search_meta(
  338. 'description', webpage, default=None)
  339. if not video_description and mobj.group('pro'):
  340. orig_webpage = self._download_webpage(
  341. orig_url, video_id,
  342. note='Downloading webpage for description',
  343. fatal=False)
  344. if orig_webpage:
  345. video_description = self._html_search_meta(
  346. 'description', orig_webpage, default=None)
  347. if not video_description and not mobj.group('player'):
  348. self._downloader.report_warning('Cannot find video description')
  349. # Extract video duration
  350. video_duration = int_or_none(config["video"].get("duration"))
  351. # Extract upload date
  352. video_upload_date = None
  353. mobj = re.search(r'<time[^>]+datetime="([^"]+)"', webpage)
  354. if mobj is not None:
  355. video_upload_date = unified_strdate(mobj.group(1))
  356. try:
  357. view_count = int(self._search_regex(r'UserPlays:(\d+)', webpage, 'view count'))
  358. like_count = int(self._search_regex(r'UserLikes:(\d+)', webpage, 'like count'))
  359. comment_count = int(self._search_regex(r'UserComments:(\d+)', webpage, 'comment count'))
  360. except RegexNotFoundError:
  361. # This info is only available in vimeo.com/{id} urls
  362. view_count = None
  363. like_count = None
  364. comment_count = None
  365. formats = []
  366. download_request = sanitized_Request('https://vimeo.com/%s?action=load_download_config' % video_id, headers={
  367. 'X-Requested-With': 'XMLHttpRequest'})
  368. download_data = self._download_json(download_request, video_id, fatal=False)
  369. if download_data:
  370. source_file = download_data.get('source_file')
  371. if source_file and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
  372. formats.append({
  373. 'url': source_file['download_url'],
  374. 'ext': source_file['extension'].lower(),
  375. 'width': int_or_none(source_file.get('width')),
  376. 'height': int_or_none(source_file.get('height')),
  377. 'filesize': parse_filesize(source_file.get('size')),
  378. 'format_id': source_file.get('public_name', 'Original'),
  379. })
  380. config_files = config['video'].get('files') or config['request'].get('files', {})
  381. for f in config_files.get('progressive', []):
  382. video_url = f.get('url')
  383. if not video_url:
  384. continue
  385. formats.append({
  386. 'url': video_url,
  387. 'format_id': 'http-%s' % f.get('quality'),
  388. 'width': int_or_none(f.get('width')),
  389. 'height': int_or_none(f.get('height')),
  390. 'fps': int_or_none(f.get('fps')),
  391. 'tbr': int_or_none(f.get('bitrate')),
  392. })
  393. m3u8_url = config_files.get('hls', {}).get('url')
  394. if m3u8_url:
  395. m3u8_formats = self._extract_m3u8_formats(
  396. m3u8_url, video_id, 'mp4', 'm3u8_native', 0, 'hls', fatal=False)
  397. if m3u8_formats:
  398. formats.extend(m3u8_formats)
  399. # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
  400. # at the same time without actual units specified. This lead to wrong sorting.
  401. self._sort_formats(formats, field_preference=('height', 'width', 'fps', 'format_id'))
  402. subtitles = {}
  403. text_tracks = config['request'].get('text_tracks')
  404. if text_tracks:
  405. for tt in text_tracks:
  406. subtitles[tt['lang']] = [{
  407. 'ext': 'vtt',
  408. 'url': 'https://vimeo.com' + tt['url'],
  409. }]
  410. return {
  411. 'id': video_id,
  412. 'uploader': video_uploader,
  413. 'uploader_id': video_uploader_id,
  414. 'upload_date': video_upload_date,
  415. 'title': video_title,
  416. 'thumbnail': video_thumbnail,
  417. 'description': video_description,
  418. 'duration': video_duration,
  419. 'formats': formats,
  420. 'webpage_url': url,
  421. 'view_count': view_count,
  422. 'like_count': like_count,
  423. 'comment_count': comment_count,
  424. 'subtitles': subtitles,
  425. }
  426. class VimeoChannelIE(VimeoBaseInfoExtractor):
  427. IE_NAME = 'vimeo:channel'
  428. _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
  429. _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
  430. _TITLE = None
  431. _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
  432. _TESTS = [{
  433. 'url': 'https://vimeo.com/channels/tributes',
  434. 'info_dict': {
  435. 'id': 'tributes',
  436. 'title': 'Vimeo Tributes',
  437. },
  438. 'playlist_mincount': 25,
  439. }]
  440. def _page_url(self, base_url, pagenum):
  441. return '%s/videos/page:%d/' % (base_url, pagenum)
  442. def _extract_list_title(self, webpage):
  443. return self._TITLE or self._html_search_regex(self._TITLE_RE, webpage, 'list title')
  444. def _login_list_password(self, page_url, list_id, webpage):
  445. login_form = self._search_regex(
  446. r'(?s)<form[^>]+?id="pw_form"(.*?)</form>',
  447. webpage, 'login form', default=None)
  448. if not login_form:
  449. return webpage
  450. password = self._downloader.params.get('videopassword', None)
  451. if password is None:
  452. raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True)
  453. fields = self._hidden_inputs(login_form)
  454. token, vuid = self._extract_xsrft_and_vuid(webpage)
  455. fields['token'] = token
  456. fields['password'] = password
  457. post = urlencode_postdata(encode_dict(fields))
  458. password_path = self._search_regex(
  459. r'action="([^"]+)"', login_form, 'password URL')
  460. password_url = compat_urlparse.urljoin(page_url, password_path)
  461. password_request = sanitized_Request(password_url, post)
  462. password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
  463. self._set_vimeo_cookie('vuid', vuid)
  464. self._set_vimeo_cookie('xsrft', token)
  465. return self._download_webpage(
  466. password_request, list_id,
  467. 'Verifying the password', 'Wrong password')
  468. def _title_and_entries(self, list_id, base_url):
  469. for pagenum in itertools.count(1):
  470. page_url = self._page_url(base_url, pagenum)
  471. webpage = self._download_webpage(
  472. page_url, list_id,
  473. 'Downloading page %s' % pagenum)
  474. if pagenum == 1:
  475. webpage = self._login_list_password(page_url, list_id, webpage)
  476. yield self._extract_list_title(webpage)
  477. for video_id in re.findall(r'id="clip_(\d+?)"', webpage):
  478. yield self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
  479. if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
  480. break
  481. def _extract_videos(self, list_id, base_url):
  482. title_and_entries = self._title_and_entries(list_id, base_url)
  483. list_title = next(title_and_entries)
  484. return self.playlist_result(title_and_entries, list_id, list_title)
  485. def _real_extract(self, url):
  486. mobj = re.match(self._VALID_URL, url)
  487. channel_id = mobj.group('id')
  488. return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
  489. class VimeoUserIE(VimeoChannelIE):
  490. IE_NAME = 'vimeo:user'
  491. _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
  492. _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
  493. _TESTS = [{
  494. 'url': 'https://vimeo.com/nkistudio/videos',
  495. 'info_dict': {
  496. 'title': 'Nki',
  497. 'id': 'nkistudio',
  498. },
  499. 'playlist_mincount': 66,
  500. }]
  501. def _real_extract(self, url):
  502. mobj = re.match(self._VALID_URL, url)
  503. name = mobj.group('name')
  504. return self._extract_videos(name, 'https://vimeo.com/%s' % name)
  505. class VimeoAlbumIE(VimeoChannelIE):
  506. IE_NAME = 'vimeo:album'
  507. _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
  508. _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
  509. _TESTS = [{
  510. 'url': 'https://vimeo.com/album/2632481',
  511. 'info_dict': {
  512. 'id': '2632481',
  513. 'title': 'Staff Favorites: November 2013',
  514. },
  515. 'playlist_mincount': 13,
  516. }, {
  517. 'note': 'Password-protected album',
  518. 'url': 'https://vimeo.com/album/3253534',
  519. 'info_dict': {
  520. 'title': 'test',
  521. 'id': '3253534',
  522. },
  523. 'playlist_count': 1,
  524. 'params': {
  525. 'videopassword': 'youtube-dl',
  526. }
  527. }]
  528. def _page_url(self, base_url, pagenum):
  529. return '%s/page:%d/' % (base_url, pagenum)
  530. def _real_extract(self, url):
  531. album_id = self._match_id(url)
  532. return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
  533. class VimeoGroupsIE(VimeoAlbumIE):
  534. IE_NAME = 'vimeo:group'
  535. _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)(?:/(?!videos?/\d+)|$)'
  536. _TESTS = [{
  537. 'url': 'https://vimeo.com/groups/rolexawards',
  538. 'info_dict': {
  539. 'id': 'rolexawards',
  540. 'title': 'Rolex Awards for Enterprise',
  541. },
  542. 'playlist_mincount': 73,
  543. }]
  544. def _extract_list_title(self, webpage):
  545. return self._og_search_title(webpage)
  546. def _real_extract(self, url):
  547. mobj = re.match(self._VALID_URL, url)
  548. name = mobj.group('name')
  549. return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
  550. class VimeoReviewIE(InfoExtractor):
  551. IE_NAME = 'vimeo:review'
  552. IE_DESC = 'Review pages on vimeo'
  553. _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
  554. _TESTS = [{
  555. 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
  556. 'md5': 'c507a72f780cacc12b2248bb4006d253',
  557. 'info_dict': {
  558. 'id': '75524534',
  559. 'ext': 'mp4',
  560. 'title': "DICK HARDWICK 'Comedian'",
  561. 'uploader': 'Richard Hardwick',
  562. }
  563. }, {
  564. 'note': 'video player needs Referer',
  565. 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
  566. 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
  567. 'info_dict': {
  568. 'id': '91613211',
  569. 'ext': 'mp4',
  570. 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
  571. 'uploader': 'DevWeek Events',
  572. 'duration': 2773,
  573. 'thumbnail': 're:^https?://.*\.jpg$',
  574. }
  575. }]
  576. def _real_extract(self, url):
  577. mobj = re.match(self._VALID_URL, url)
  578. video_id = mobj.group('id')
  579. player_url = 'https://player.vimeo.com/player/' + video_id
  580. return self.url_result(player_url, 'Vimeo', video_id)
  581. class VimeoWatchLaterIE(VimeoChannelIE):
  582. IE_NAME = 'vimeo:watchlater'
  583. IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
  584. _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
  585. _TITLE = 'Watch Later'
  586. _LOGIN_REQUIRED = True
  587. _TESTS = [{
  588. 'url': 'https://vimeo.com/watchlater',
  589. 'only_matching': True,
  590. }]
  591. def _real_initialize(self):
  592. self._login()
  593. def _page_url(self, base_url, pagenum):
  594. url = '%s/page:%d/' % (base_url, pagenum)
  595. request = sanitized_Request(url)
  596. # Set the header to get a partial html page with the ids,
  597. # the normal page doesn't contain them.
  598. request.add_header('X-Requested-With', 'XMLHttpRequest')
  599. return request
  600. def _real_extract(self, url):
  601. return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
  602. class VimeoLikesIE(InfoExtractor):
  603. _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
  604. IE_NAME = 'vimeo:likes'
  605. IE_DESC = 'Vimeo user likes'
  606. _TEST = {
  607. 'url': 'https://vimeo.com/user755559/likes/',
  608. 'playlist_mincount': 293,
  609. "info_dict": {
  610. 'id': 'user755559_likes',
  611. "description": "See all the videos urza likes",
  612. "title": 'Videos urza likes',
  613. },
  614. }
  615. def _real_extract(self, url):
  616. user_id = self._match_id(url)
  617. webpage = self._download_webpage(url, user_id)
  618. page_count = self._int(
  619. self._search_regex(
  620. r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
  621. .*?</a></li>\s*<li\s+class="pagination_next">
  622. ''', webpage, 'page count'),
  623. 'page count', fatal=True)
  624. PAGE_SIZE = 12
  625. title = self._html_search_regex(
  626. r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
  627. description = self._html_search_meta('description', webpage)
  628. def _get_page(idx):
  629. page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
  630. user_id, idx + 1)
  631. webpage = self._download_webpage(
  632. page_url, user_id,
  633. note='Downloading page %d/%d' % (idx + 1, page_count))
  634. video_list = self._search_regex(
  635. r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
  636. webpage, 'video content')
  637. paths = re.findall(
  638. r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
  639. for path in paths:
  640. yield {
  641. '_type': 'url',
  642. 'url': compat_urlparse.urljoin(page_url, path),
  643. }
  644. pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
  645. return {
  646. '_type': 'playlist',
  647. 'id': 'user%s_likes' % user_id,
  648. 'title': title,
  649. 'description': description,
  650. 'entries': pl,
  651. }