vimeo.py 28 KB

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