2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_request
14 class VesselIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?vessel\.com/videos/(?P<id>[0-9a-zA-Z]+)'
16 _API_URL_TEMPLATE = 'https://www.vessel.com/api/view/items/%s'
17 _LOGIN_URL = 'https://www.vessel.com/api/account/login'
18 _NETRC_MACHINE = 'vessel'
20 'url': 'https://www.vessel.com/videos/HDN7G5UMs',
21 'md5': '455cdf8beb71c6dd797fd2f3818d05c4',
25 'title': 'Nvidia GeForce GTX Titan X - The Best Video Card on the Market?',
26 'thumbnail': 're:^https?://.*\.jpg$',
27 'upload_date': '20150317',
28 'description': 'Did Nvidia pull out all the stops on the Titan X, or does its performance leave something to be desired?',
34 def make_json_request(url, data):
35 payload = json.dumps(data).encode('utf-8')
36 req = compat_urllib_request.Request(url, payload)
37 req.add_header('Content-Type', 'application/json; charset=utf-8')
41 def find_assets(data, asset_type):
42 for asset in data.get('assets', []):
43 if asset.get('type') == asset_type:
46 def _check_access_rights(self, data):
47 access_info = data.get('__view', {})
48 if not access_info.get('allow_access', True):
49 err_code = access_info.get('error_code') or ''
50 if err_code == 'ITEM_PAID_ONLY':
52 'This video requires subscription.', expected=True)
55 'Access to this content is restricted. (%s said: %s)' % (self.IE_NAME, err_code), expected=True)
58 (username, password) = self._get_login_info()
68 login_request = VesselIE.make_json_request(self._LOGIN_URL, data)
69 self._download_webpage(login_request, None, False, 'Wrong login info')
71 def _real_initialize(self):
74 def _real_extract(self, url):
75 video_id = self._match_id(url)
77 webpage = self._download_webpage(url, video_id)
78 data = self._parse_json(self._search_regex(
79 r'App\.bootstrapData\((.*?)\);', webpage, 'data'), video_id)
80 asset_id = data['model']['data']['id']
82 req = VesselIE.make_json_request(
83 self._API_URL_TEMPLATE % asset_id, {'client': 'web'})
84 data = self._download_json(req, video_id)
86 self._check_access_rights(data)
89 video_asset = next(VesselIE.find_assets(data, 'video'))
91 raise ExtractorError('No video assets found')
94 for f in video_asset.get('sources', []):
95 if f['name'] == 'hls-index':
96 formats.extend(self._extract_m3u8_formats(
97 f['location'], video_id, ext='mp4', m3u8_id='m3u8'))
100 'format_id': f['name'],
101 'tbr': f.get('bitrate'),
102 'height': f.get('height'),
103 'width': f.get('width'),
104 'url': f['location'],
106 self._sort_formats(formats)
109 for im_asset in VesselIE.find_assets(data, 'image'):
111 'url': im_asset['location'],
112 'width': im_asset.get('width', 0),
113 'height': im_asset.get('height', 0),
118 'title': data['title'],
120 'thumbnails': thumbnails,
121 'description': data.get('short_description'),
122 'duration': data.get('duration'),
123 'comment_count': data.get('comment_count'),
124 'like_count': data.get('like_count'),
125 'view_count': data.get('view_count'),
126 'timestamp': parse_iso8601(data.get('released_at')),