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.

151 lines
5.3 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. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. ExtractorError,
  8. parse_iso8601,
  9. sanitized_Request,
  10. )
  11. class VesselIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?vessel\.com/(?:videos|embed)/(?P<id>[0-9a-zA-Z]+)'
  13. _API_URL_TEMPLATE = 'https://www.vessel.com/api/view/items/%s'
  14. _LOGIN_URL = 'https://www.vessel.com/api/account/login'
  15. _NETRC_MACHINE = 'vessel'
  16. _TESTS = [{
  17. 'url': 'https://www.vessel.com/videos/HDN7G5UMs',
  18. 'md5': '455cdf8beb71c6dd797fd2f3818d05c4',
  19. 'info_dict': {
  20. 'id': 'HDN7G5UMs',
  21. 'ext': 'mp4',
  22. 'title': 'Nvidia GeForce GTX Titan X - The Best Video Card on the Market?',
  23. 'thumbnail': 're:^https?://.*\.jpg$',
  24. 'upload_date': '20150317',
  25. 'description': 'Did Nvidia pull out all the stops on the Titan X, or does its performance leave something to be desired?',
  26. 'timestamp': int,
  27. },
  28. }, {
  29. 'url': 'https://www.vessel.com/embed/G4U7gUJ6a?w=615&h=346',
  30. 'only_matching': True,
  31. }]
  32. @staticmethod
  33. def _extract_urls(webpage):
  34. return [url for _, url in re.findall(
  35. r'<iframe[^>]+src=(["\'])((?:https?:)?//(?:www\.)?vessel\.com/embed/[0-9a-zA-Z]+.*?)\1',
  36. webpage)]
  37. @staticmethod
  38. def make_json_request(url, data):
  39. payload = json.dumps(data).encode('utf-8')
  40. req = sanitized_Request(url, payload)
  41. req.add_header('Content-Type', 'application/json; charset=utf-8')
  42. return req
  43. @staticmethod
  44. def find_assets(data, asset_type, asset_id=None):
  45. for asset in data.get('assets', []):
  46. if not asset.get('type') == asset_type:
  47. continue
  48. elif asset_id is not None and not asset.get('id') == asset_id:
  49. continue
  50. else:
  51. yield asset
  52. def _check_access_rights(self, data):
  53. access_info = data.get('__view', {})
  54. if not access_info.get('allow_access', True):
  55. err_code = access_info.get('error_code') or ''
  56. if err_code == 'ITEM_PAID_ONLY':
  57. raise ExtractorError(
  58. 'This video requires subscription.', expected=True)
  59. else:
  60. raise ExtractorError(
  61. 'Access to this content is restricted. (%s said: %s)' % (self.IE_NAME, err_code), expected=True)
  62. def _login(self):
  63. (username, password) = self._get_login_info()
  64. if username is None:
  65. return
  66. self.report_login()
  67. data = {
  68. 'client_id': 'web',
  69. 'type': 'password',
  70. 'user_key': username,
  71. 'password': password,
  72. }
  73. login_request = VesselIE.make_json_request(self._LOGIN_URL, data)
  74. self._download_webpage(login_request, None, False, 'Wrong login info')
  75. def _real_initialize(self):
  76. self._login()
  77. def _real_extract(self, url):
  78. video_id = self._match_id(url)
  79. webpage = self._download_webpage(url, video_id)
  80. data = self._parse_json(self._search_regex(
  81. r'App\.bootstrapData\((.*?)\);', webpage, 'data'), video_id)
  82. asset_id = data['model']['data']['id']
  83. req = VesselIE.make_json_request(
  84. self._API_URL_TEMPLATE % asset_id, {'client': 'web'})
  85. data = self._download_json(req, video_id)
  86. video_asset_id = data.get('main_video_asset')
  87. self._check_access_rights(data)
  88. try:
  89. video_asset = next(
  90. VesselIE.find_assets(data, 'video', asset_id=video_asset_id))
  91. except StopIteration:
  92. raise ExtractorError('No video assets found')
  93. formats = []
  94. for f in video_asset.get('sources', []):
  95. location = f.get('location')
  96. if not location:
  97. continue
  98. name = f.get('name')
  99. if name == 'hls-index':
  100. formats.extend(self._extract_m3u8_formats(
  101. location, video_id, ext='mp4',
  102. entry_protocol='m3u8_native', m3u8_id='m3u8', fatal=False))
  103. elif name == 'dash-index':
  104. formats.extend(self._extract_mpd_formats(
  105. location, video_id, mpd_id='dash', fatal=False))
  106. else:
  107. formats.append({
  108. 'format_id': name,
  109. 'tbr': f.get('bitrate'),
  110. 'height': f.get('height'),
  111. 'width': f.get('width'),
  112. 'url': location,
  113. })
  114. self._sort_formats(formats)
  115. thumbnails = []
  116. for im_asset in VesselIE.find_assets(data, 'image'):
  117. thumbnails.append({
  118. 'url': im_asset['location'],
  119. 'width': im_asset.get('width', 0),
  120. 'height': im_asset.get('height', 0),
  121. })
  122. return {
  123. 'id': video_id,
  124. 'title': data['title'],
  125. 'formats': formats,
  126. 'thumbnails': thumbnails,
  127. 'description': data.get('short_description'),
  128. 'duration': data.get('duration'),
  129. 'comment_count': data.get('comment_count'),
  130. 'like_count': data.get('like_count'),
  131. 'view_count': data.get('view_count'),
  132. 'timestamp': parse_iso8601(data.get('released_at')),
  133. }