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.

689 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 = dict(re.findall(r'''(?x)<input\s+
  418. type="hidden"\s+
  419. name="([^"]+)"\s+
  420. value="([^"]*)"
  421. ''', login_form))
  422. token = self._search_regex(r'xsrft[\s=:"\']+([^"\']+)', webpage, 'login token')
  423. fields['token'] = token
  424. fields['password'] = password
  425. post = urlencode_postdata(fields)
  426. password_path = self._search_regex(
  427. r'action="([^"]+)"', login_form, 'password URL')
  428. password_url = compat_urlparse.urljoin(page_url, password_path)
  429. password_request = compat_urllib_request.Request(password_url, post)
  430. password_request.add_header('Content-type', 'application/x-www-form-urlencoded')
  431. self._set_cookie('vimeo.com', 'xsrft', token)
  432. return self._download_webpage(
  433. password_request, list_id,
  434. 'Verifying the password', 'Wrong password')
  435. def _extract_videos(self, list_id, base_url):
  436. video_ids = []
  437. for pagenum in itertools.count(1):
  438. page_url = self._page_url(base_url, pagenum)
  439. webpage = self._download_webpage(
  440. page_url, list_id,
  441. 'Downloading page %s' % pagenum)
  442. if pagenum == 1:
  443. webpage = self._login_list_password(page_url, list_id, webpage)
  444. video_ids.extend(re.findall(r'id="clip_(\d+?)"', webpage))
  445. if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
  446. break
  447. entries = [self.url_result('https://vimeo.com/%s' % video_id, 'Vimeo')
  448. for video_id in video_ids]
  449. return {'_type': 'playlist',
  450. 'id': list_id,
  451. 'title': self._extract_list_title(webpage),
  452. 'entries': entries,
  453. }
  454. def _real_extract(self, url):
  455. mobj = re.match(self._VALID_URL, url)
  456. channel_id = mobj.group('id')
  457. return self._extract_videos(channel_id, 'https://vimeo.com/channels/%s' % channel_id)
  458. class VimeoUserIE(VimeoChannelIE):
  459. IE_NAME = 'vimeo:user'
  460. _VALID_URL = r'https://vimeo\.com/(?![0-9]+(?:$|[?#/]))(?P<name>[^/]+)(?:/videos|[#?]|$)'
  461. _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
  462. _TESTS = [{
  463. 'url': 'https://vimeo.com/nkistudio/videos',
  464. 'info_dict': {
  465. 'title': 'Nki',
  466. 'id': 'nkistudio',
  467. },
  468. 'playlist_mincount': 66,
  469. }]
  470. def _real_extract(self, url):
  471. mobj = re.match(self._VALID_URL, url)
  472. name = mobj.group('name')
  473. return self._extract_videos(name, 'https://vimeo.com/%s' % name)
  474. class VimeoAlbumIE(VimeoChannelIE):
  475. IE_NAME = 'vimeo:album'
  476. _VALID_URL = r'https://vimeo\.com/album/(?P<id>\d+)'
  477. _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
  478. _TESTS = [{
  479. 'url': 'https://vimeo.com/album/2632481',
  480. 'info_dict': {
  481. 'id': '2632481',
  482. 'title': 'Staff Favorites: November 2013',
  483. },
  484. 'playlist_mincount': 13,
  485. }, {
  486. 'note': 'Password-protected album',
  487. 'url': 'https://vimeo.com/album/3253534',
  488. 'info_dict': {
  489. 'title': 'test',
  490. 'id': '3253534',
  491. },
  492. 'playlist_count': 1,
  493. 'params': {
  494. 'videopassword': 'youtube-dl',
  495. }
  496. }]
  497. def _page_url(self, base_url, pagenum):
  498. return '%s/page:%d/' % (base_url, pagenum)
  499. def _real_extract(self, url):
  500. album_id = self._match_id(url)
  501. return self._extract_videos(album_id, 'https://vimeo.com/album/%s' % album_id)
  502. class VimeoGroupsIE(VimeoAlbumIE):
  503. IE_NAME = 'vimeo:group'
  504. _VALID_URL = r'https://vimeo\.com/groups/(?P<name>[^/]+)'
  505. _TESTS = [{
  506. 'url': 'https://vimeo.com/groups/rolexawards',
  507. 'info_dict': {
  508. 'id': 'rolexawards',
  509. 'title': 'Rolex Awards for Enterprise',
  510. },
  511. 'playlist_mincount': 73,
  512. }]
  513. def _extract_list_title(self, webpage):
  514. return self._og_search_title(webpage)
  515. def _real_extract(self, url):
  516. mobj = re.match(self._VALID_URL, url)
  517. name = mobj.group('name')
  518. return self._extract_videos(name, 'https://vimeo.com/groups/%s' % name)
  519. class VimeoReviewIE(InfoExtractor):
  520. IE_NAME = 'vimeo:review'
  521. IE_DESC = 'Review pages on vimeo'
  522. _VALID_URL = r'https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)'
  523. _TESTS = [{
  524. 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
  525. 'md5': 'c507a72f780cacc12b2248bb4006d253',
  526. 'info_dict': {
  527. 'id': '75524534',
  528. 'ext': 'mp4',
  529. 'title': "DICK HARDWICK 'Comedian'",
  530. 'uploader': 'Richard Hardwick',
  531. }
  532. }, {
  533. 'note': 'video player needs Referer',
  534. 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
  535. 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
  536. 'info_dict': {
  537. 'id': '91613211',
  538. 'ext': 'mp4',
  539. 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
  540. 'uploader': 'DevWeek Events',
  541. 'duration': 2773,
  542. 'thumbnail': 're:^https?://.*\.jpg$',
  543. }
  544. }]
  545. def _real_extract(self, url):
  546. mobj = re.match(self._VALID_URL, url)
  547. video_id = mobj.group('id')
  548. player_url = 'https://player.vimeo.com/player/' + video_id
  549. return self.url_result(player_url, 'Vimeo', video_id)
  550. class VimeoWatchLaterIE(VimeoBaseInfoExtractor, VimeoChannelIE):
  551. IE_NAME = 'vimeo:watchlater'
  552. IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
  553. _VALID_URL = r'https://vimeo\.com/home/watchlater|:vimeowatchlater'
  554. _LOGIN_REQUIRED = True
  555. _TITLE_RE = r'href="/home/watchlater".*?>(.*?)<'
  556. _TESTS = [{
  557. 'url': 'https://vimeo.com/home/watchlater',
  558. 'only_matching': True,
  559. }]
  560. def _real_initialize(self):
  561. self._login()
  562. def _page_url(self, base_url, pagenum):
  563. url = '%s/page:%d/' % (base_url, pagenum)
  564. request = compat_urllib_request.Request(url)
  565. # Set the header to get a partial html page with the ids,
  566. # the normal page doesn't contain them.
  567. request.add_header('X-Requested-With', 'XMLHttpRequest')
  568. return request
  569. def _real_extract(self, url):
  570. return self._extract_videos('watchlater', 'https://vimeo.com/home/watchlater')
  571. class VimeoLikesIE(InfoExtractor):
  572. _VALID_URL = r'https://(?:www\.)?vimeo\.com/user(?P<id>[0-9]+)/likes/?(?:$|[?#]|sort:)'
  573. IE_NAME = 'vimeo:likes'
  574. IE_DESC = 'Vimeo user likes'
  575. _TEST = {
  576. 'url': 'https://vimeo.com/user755559/likes/',
  577. 'playlist_mincount': 293,
  578. "info_dict": {
  579. 'id': 'user755559_likes',
  580. "description": "See all the videos urza likes",
  581. "title": 'Videos urza likes',
  582. },
  583. }
  584. def _real_extract(self, url):
  585. user_id = self._match_id(url)
  586. webpage = self._download_webpage(url, user_id)
  587. page_count = self._int(
  588. self._search_regex(
  589. r'''(?x)<li><a\s+href="[^"]+"\s+data-page="([0-9]+)">
  590. .*?</a></li>\s*<li\s+class="pagination_next">
  591. ''', webpage, 'page count'),
  592. 'page count', fatal=True)
  593. PAGE_SIZE = 12
  594. title = self._html_search_regex(
  595. r'(?s)<h1>(.+?)</h1>', webpage, 'title', fatal=False)
  596. description = self._html_search_meta('description', webpage)
  597. def _get_page(idx):
  598. page_url = 'https://vimeo.com/user%s/likes/page:%d/sort:date' % (
  599. user_id, idx + 1)
  600. webpage = self._download_webpage(
  601. page_url, user_id,
  602. note='Downloading page %d/%d' % (idx + 1, page_count))
  603. video_list = self._search_regex(
  604. r'(?s)<ol class="js-browse_list[^"]+"[^>]*>(.*?)</ol>',
  605. webpage, 'video content')
  606. paths = re.findall(
  607. r'<li[^>]*>\s*<a\s+href="([^"]+)"', video_list)
  608. for path in paths:
  609. yield {
  610. '_type': 'url',
  611. 'url': compat_urlparse.urljoin(page_url, path),
  612. }
  613. pl = InAdvancePagedList(_get_page, page_count, PAGE_SIZE)
  614. return {
  615. '_type': 'playlist',
  616. 'id': 'user%s_likes' % user_id,
  617. 'title': title,
  618. 'description': description,
  619. 'entries': pl,
  620. }