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.

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