vimeo.py 33 KB

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