vimeo.py 28 KB

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