You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

706 lines
28 KiB

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