You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.7 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. parse_iso8601,
  8. sanitized_Request,
  9. )
  10. class VesselIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?vessel\.com/videos/(?P<id>[0-9a-zA-Z]+)'
  12. _API_URL_TEMPLATE = 'https://www.vessel.com/api/view/items/%s'
  13. _LOGIN_URL = 'https://www.vessel.com/api/account/login'
  14. _NETRC_MACHINE = 'vessel'
  15. _TEST = {
  16. 'url': 'https://www.vessel.com/videos/HDN7G5UMs',
  17. 'md5': '455cdf8beb71c6dd797fd2f3818d05c4',
  18. 'info_dict': {
  19. 'id': 'HDN7G5UMs',
  20. 'ext': 'mp4',
  21. 'title': 'Nvidia GeForce GTX Titan X - The Best Video Card on the Market?',
  22. 'thumbnail': 're:^https?://.*\.jpg$',
  23. 'upload_date': '20150317',
  24. 'description': 'Did Nvidia pull out all the stops on the Titan X, or does its performance leave something to be desired?',
  25. 'timestamp': int,
  26. },
  27. }
  28. @staticmethod
  29. def make_json_request(url, data):
  30. payload = json.dumps(data).encode('utf-8')
  31. req = sanitized_Request(url, payload)
  32. req.add_header('Content-Type', 'application/json; charset=utf-8')
  33. return req
  34. @staticmethod
  35. def find_assets(data, asset_type, asset_id=None):
  36. for asset in data.get('assets', []):
  37. if not asset.get('type') == asset_type:
  38. continue
  39. elif asset_id is not None and not asset.get('id') == asset_id:
  40. continue
  41. else:
  42. yield asset
  43. def _check_access_rights(self, data):
  44. access_info = data.get('__view', {})
  45. if not access_info.get('allow_access', True):
  46. err_code = access_info.get('error_code') or ''
  47. if err_code == 'ITEM_PAID_ONLY':
  48. raise ExtractorError(
  49. 'This video requires subscription.', expected=True)
  50. else:
  51. raise ExtractorError(
  52. 'Access to this content is restricted. (%s said: %s)' % (self.IE_NAME, err_code), expected=True)
  53. def _login(self):
  54. (username, password) = self._get_login_info()
  55. if username is None:
  56. return
  57. self.report_login()
  58. data = {
  59. 'client_id': 'web',
  60. 'type': 'password',
  61. 'user_key': username,
  62. 'password': password,
  63. }
  64. login_request = VesselIE.make_json_request(self._LOGIN_URL, data)
  65. self._download_webpage(login_request, None, False, 'Wrong login info')
  66. def _real_initialize(self):
  67. self._login()
  68. def _real_extract(self, url):
  69. video_id = self._match_id(url)
  70. webpage = self._download_webpage(url, video_id)
  71. data = self._parse_json(self._search_regex(
  72. r'App\.bootstrapData\((.*?)\);', webpage, 'data'), video_id)
  73. asset_id = data['model']['data']['id']
  74. req = VesselIE.make_json_request(
  75. self._API_URL_TEMPLATE % asset_id, {'client': 'web'})
  76. data = self._download_json(req, video_id)
  77. video_asset_id = data.get('main_video_asset')
  78. self._check_access_rights(data)
  79. try:
  80. video_asset = next(
  81. VesselIE.find_assets(data, 'video', asset_id=video_asset_id))
  82. except StopIteration:
  83. raise ExtractorError('No video assets found')
  84. formats = []
  85. for f in video_asset.get('sources', []):
  86. if f['name'] == 'hls-index':
  87. formats.extend(self._extract_m3u8_formats(
  88. f['location'], video_id, ext='mp4', m3u8_id='m3u8'))
  89. else:
  90. formats.append({
  91. 'format_id': f['name'],
  92. 'tbr': f.get('bitrate'),
  93. 'height': f.get('height'),
  94. 'width': f.get('width'),
  95. 'url': f['location'],
  96. })
  97. self._sort_formats(formats)
  98. thumbnails = []
  99. for im_asset in VesselIE.find_assets(data, 'image'):
  100. thumbnails.append({
  101. 'url': im_asset['location'],
  102. 'width': im_asset.get('width', 0),
  103. 'height': im_asset.get('height', 0),
  104. })
  105. return {
  106. 'id': video_id,
  107. 'title': data['title'],
  108. 'formats': formats,
  109. 'thumbnails': thumbnails,
  110. 'description': data.get('short_description'),
  111. 'duration': data.get('duration'),
  112. 'comment_count': data.get('comment_count'),
  113. 'like_count': data.get('like_count'),
  114. 'view_count': data.get('view_count'),
  115. 'timestamp': parse_iso8601(data.get('released_at')),
  116. }