vimeo.py 30 KB

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