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.

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