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.

157 lines
5.5 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': r'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. 'url': 'https://www.vessel.com/videos/F01_dsLj1',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'https://www.vessel.com/videos/RRX-sir-J',
  36. 'only_matching': True,
  37. }]
  38. @staticmethod
  39. def _extract_urls(webpage):
  40. return [url for _, url in re.findall(
  41. r'<iframe[^>]+src=(["\'])((?:https?:)?//(?:www\.)?vessel\.com/embed/[0-9a-zA-Z-_]+.*?)\1',
  42. webpage)]
  43. @staticmethod
  44. def make_json_request(url, data):
  45. payload = json.dumps(data).encode('utf-8')
  46. req = sanitized_Request(url, payload)
  47. req.add_header('Content-Type', 'application/json; charset=utf-8')
  48. return req
  49. @staticmethod
  50. def find_assets(data, asset_type, asset_id=None):
  51. for asset in data.get('assets', []):
  52. if not asset.get('type') == asset_type:
  53. continue
  54. elif asset_id is not None and not asset.get('id') == asset_id:
  55. continue
  56. else:
  57. yield asset
  58. def _check_access_rights(self, data):
  59. access_info = data.get('__view', {})
  60. if not access_info.get('allow_access', True):
  61. err_code = access_info.get('error_code') or ''
  62. if err_code == 'ITEM_PAID_ONLY':
  63. raise ExtractorError(
  64. 'This video requires subscription.', expected=True)
  65. else:
  66. raise ExtractorError(
  67. 'Access to this content is restricted. (%s said: %s)' % (self.IE_NAME, err_code), expected=True)
  68. def _login(self):
  69. username, password = self._get_login_info()
  70. if username is None:
  71. return
  72. self.report_login()
  73. data = {
  74. 'client_id': 'web',
  75. 'type': 'password',
  76. 'user_key': username,
  77. 'password': password,
  78. }
  79. login_request = VesselIE.make_json_request(self._LOGIN_URL, data)
  80. self._download_webpage(login_request, None, False, 'Wrong login info')
  81. def _real_initialize(self):
  82. self._login()
  83. def _real_extract(self, url):
  84. video_id = self._match_id(url)
  85. webpage = self._download_webpage(url, video_id)
  86. data = self._parse_json(self._search_regex(
  87. r'App\.bootstrapData\((.*?)\);', webpage, 'data'), video_id)
  88. asset_id = data['model']['data']['id']
  89. req = VesselIE.make_json_request(
  90. self._API_URL_TEMPLATE % asset_id, {'client': 'web'})
  91. data = self._download_json(req, video_id)
  92. video_asset_id = data.get('main_video_asset')
  93. self._check_access_rights(data)
  94. try:
  95. video_asset = next(
  96. VesselIE.find_assets(data, 'video', asset_id=video_asset_id))
  97. except StopIteration:
  98. raise ExtractorError('No video assets found')
  99. formats = []
  100. for f in video_asset.get('sources', []):
  101. location = f.get('location')
  102. if not location:
  103. continue
  104. name = f.get('name')
  105. if name == 'hls-index':
  106. formats.extend(self._extract_m3u8_formats(
  107. location, video_id, ext='mp4',
  108. entry_protocol='m3u8_native', m3u8_id='m3u8', fatal=False))
  109. elif name == 'dash-index':
  110. formats.extend(self._extract_mpd_formats(
  111. location, video_id, mpd_id='dash', fatal=False))
  112. else:
  113. formats.append({
  114. 'format_id': name,
  115. 'tbr': f.get('bitrate'),
  116. 'height': f.get('height'),
  117. 'width': f.get('width'),
  118. 'url': location,
  119. })
  120. self._sort_formats(formats)
  121. thumbnails = []
  122. for im_asset in VesselIE.find_assets(data, 'image'):
  123. thumbnails.append({
  124. 'url': im_asset['location'],
  125. 'width': im_asset.get('width', 0),
  126. 'height': im_asset.get('height', 0),
  127. })
  128. return {
  129. 'id': video_id,
  130. 'title': data['title'],
  131. 'formats': formats,
  132. 'thumbnails': thumbnails,
  133. 'description': data.get('short_description'),
  134. 'duration': data.get('duration'),
  135. 'comment_count': data.get('comment_count'),
  136. 'like_count': data.get('like_count'),
  137. 'view_count': data.get('view_count'),
  138. 'timestamp': parse_iso8601(data.get('released_at')),
  139. }