vimeo.py 28 KB

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