vimeo.py 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. import functools
  5. import re
  6. import itertools
  7. from .common import InfoExtractor
  8. from ..compat import (
  9. compat_kwargs,
  10. compat_HTTPError,
  11. compat_str,
  12. compat_urlparse,
  13. )
  14. from ..utils import (
  15. clean_html,
  16. determine_ext,
  17. ExtractorError,
  18. get_element_by_class,
  19. js_to_json,
  20. int_or_none,
  21. merge_dicts,
  22. OnDemandPagedList,
  23. parse_filesize,
  24. parse_iso8601,
  25. sanitized_Request,
  26. smuggle_url,
  27. std_headers,
  28. str_or_none,
  29. try_get,
  30. unified_timestamp,
  31. unsmuggle_url,
  32. urlencode_postdata,
  33. urljoin,
  34. unescapeHTML,
  35. )
  36. class VimeoBaseInfoExtractor(InfoExtractor):
  37. _NETRC_MACHINE = 'vimeo'
  38. _LOGIN_REQUIRED = False
  39. _LOGIN_URL = 'https://vimeo.com/log_in'
  40. def _login(self):
  41. username, password = self._get_login_info()
  42. if username is None:
  43. if self._LOGIN_REQUIRED:
  44. raise ExtractorError('No login info available, needed for using %s.' % self.IE_NAME, expected=True)
  45. return
  46. webpage = self._download_webpage(
  47. self._LOGIN_URL, None, 'Downloading login page')
  48. token, vuid = self._extract_xsrft_and_vuid(webpage)
  49. data = {
  50. 'action': 'login',
  51. 'email': username,
  52. 'password': password,
  53. 'service': 'vimeo',
  54. 'token': token,
  55. }
  56. self._set_vimeo_cookie('vuid', vuid)
  57. try:
  58. self._download_webpage(
  59. self._LOGIN_URL, None, 'Logging in',
  60. data=urlencode_postdata(data), headers={
  61. 'Content-Type': 'application/x-www-form-urlencoded',
  62. 'Referer': self._LOGIN_URL,
  63. })
  64. except ExtractorError as e:
  65. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 418:
  66. raise ExtractorError(
  67. 'Unable to log in: bad username or password',
  68. expected=True)
  69. raise ExtractorError('Unable to log in')
  70. def _get_video_password(self):
  71. password = self._downloader.params.get('videopassword')
  72. if password is None:
  73. raise ExtractorError(
  74. 'This video is protected by a password, use the --video-password option',
  75. expected=True)
  76. return password
  77. def _verify_video_password(self, url, video_id, password, token, vuid):
  78. if url.startswith('http://'):
  79. # vimeo only supports https now, but the user can give an http url
  80. url = url.replace('http://', 'https://')
  81. self._set_vimeo_cookie('vuid', vuid)
  82. return self._download_webpage(
  83. url + '/password', video_id, 'Verifying the password',
  84. 'Wrong password', data=urlencode_postdata({
  85. 'password': password,
  86. 'token': token,
  87. }), headers={
  88. 'Content-Type': 'application/x-www-form-urlencoded',
  89. 'Referer': url,
  90. })
  91. def _extract_xsrft_and_vuid(self, webpage):
  92. xsrft = self._search_regex(
  93. r'(?:(?P<q1>["\'])xsrft(?P=q1)\s*:|xsrft\s*[=:])\s*(?P<q>["\'])(?P<xsrft>.+?)(?P=q)',
  94. webpage, 'login token', group='xsrft')
  95. vuid = self._search_regex(
  96. r'["\']vuid["\']\s*:\s*(["\'])(?P<vuid>.+?)\1',
  97. webpage, 'vuid', group='vuid')
  98. return xsrft, vuid
  99. def _extract_vimeo_config(self, webpage, video_id, *args, **kwargs):
  100. vimeo_config = self._search_regex(
  101. r'vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));',
  102. webpage, 'vimeo config', *args, **compat_kwargs(kwargs))
  103. if vimeo_config:
  104. return self._parse_json(vimeo_config, video_id)
  105. def _set_vimeo_cookie(self, name, value):
  106. self._set_cookie('vimeo.com', name, value)
  107. def _vimeo_sort_formats(self, formats):
  108. # Bitrates are completely broken. Single m3u8 may contain entries in kbps and bps
  109. # at the same time without actual units specified. This lead to wrong sorting.
  110. self._sort_formats(formats, field_preference=('preference', 'height', 'width', 'fps', 'tbr', 'format_id'))
  111. def _parse_config(self, config, video_id):
  112. video_data = config['video']
  113. video_title = video_data['title']
  114. live_event = video_data.get('live_event') or {}
  115. is_live = live_event.get('status') == 'started'
  116. request = config.get('request') or {}
  117. formats = []
  118. config_files = video_data.get('files') or request.get('files') or {}
  119. for f in (config_files.get('progressive') or []):
  120. video_url = f.get('url')
  121. if not video_url:
  122. continue
  123. formats.append({
  124. 'url': video_url,
  125. 'format_id': 'http-%s' % f.get('quality'),
  126. 'width': int_or_none(f.get('width')),
  127. 'height': int_or_none(f.get('height')),
  128. 'fps': int_or_none(f.get('fps')),
  129. 'tbr': int_or_none(f.get('bitrate')),
  130. })
  131. # TODO: fix handling of 308 status code returned for live archive manifest requests
  132. sep_pattern = r'/sep/video/'
  133. for files_type in ('hls', 'dash'):
  134. for cdn_name, cdn_data in (try_get(config_files, lambda x: x[files_type]['cdns']) or {}).items():
  135. manifest_url = cdn_data.get('url')
  136. if not manifest_url:
  137. continue
  138. format_id = '%s-%s' % (files_type, cdn_name)
  139. sep_manifest_urls = []
  140. if re.search(sep_pattern, manifest_url):
  141. for suffix, repl in (('', 'video'), ('_sep', 'sep/video')):
  142. sep_manifest_urls.append((format_id + suffix, re.sub(
  143. sep_pattern, '/%s/' % repl, manifest_url)))
  144. else:
  145. sep_manifest_urls = [(format_id, manifest_url)]
  146. for f_id, m_url in sep_manifest_urls:
  147. if files_type == 'hls':
  148. formats.extend(self._extract_m3u8_formats(
  149. m_url, video_id, 'mp4',
  150. 'm3u8' if is_live else 'm3u8_native', m3u8_id=f_id,
  151. note='Downloading %s m3u8 information' % cdn_name,
  152. fatal=False))
  153. elif files_type == 'dash':
  154. if 'json=1' in m_url:
  155. real_m_url = (self._download_json(m_url, video_id, fatal=False) or {}).get('url')
  156. if real_m_url:
  157. m_url = real_m_url
  158. mpd_formats = self._extract_mpd_formats(
  159. m_url.replace('/master.json', '/master.mpd'), video_id, f_id,
  160. 'Downloading %s MPD information' % cdn_name,
  161. fatal=False)
  162. formats.extend(mpd_formats)
  163. live_archive = live_event.get('archive') or {}
  164. live_archive_source_url = live_archive.get('source_url')
  165. if live_archive_source_url and live_archive.get('status') == 'done':
  166. formats.append({
  167. 'format_id': 'live-archive-source',
  168. 'url': live_archive_source_url,
  169. 'preference': 1,
  170. })
  171. for f in formats:
  172. if f.get('vcodec') == 'none':
  173. f['preference'] = -50
  174. elif f.get('acodec') == 'none':
  175. f['preference'] = -40
  176. subtitles = {}
  177. for tt in (request.get('text_tracks') or []):
  178. subtitles[tt['lang']] = [{
  179. 'ext': 'vtt',
  180. 'url': urljoin('https://vimeo.com', tt['url']),
  181. }]
  182. thumbnails = []
  183. if not is_live:
  184. for key, thumb in (video_data.get('thumbs') or {}).items():
  185. thumbnails.append({
  186. 'id': key,
  187. 'width': int_or_none(key),
  188. 'url': thumb,
  189. })
  190. thumbnail = video_data.get('thumbnail')
  191. if thumbnail:
  192. thumbnails.append({
  193. 'url': thumbnail,
  194. })
  195. owner = video_data.get('owner') or {}
  196. video_uploader_url = owner.get('url')
  197. return {
  198. 'id': str_or_none(video_data.get('id')) or video_id,
  199. 'title': self._live_title(video_title) if is_live else video_title,
  200. 'uploader': owner.get('name'),
  201. 'uploader_id': video_uploader_url.split('/')[-1] if video_uploader_url else None,
  202. 'uploader_url': video_uploader_url,
  203. 'thumbnails': thumbnails,
  204. 'duration': int_or_none(video_data.get('duration')),
  205. 'formats': formats,
  206. 'subtitles': subtitles,
  207. 'is_live': is_live,
  208. }
  209. def _extract_original_format(self, url, video_id, unlisted_hash=None):
  210. query = {'action': 'load_download_config'}
  211. if unlisted_hash:
  212. query['unlisted_hash'] = unlisted_hash
  213. download_data = self._download_json(
  214. url, video_id, fatal=False, query=query,
  215. headers={'X-Requested-With': 'XMLHttpRequest'})
  216. if download_data:
  217. source_file = download_data.get('source_file')
  218. if isinstance(source_file, dict):
  219. download_url = source_file.get('download_url')
  220. if download_url and not source_file.get('is_cold') and not source_file.get('is_defrosting'):
  221. source_name = source_file.get('public_name', 'Original')
  222. if self._is_valid_url(download_url, video_id, '%s video' % source_name):
  223. ext = (try_get(
  224. source_file, lambda x: x['extension'],
  225. compat_str) or determine_ext(
  226. download_url, None) or 'mp4').lower()
  227. return {
  228. 'url': download_url,
  229. 'ext': ext,
  230. 'width': int_or_none(source_file.get('width')),
  231. 'height': int_or_none(source_file.get('height')),
  232. 'filesize': parse_filesize(source_file.get('size')),
  233. 'format_id': source_name,
  234. 'preference': 1,
  235. }
  236. class VimeoIE(VimeoBaseInfoExtractor):
  237. """Information extractor for vimeo.com."""
  238. # _VALID_URL matches Vimeo URLs
  239. _VALID_URL = r'''(?x)
  240. https?://
  241. (?:
  242. (?:
  243. www|
  244. player
  245. )
  246. \.
  247. )?
  248. vimeo(?:pro)?\.com/
  249. (?!(?:channels|album|showcase)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/)
  250. (?:.*?/)?
  251. (?:
  252. (?:
  253. play_redirect_hls|
  254. moogaloop\.swf)\?clip_id=
  255. )?
  256. (?:videos?/)?
  257. (?P<id>[0-9]+)
  258. (?:/(?P<unlisted_hash>[\da-f]{10}))?
  259. /?(?:[?&].*)?(?:[#].*)?$
  260. '''
  261. IE_NAME = 'vimeo'
  262. _TESTS = [
  263. {
  264. 'url': 'http://vimeo.com/56015672#at=0',
  265. 'md5': '8879b6cc097e987f02484baf890129e5',
  266. 'info_dict': {
  267. 'id': '56015672',
  268. 'ext': 'mp4',
  269. 'title': "youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
  270. 'description': 'md5:2d3305bad981a06ff79f027f19865021',
  271. 'timestamp': 1355990239,
  272. 'upload_date': '20121220',
  273. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user7108434',
  274. 'uploader_id': 'user7108434',
  275. 'uploader': 'Filippo Valsorda',
  276. 'duration': 10,
  277. 'license': 'by-sa',
  278. },
  279. 'params': {
  280. 'format': 'best[protocol=https]',
  281. },
  282. },
  283. {
  284. 'url': 'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
  285. 'md5': '3b5ca6aa22b60dfeeadf50b72e44ed82',
  286. 'note': 'Vimeo Pro video (#1197)',
  287. 'info_dict': {
  288. 'id': '68093876',
  289. 'ext': 'mp4',
  290. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/openstreetmapus',
  291. 'uploader_id': 'openstreetmapus',
  292. 'uploader': 'OpenStreetMap US',
  293. 'title': 'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
  294. 'description': 'md5:2c362968038d4499f4d79f88458590c1',
  295. 'duration': 1595,
  296. 'upload_date': '20130610',
  297. 'timestamp': 1370893156,
  298. 'license': 'by',
  299. },
  300. 'params': {
  301. 'format': 'best[protocol=https]',
  302. },
  303. },
  304. {
  305. 'url': 'http://player.vimeo.com/video/54469442',
  306. 'md5': '619b811a4417aa4abe78dc653becf511',
  307. 'note': 'Videos that embed the url in the player page',
  308. 'info_dict': {
  309. 'id': '54469442',
  310. 'ext': 'mp4',
  311. 'title': 'Kathy Sierra: Building the minimum Badass User, Business of Software 2012',
  312. 'uploader': 'Business of Software',
  313. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/businessofsoftware',
  314. 'uploader_id': 'businessofsoftware',
  315. 'duration': 3610,
  316. 'description': None,
  317. },
  318. 'params': {
  319. 'format': 'best[protocol=https]',
  320. },
  321. 'expected_warnings': ['Unable to download JSON metadata'],
  322. },
  323. {
  324. 'url': 'http://vimeo.com/68375962',
  325. 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
  326. 'note': 'Video protected with password',
  327. 'info_dict': {
  328. 'id': '68375962',
  329. 'ext': 'mp4',
  330. 'title': 'youtube-dl password protected test video',
  331. 'timestamp': 1371200155,
  332. 'upload_date': '20130614',
  333. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
  334. 'uploader_id': 'user18948128',
  335. 'uploader': 'Jaime Marquínez Ferrándiz',
  336. 'duration': 10,
  337. 'description': 'md5:dca3ea23adb29ee387127bc4ddfce63f',
  338. },
  339. 'params': {
  340. 'format': 'best[protocol=https]',
  341. 'videopassword': 'youtube-dl',
  342. },
  343. },
  344. {
  345. 'url': 'http://vimeo.com/channels/keypeele/75629013',
  346. 'md5': '2f86a05afe9d7abc0b9126d229bbe15d',
  347. 'info_dict': {
  348. 'id': '75629013',
  349. 'ext': 'mp4',
  350. 'title': 'Key & Peele: Terrorist Interrogation',
  351. 'description': 'md5:8678b246399b070816b12313e8b4eb5c',
  352. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/atencio',
  353. 'uploader_id': 'atencio',
  354. 'uploader': 'Peter Atencio',
  355. 'channel_id': 'keypeele',
  356. 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/keypeele',
  357. 'timestamp': 1380339469,
  358. 'upload_date': '20130928',
  359. 'duration': 187,
  360. },
  361. 'expected_warnings': ['Unable to download JSON metadata'],
  362. },
  363. {
  364. 'url': 'http://vimeo.com/76979871',
  365. 'note': 'Video with subtitles',
  366. 'info_dict': {
  367. 'id': '76979871',
  368. 'ext': 'mp4',
  369. 'title': 'The New Vimeo Player (You Know, For Videos)',
  370. 'description': 'md5:2ec900bf97c3f389378a96aee11260ea',
  371. 'timestamp': 1381846109,
  372. 'upload_date': '20131015',
  373. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/staff',
  374. 'uploader_id': 'staff',
  375. 'uploader': 'Vimeo Staff',
  376. 'duration': 62,
  377. 'subtitles': {
  378. 'de': [{'ext': 'vtt'}],
  379. 'en': [{'ext': 'vtt'}],
  380. 'es': [{'ext': 'vtt'}],
  381. 'fr': [{'ext': 'vtt'}],
  382. },
  383. }
  384. },
  385. {
  386. # from https://www.ouya.tv/game/Pier-Solar-and-the-Great-Architects/
  387. 'url': 'https://player.vimeo.com/video/98044508',
  388. 'note': 'The js code contains assignments to the same variable as the config',
  389. 'info_dict': {
  390. 'id': '98044508',
  391. 'ext': 'mp4',
  392. 'title': 'Pier Solar OUYA Official Trailer',
  393. 'uploader': 'Tulio Gonçalves',
  394. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user28849593',
  395. 'uploader_id': 'user28849593',
  396. },
  397. },
  398. {
  399. # contains original format
  400. 'url': 'https://vimeo.com/33951933',
  401. 'md5': '53c688fa95a55bf4b7293d37a89c5c53',
  402. 'info_dict': {
  403. 'id': '33951933',
  404. 'ext': 'mp4',
  405. 'title': 'FOX CLASSICS - Forever Classic ID - A Full Minute',
  406. 'uploader': 'The DMCI',
  407. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/dmci',
  408. 'uploader_id': 'dmci',
  409. 'timestamp': 1324343742,
  410. 'upload_date': '20111220',
  411. 'description': 'md5:ae23671e82d05415868f7ad1aec21147',
  412. },
  413. },
  414. {
  415. # only available via https://vimeo.com/channels/tributes/6213729 and
  416. # not via https://vimeo.com/6213729
  417. 'url': 'https://vimeo.com/channels/tributes/6213729',
  418. 'info_dict': {
  419. 'id': '6213729',
  420. 'ext': 'mp4',
  421. 'title': 'Vimeo Tribute: The Shining',
  422. 'uploader': 'Casey Donahue',
  423. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/caseydonahue',
  424. 'uploader_id': 'caseydonahue',
  425. 'channel_url': r're:https?://(?:www\.)?vimeo\.com/channels/tributes',
  426. 'channel_id': 'tributes',
  427. 'timestamp': 1250886430,
  428. 'upload_date': '20090821',
  429. 'description': 'md5:bdbf314014e58713e6e5b66eb252f4a6',
  430. },
  431. 'params': {
  432. 'skip_download': True,
  433. },
  434. 'expected_warnings': ['Unable to download JSON metadata'],
  435. },
  436. {
  437. # redirects to ondemand extractor and should be passed through it
  438. # for successful extraction
  439. 'url': 'https://vimeo.com/73445910',
  440. 'info_dict': {
  441. 'id': '73445910',
  442. 'ext': 'mp4',
  443. 'title': 'The Reluctant Revolutionary',
  444. 'uploader': '10Ft Films',
  445. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/tenfootfilms',
  446. 'uploader_id': 'tenfootfilms',
  447. 'description': 'md5:0fa704e05b04f91f40b7f3ca2e801384',
  448. 'upload_date': '20130830',
  449. 'timestamp': 1377853339,
  450. },
  451. 'params': {
  452. 'skip_download': True,
  453. },
  454. 'expected_warnings': ['Unable to download JSON metadata'],
  455. 'skip': 'this page is no longer available.',
  456. },
  457. {
  458. 'url': 'http://player.vimeo.com/video/68375962',
  459. 'md5': 'aaf896bdb7ddd6476df50007a0ac0ae7',
  460. 'info_dict': {
  461. 'id': '68375962',
  462. 'ext': 'mp4',
  463. 'title': 'youtube-dl password protected test video',
  464. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/user18948128',
  465. 'uploader_id': 'user18948128',
  466. 'uploader': 'Jaime Marquínez Ferrándiz',
  467. 'duration': 10,
  468. },
  469. 'params': {
  470. 'format': 'best[protocol=https]',
  471. 'videopassword': 'youtube-dl',
  472. },
  473. },
  474. {
  475. 'url': 'http://vimeo.com/moogaloop.swf?clip_id=2539741',
  476. 'only_matching': True,
  477. },
  478. {
  479. 'url': 'https://vimeo.com/109815029',
  480. 'note': 'Video not completely processed, "failed" seed status',
  481. 'only_matching': True,
  482. },
  483. {
  484. 'url': 'https://vimeo.com/groups/travelhd/videos/22439234',
  485. 'only_matching': True,
  486. },
  487. {
  488. 'url': 'https://vimeo.com/album/2632481/video/79010983',
  489. 'only_matching': True,
  490. },
  491. {
  492. # source file returns 403: Forbidden
  493. 'url': 'https://vimeo.com/7809605',
  494. 'only_matching': True,
  495. },
  496. {
  497. 'url': 'https://vimeo.com/160743502/abd0e13fb4',
  498. 'only_matching': True,
  499. },
  500. {
  501. # requires passing unlisted_hash(a52724358e) to load_download_config request
  502. 'url': 'https://vimeo.com/392479337/a52724358e',
  503. 'only_matching': True,
  504. }
  505. # https://gettingthingsdone.com/workflowmap/
  506. # vimeo embed with check-password page protected by Referer header
  507. ]
  508. @staticmethod
  509. def _smuggle_referrer(url, referrer_url):
  510. return smuggle_url(url, {'http_headers': {'Referer': referrer_url}})
  511. @staticmethod
  512. def _extract_urls(url, webpage):
  513. urls = []
  514. # Look for embedded (iframe) Vimeo player
  515. for mobj in re.finditer(
  516. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/\d+.*?)\1',
  517. webpage):
  518. urls.append(VimeoIE._smuggle_referrer(unescapeHTML(mobj.group('url')), url))
  519. PLAIN_EMBED_RE = (
  520. # Look for embedded (swf embed) Vimeo player
  521. r'<embed[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)\1',
  522. # Look more for non-standard embedded Vimeo player
  523. r'<video[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)\1',
  524. )
  525. for embed_re in PLAIN_EMBED_RE:
  526. for mobj in re.finditer(embed_re, webpage):
  527. urls.append(mobj.group('url'))
  528. return urls
  529. @staticmethod
  530. def _extract_url(url, webpage):
  531. urls = VimeoIE._extract_urls(url, webpage)
  532. return urls[0] if urls else None
  533. def _verify_player_video_password(self, url, video_id, headers):
  534. password = self._get_video_password()
  535. data = urlencode_postdata({
  536. 'password': base64.b64encode(password.encode()),
  537. })
  538. headers = merge_dicts(headers, {
  539. 'Content-Type': 'application/x-www-form-urlencoded',
  540. })
  541. checked = self._download_json(
  542. url + '/check-password', video_id,
  543. 'Verifying the password', data=data, headers=headers)
  544. if checked is False:
  545. raise ExtractorError('Wrong video password', expected=True)
  546. return checked
  547. def _real_initialize(self):
  548. self._login()
  549. def _extract_from_api(self, video_id, unlisted_hash=None):
  550. token = self._download_json(
  551. 'https://vimeo.com/_rv/jwt', video_id, headers={
  552. 'X-Requested-With': 'XMLHttpRequest'
  553. })['token']
  554. api_url = 'https://api.vimeo.com/videos/' + video_id
  555. if unlisted_hash:
  556. api_url += ':' + unlisted_hash
  557. video = self._download_json(
  558. api_url, video_id, headers={
  559. 'Authorization': 'jwt ' + token,
  560. }, query={
  561. 'fields': 'config_url,created_time,description,license,metadata.connections.comments.total,metadata.connections.likes.total,release_time,stats.plays',
  562. })
  563. info = self._parse_config(self._download_json(
  564. video['config_url'], video_id), video_id)
  565. self._vimeo_sort_formats(info['formats'])
  566. get_timestamp = lambda x: parse_iso8601(video.get(x + '_time'))
  567. info.update({
  568. 'description': video.get('description'),
  569. 'license': video.get('license'),
  570. 'release_timestamp': get_timestamp('release'),
  571. 'timestamp': get_timestamp('created'),
  572. 'view_count': int_or_none(try_get(video, lambda x: x['stats']['plays'])),
  573. })
  574. connections = try_get(
  575. video, lambda x: x['metadata']['connections'], dict) or {}
  576. for k in ('comment', 'like'):
  577. info[k + '_count'] = int_or_none(try_get(connections, lambda x: x[k + 's']['total']))
  578. return info
  579. def _real_extract(self, url):
  580. url, data = unsmuggle_url(url, {})
  581. headers = std_headers.copy()
  582. if 'http_headers' in data:
  583. headers.update(data['http_headers'])
  584. if 'Referer' not in headers:
  585. headers['Referer'] = url
  586. mobj = re.match(self._VALID_URL, url).groupdict()
  587. video_id, unlisted_hash = mobj['id'], mobj.get('unlisted_hash')
  588. if unlisted_hash:
  589. return self._extract_from_api(video_id, unlisted_hash)
  590. orig_url = url
  591. is_pro = 'vimeopro.com/' in url
  592. if is_pro:
  593. # some videos require portfolio_id to be present in player url
  594. # https://github.com/ytdl-org/youtube-dl/issues/20070
  595. url = self._extract_url(url, self._download_webpage(url, video_id))
  596. if not url:
  597. url = 'https://vimeo.com/' + video_id
  598. elif any(p in url for p in ('play_redirect_hls', 'moogaloop.swf')):
  599. url = 'https://vimeo.com/' + video_id
  600. try:
  601. # Retrieve video webpage to extract further information
  602. webpage, urlh = self._download_webpage_handle(
  603. url, video_id, headers=headers)
  604. redirect_url = urlh.geturl()
  605. except ExtractorError as ee:
  606. if isinstance(ee.cause, compat_HTTPError) and ee.cause.code == 403:
  607. errmsg = ee.cause.read()
  608. if b'Because of its privacy settings, this video cannot be played here' in errmsg:
  609. raise ExtractorError(
  610. 'Cannot download embed-only video without embedding '
  611. 'URL. Please call youtube-dl with the URL of the page '
  612. 'that embeds this video.',
  613. expected=True)
  614. raise
  615. if '://player.vimeo.com/video/' in url:
  616. config = self._parse_json(self._search_regex(
  617. r'\bconfig\s*=\s*({.+?})\s*;', webpage, 'info section'), video_id)
  618. if config.get('view') == 4:
  619. config = self._verify_player_video_password(
  620. redirect_url, video_id, headers)
  621. info = self._parse_config(config, video_id)
  622. self._vimeo_sort_formats(info['formats'])
  623. return info
  624. if re.search(r'<form[^>]+?id="pw_form"', webpage):
  625. video_password = self._get_video_password()
  626. token, vuid = self._extract_xsrft_and_vuid(webpage)
  627. webpage = self._verify_video_password(
  628. redirect_url, video_id, video_password, token, vuid)
  629. vimeo_config = self._extract_vimeo_config(webpage, video_id, default=None)
  630. if vimeo_config:
  631. seed_status = vimeo_config.get('seed_status') or {}
  632. if seed_status.get('state') == 'failed':
  633. raise ExtractorError(
  634. '%s said: %s' % (self.IE_NAME, seed_status['title']),
  635. expected=True)
  636. cc_license = None
  637. timestamp = None
  638. video_description = None
  639. info_dict = {}
  640. channel_id = self._search_regex(
  641. r'vimeo\.com/channels/([^/]+)', url, 'channel id', default=None)
  642. if channel_id:
  643. config_url = self._html_search_regex(
  644. r'\bdata-config-url="([^"]+)"', webpage, 'config URL')
  645. video_description = clean_html(get_element_by_class('description', webpage))
  646. info_dict.update({
  647. 'channel_id': channel_id,
  648. 'channel_url': 'https://vimeo.com/channels/' + channel_id,
  649. })
  650. else:
  651. page_config = self._parse_json(self._search_regex(
  652. r'vimeo\.(?:clip|vod_title)_page_config\s*=\s*({.+?});',
  653. webpage, 'page config', default='{}'), video_id, fatal=False)
  654. if not page_config:
  655. return self._extract_from_api(video_id)
  656. config_url = page_config['player']['config_url']
  657. cc_license = page_config.get('cc_license')
  658. clip = page_config.get('clip') or {}
  659. timestamp = clip.get('uploaded_on')
  660. video_description = clean_html(
  661. clip.get('description') or page_config.get('description_html_escaped'))
  662. config = self._download_json(config_url, video_id)
  663. video = config.get('video') or {}
  664. vod = video.get('vod') or {}
  665. def is_rented():
  666. if '>You rented this title.<' in webpage:
  667. return True
  668. if try_get(config, lambda x: x['user']['purchased']):
  669. return True
  670. for purchase_option in (vod.get('purchase_options') or []):
  671. if purchase_option.get('purchased'):
  672. return True
  673. label = purchase_option.get('label_string')
  674. if label and (label.startswith('You rented this') or label.endswith(' remaining')):
  675. return True
  676. return False
  677. if is_rented() and vod.get('is_trailer'):
  678. feature_id = vod.get('feature_id')
  679. if feature_id and not data.get('force_feature_id', False):
  680. return self.url_result(smuggle_url(
  681. 'https://player.vimeo.com/player/%s' % feature_id,
  682. {'force_feature_id': True}), 'Vimeo')
  683. if not video_description:
  684. video_description = self._html_search_meta(
  685. ['description', 'og:description', 'twitter:description'],
  686. webpage, default=None)
  687. if not video_description and is_pro:
  688. orig_webpage = self._download_webpage(
  689. orig_url, video_id,
  690. note='Downloading webpage for description',
  691. fatal=False)
  692. if orig_webpage:
  693. video_description = self._html_search_meta(
  694. 'description', orig_webpage, default=None)
  695. if not video_description:
  696. self._downloader.report_warning('Cannot find video description')
  697. if not timestamp:
  698. timestamp = self._search_regex(
  699. r'<time[^>]+datetime="([^"]+)"', webpage,
  700. 'timestamp', default=None)
  701. formats = []
  702. source_format = self._extract_original_format(
  703. 'https://vimeo.com/' + video_id, video_id, video.get('unlisted_hash'))
  704. if source_format:
  705. formats.append(source_format)
  706. info_dict_config = self._parse_config(config, video_id)
  707. formats.extend(info_dict_config['formats'])
  708. self._vimeo_sort_formats(formats)
  709. json_ld = self._search_json_ld(webpage, video_id, default={})
  710. if not cc_license:
  711. cc_license = self._search_regex(
  712. r'<link[^>]+rel=["\']license["\'][^>]+href=(["\'])(?P<license>(?:(?!\1).)+)\1',
  713. webpage, 'license', default=None, group='license')
  714. info_dict.update({
  715. 'formats': formats,
  716. 'timestamp': unified_timestamp(timestamp),
  717. 'description': video_description,
  718. 'webpage_url': url,
  719. 'license': cc_license,
  720. })
  721. return merge_dicts(info_dict, info_dict_config, json_ld)
  722. class VimeoOndemandIE(VimeoIE):
  723. IE_NAME = 'vimeo:ondemand'
  724. _VALID_URL = r'https?://(?:www\.)?vimeo\.com/ondemand/(?:[^/]+/)?(?P<id>[^/?#&]+)'
  725. _TESTS = [{
  726. # ondemand video not available via https://vimeo.com/id
  727. 'url': 'https://vimeo.com/ondemand/20704',
  728. 'md5': 'c424deda8c7f73c1dfb3edd7630e2f35',
  729. 'info_dict': {
  730. 'id': '105442900',
  731. 'ext': 'mp4',
  732. 'title': 'המעבדה - במאי יותם פלדמן',
  733. 'uploader': 'גם סרטים',
  734. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/gumfilms',
  735. 'uploader_id': 'gumfilms',
  736. 'description': 'md5:4c027c965e439de4baab621e48b60791',
  737. 'upload_date': '20140906',
  738. 'timestamp': 1410032453,
  739. },
  740. 'params': {
  741. 'format': 'best[protocol=https]',
  742. },
  743. 'expected_warnings': ['Unable to download JSON metadata'],
  744. }, {
  745. # requires Referer to be passed along with og:video:url
  746. 'url': 'https://vimeo.com/ondemand/36938/126682985',
  747. 'info_dict': {
  748. 'id': '126584684',
  749. 'ext': 'mp4',
  750. 'title': 'Rävlock, rätt läte på rätt plats',
  751. 'uploader': 'Lindroth & Norin',
  752. 'uploader_url': r're:https?://(?:www\.)?vimeo\.com/lindrothnorin',
  753. 'uploader_id': 'lindrothnorin',
  754. 'description': 'md5:c3c46a90529612c8279fb6af803fc0df',
  755. 'upload_date': '20150502',
  756. 'timestamp': 1430586422,
  757. },
  758. 'params': {
  759. 'skip_download': True,
  760. },
  761. 'expected_warnings': ['Unable to download JSON metadata'],
  762. }, {
  763. 'url': 'https://vimeo.com/ondemand/nazmaalik',
  764. 'only_matching': True,
  765. }, {
  766. 'url': 'https://vimeo.com/ondemand/141692381',
  767. 'only_matching': True,
  768. }, {
  769. 'url': 'https://vimeo.com/ondemand/thelastcolony/150274832',
  770. 'only_matching': True,
  771. }]
  772. class VimeoChannelIE(VimeoBaseInfoExtractor):
  773. IE_NAME = 'vimeo:channel'
  774. _VALID_URL = r'https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])'
  775. _MORE_PAGES_INDICATOR = r'<a.+?rel="next"'
  776. _TITLE = None
  777. _TITLE_RE = r'<link rel="alternate"[^>]+?title="(.*?)"'
  778. _TESTS = [{
  779. 'url': 'https://vimeo.com/channels/tributes',
  780. 'info_dict': {
  781. 'id': 'tributes',
  782. 'title': 'Vimeo Tributes',
  783. },
  784. 'playlist_mincount': 25,
  785. }]
  786. _BASE_URL_TEMPL = 'https://vimeo.com/channels/%s'
  787. def _page_url(self, base_url, pagenum):
  788. return '%s/videos/page:%d/' % (base_url, pagenum)
  789. def _extract_list_title(self, webpage):
  790. return self._TITLE or self._html_search_regex(
  791. self._TITLE_RE, webpage, 'list title', fatal=False)
  792. def _title_and_entries(self, list_id, base_url):
  793. for pagenum in itertools.count(1):
  794. page_url = self._page_url(base_url, pagenum)
  795. webpage = self._download_webpage(
  796. page_url, list_id,
  797. 'Downloading page %s' % pagenum)
  798. if pagenum == 1:
  799. yield self._extract_list_title(webpage)
  800. # Try extracting href first since not all videos are available via
  801. # short https://vimeo.com/id URL (e.g. https://vimeo.com/channels/tributes/6213729)
  802. clips = re.findall(
  803. r'id="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)(?:[^>]+\btitle="([^"]+)")?', webpage)
  804. if clips:
  805. for video_id, video_url, video_title in clips:
  806. yield self.url_result(
  807. compat_urlparse.urljoin(base_url, video_url),
  808. VimeoIE.ie_key(), video_id=video_id, video_title=video_title)
  809. # More relaxed fallback
  810. else:
  811. for video_id in re.findall(r'id=["\']clip_(\d+)', webpage):
  812. yield self.url_result(
  813. 'https://vimeo.com/%s' % video_id,
  814. VimeoIE.ie_key(), video_id=video_id)
  815. if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
  816. break
  817. def _extract_videos(self, list_id, base_url):
  818. title_and_entries = self._title_and_entries(list_id, base_url)
  819. list_title = next(title_and_entries)
  820. return self.playlist_result(title_and_entries, list_id, list_title)
  821. def _real_extract(self, url):
  822. channel_id = self._match_id(url)
  823. return self._extract_videos(channel_id, self._BASE_URL_TEMPL % channel_id)
  824. class VimeoUserIE(VimeoChannelIE):
  825. IE_NAME = 'vimeo:user'
  826. _VALID_URL = r'https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<id>[^/]+)(?:/videos|[#?]|$)'
  827. _TITLE_RE = r'<a[^>]+?class="user">([^<>]+?)</a>'
  828. _TESTS = [{
  829. 'url': 'https://vimeo.com/nkistudio/videos',
  830. 'info_dict': {
  831. 'title': 'Nki',
  832. 'id': 'nkistudio',
  833. },
  834. 'playlist_mincount': 66,
  835. }]
  836. _BASE_URL_TEMPL = 'https://vimeo.com/%s'
  837. class VimeoAlbumIE(VimeoBaseInfoExtractor):
  838. IE_NAME = 'vimeo:album'
  839. _VALID_URL = r'https://vimeo\.com/(?:album|showcase)/(?P<id>\d+)(?:$|[?#]|/(?!video))'
  840. _TITLE_RE = r'<header id="page_header">\n\s*<h1>(.*?)</h1>'
  841. _TESTS = [{
  842. 'url': 'https://vimeo.com/album/2632481',
  843. 'info_dict': {
  844. 'id': '2632481',
  845. 'title': 'Staff Favorites: November 2013',
  846. },
  847. 'playlist_mincount': 13,
  848. }, {
  849. 'note': 'Password-protected album',
  850. 'url': 'https://vimeo.com/album/3253534',
  851. 'info_dict': {
  852. 'title': 'test',
  853. 'id': '3253534',
  854. },
  855. 'playlist_count': 1,
  856. 'params': {
  857. 'videopassword': 'youtube-dl',
  858. }
  859. }]
  860. _PAGE_SIZE = 100
  861. def _fetch_page(self, album_id, authorization, hashed_pass, page):
  862. api_page = page + 1
  863. query = {
  864. 'fields': 'link,uri',
  865. 'page': api_page,
  866. 'per_page': self._PAGE_SIZE,
  867. }
  868. if hashed_pass:
  869. query['_hashed_pass'] = hashed_pass
  870. try:
  871. videos = self._download_json(
  872. 'https://api.vimeo.com/albums/%s/videos' % album_id,
  873. album_id, 'Downloading page %d' % api_page, query=query, headers={
  874. 'Authorization': 'jwt ' + authorization,
  875. })['data']
  876. except ExtractorError as e:
  877. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  878. return
  879. for video in videos:
  880. link = video.get('link')
  881. if not link:
  882. continue
  883. uri = video.get('uri')
  884. video_id = self._search_regex(r'/videos/(\d+)', uri, 'video_id', default=None) if uri else None
  885. yield self.url_result(link, VimeoIE.ie_key(), video_id)
  886. def _real_extract(self, url):
  887. album_id = self._match_id(url)
  888. viewer = self._download_json(
  889. 'https://vimeo.com/_rv/viewer', album_id, fatal=False)
  890. if not viewer:
  891. webpage = self._download_webpage(url, album_id)
  892. viewer = self._parse_json(self._search_regex(
  893. r'bootstrap_data\s*=\s*({.+?})</script>',
  894. webpage, 'bootstrap data'), album_id)['viewer']
  895. jwt = viewer['jwt']
  896. album = self._download_json(
  897. 'https://api.vimeo.com/albums/' + album_id,
  898. album_id, headers={'Authorization': 'jwt ' + jwt},
  899. query={'fields': 'description,name,privacy'})
  900. hashed_pass = None
  901. if try_get(album, lambda x: x['privacy']['view']) == 'password':
  902. password = self._downloader.params.get('videopassword')
  903. if not password:
  904. raise ExtractorError(
  905. 'This album is protected by a password, use the --video-password option',
  906. expected=True)
  907. self._set_vimeo_cookie('vuid', viewer['vuid'])
  908. try:
  909. hashed_pass = self._download_json(
  910. 'https://vimeo.com/showcase/%s/auth' % album_id,
  911. album_id, 'Verifying the password', data=urlencode_postdata({
  912. 'password': password,
  913. 'token': viewer['xsrft'],
  914. }), headers={
  915. 'X-Requested-With': 'XMLHttpRequest',
  916. })['hashed_pass']
  917. except ExtractorError as e:
  918. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
  919. raise ExtractorError('Wrong password', expected=True)
  920. raise
  921. entries = OnDemandPagedList(functools.partial(
  922. self._fetch_page, album_id, jwt, hashed_pass), self._PAGE_SIZE)
  923. return self.playlist_result(
  924. entries, album_id, album.get('name'), album.get('description'))
  925. class VimeoGroupsIE(VimeoChannelIE):
  926. IE_NAME = 'vimeo:group'
  927. _VALID_URL = r'https://vimeo\.com/groups/(?P<id>[^/]+)(?:/(?!videos?/\d+)|$)'
  928. _TESTS = [{
  929. 'url': 'https://vimeo.com/groups/kattykay',
  930. 'info_dict': {
  931. 'id': 'kattykay',
  932. 'title': 'Katty Kay',
  933. },
  934. 'playlist_mincount': 27,
  935. }]
  936. _BASE_URL_TEMPL = 'https://vimeo.com/groups/%s'
  937. class VimeoReviewIE(VimeoBaseInfoExtractor):
  938. IE_NAME = 'vimeo:review'
  939. IE_DESC = 'Review pages on vimeo'
  940. _VALID_URL = r'(?P<url>https://vimeo\.com/[^/]+/review/(?P<id>[^/]+)/[0-9a-f]{10})'
  941. _TESTS = [{
  942. 'url': 'https://vimeo.com/user21297594/review/75524534/3c257a1b5d',
  943. 'md5': 'c507a72f780cacc12b2248bb4006d253',
  944. 'info_dict': {
  945. 'id': '75524534',
  946. 'ext': 'mp4',
  947. 'title': "DICK HARDWICK 'Comedian'",
  948. 'uploader': 'Richard Hardwick',
  949. 'uploader_id': 'user21297594',
  950. 'description': "Comedian Dick Hardwick's five minute demo filmed in front of a live theater audience.\nEdit by Doug Mattocks",
  951. },
  952. 'expected_warnings': ['Unable to download JSON metadata'],
  953. }, {
  954. 'note': 'video player needs Referer',
  955. 'url': 'https://vimeo.com/user22258446/review/91613211/13f927e053',
  956. 'md5': '6295fdab8f4bf6a002d058b2c6dce276',
  957. 'info_dict': {
  958. 'id': '91613211',
  959. 'ext': 'mp4',
  960. 'title': 're:(?i)^Death by dogma versus assembling agile . Sander Hoogendoorn',
  961. 'uploader': 'DevWeek Events',
  962. 'duration': 2773,
  963. 'thumbnail': r're:^https?://.*\.jpg$',
  964. 'uploader_id': 'user22258446',
  965. },
  966. 'skip': 'video gone',
  967. }, {
  968. 'note': 'Password protected',
  969. 'url': 'https://vimeo.com/user37284429/review/138823582/c4d865efde',
  970. 'info_dict': {
  971. 'id': '138823582',
  972. 'ext': 'mp4',
  973. 'title': 'EFFICIENT PICKUP MASTERCLASS MODULE 1',
  974. 'uploader': 'TMB',
  975. 'uploader_id': 'user37284429',
  976. },
  977. 'params': {
  978. 'videopassword': 'holygrail',
  979. },
  980. 'skip': 'video gone',
  981. }]
  982. def _real_initialize(self):
  983. self._login()
  984. def _real_extract(self, url):
  985. page_url, video_id = re.match(self._VALID_URL, url).groups()
  986. data = self._download_json(
  987. page_url.replace('/review/', '/review/data/'), video_id)
  988. if data.get('isLocked') is True:
  989. video_password = self._get_video_password()
  990. viewer = self._download_json(
  991. 'https://vimeo.com/_rv/viewer', video_id)
  992. webpage = self._verify_video_password(
  993. 'https://vimeo.com/' + video_id, video_id,
  994. video_password, viewer['xsrft'], viewer['vuid'])
  995. clip_page_config = self._parse_json(self._search_regex(
  996. r'window\.vimeo\.clip_page_config\s*=\s*({.+?});',
  997. webpage, 'clip page config'), video_id)
  998. config_url = clip_page_config['player']['config_url']
  999. clip_data = clip_page_config.get('clip') or {}
  1000. else:
  1001. clip_data = data['clipData']
  1002. config_url = clip_data['configUrl']
  1003. config = self._download_json(config_url, video_id)
  1004. info_dict = self._parse_config(config, video_id)
  1005. source_format = self._extract_original_format(
  1006. page_url + '/action', video_id)
  1007. if source_format:
  1008. info_dict['formats'].append(source_format)
  1009. self._vimeo_sort_formats(info_dict['formats'])
  1010. info_dict['description'] = clean_html(clip_data.get('description'))
  1011. return info_dict
  1012. class VimeoWatchLaterIE(VimeoChannelIE):
  1013. IE_NAME = 'vimeo:watchlater'
  1014. IE_DESC = 'Vimeo watch later list, "vimeowatchlater" keyword (requires authentication)'
  1015. _VALID_URL = r'https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlater'
  1016. _TITLE = 'Watch Later'
  1017. _LOGIN_REQUIRED = True
  1018. _TESTS = [{
  1019. 'url': 'https://vimeo.com/watchlater',
  1020. 'only_matching': True,
  1021. }]
  1022. def _real_initialize(self):
  1023. self._login()
  1024. def _page_url(self, base_url, pagenum):
  1025. url = '%s/page:%d/' % (base_url, pagenum)
  1026. request = sanitized_Request(url)
  1027. # Set the header to get a partial html page with the ids,
  1028. # the normal page doesn't contain them.
  1029. request.add_header('X-Requested-With', 'XMLHttpRequest')
  1030. return request
  1031. def _real_extract(self, url):
  1032. return self._extract_videos('watchlater', 'https://vimeo.com/watchlater')
  1033. class VimeoLikesIE(VimeoChannelIE):
  1034. _VALID_URL = r'https://(?:www\.)?vimeo\.com/(?P<id>[^/]+)/likes/?(?:$|[?#]|sort:)'
  1035. IE_NAME = 'vimeo:likes'
  1036. IE_DESC = 'Vimeo user likes'
  1037. _TESTS = [{
  1038. 'url': 'https://vimeo.com/user755559/likes/',
  1039. 'playlist_mincount': 293,
  1040. 'info_dict': {
  1041. 'id': 'user755559',
  1042. 'title': 'urza’s Likes',
  1043. },
  1044. }, {
  1045. 'url': 'https://vimeo.com/stormlapse/likes',
  1046. 'only_matching': True,
  1047. }]
  1048. def _page_url(self, base_url, pagenum):
  1049. return '%s/page:%d/' % (base_url, pagenum)
  1050. def _real_extract(self, url):
  1051. user_id = self._match_id(url)
  1052. return self._extract_videos(user_id, 'https://vimeo.com/%s/likes' % user_id)
  1053. class VHXEmbedIE(VimeoBaseInfoExtractor):
  1054. IE_NAME = 'vhx:embed'
  1055. _VALID_URL = r'https?://embed\.vhx\.tv/videos/(?P<id>\d+)'
  1056. @staticmethod
  1057. def _extract_url(webpage):
  1058. mobj = re.search(
  1059. r'<iframe[^>]+src="(https?://embed\.vhx\.tv/videos/\d+[^"]*)"', webpage)
  1060. return unescapeHTML(mobj.group(1)) if mobj else None
  1061. def _real_extract(self, url):
  1062. video_id = self._match_id(url)
  1063. webpage = self._download_webpage(url, video_id)
  1064. config_url = self._parse_json(self._search_regex(
  1065. r'window\.OTTData\s*=\s*({.+})', webpage,
  1066. 'ott data'), video_id, js_to_json)['config_url']
  1067. config = self._download_json(config_url, video_id)
  1068. info = self._parse_config(config, video_id)
  1069. info['id'] = video_id
  1070. self._vimeo_sort_formats(info['formats'])
  1071. return info