2 from __future__ import unicode_literals
7 from .common import InfoExtractor
15 class VesselIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?vessel\.com/(?:videos|embed)/(?P<id>[0-9a-zA-Z-_]+)'
17 _API_URL_TEMPLATE = 'https://www.vessel.com/api/view/items/%s'
18 _LOGIN_URL = 'https://www.vessel.com/api/account/login'
19 _NETRC_MACHINE = 'vessel'
21 'url': 'https://www.vessel.com/videos/HDN7G5UMs',
22 'md5': '455cdf8beb71c6dd797fd2f3818d05c4',
26 'title': 'Nvidia GeForce GTX Titan X - The Best Video Card on the Market?',
27 'thumbnail': r're:^https?://.*\.jpg$',
28 'upload_date': '20150317',
29 'description': 'Did Nvidia pull out all the stops on the Titan X, or does its performance leave something to be desired?',
33 'url': 'https://www.vessel.com/embed/G4U7gUJ6a?w=615&h=346',
34 'only_matching': True,
36 'url': 'https://www.vessel.com/videos/F01_dsLj1',
37 'only_matching': True,
39 'url': 'https://www.vessel.com/videos/RRX-sir-J',
40 'only_matching': True,
44 def _extract_urls(webpage):
45 return [url for _, url in re.findall(
46 r'<iframe[^>]+src=(["\'])((?:https?:)?//(?:www\.)?vessel\.com/embed/[0-9a-zA-Z-_]+.*?)\1',
50 def make_json_request(url, data):
51 payload = json.dumps(data).encode('utf-8')
52 req = sanitized_Request(url, payload)
53 req.add_header('Content-Type', 'application/json; charset=utf-8')
57 def find_assets(data, asset_type, asset_id=None):
58 for asset in data.get('assets', []):
59 if not asset.get('type') == asset_type:
61 elif asset_id is not None and not asset.get('id') == asset_id:
66 def _check_access_rights(self, data):
67 access_info = data.get('__view', {})
68 if not access_info.get('allow_access', True):
69 err_code = access_info.get('error_code') or ''
70 if err_code == 'ITEM_PAID_ONLY':
72 'This video requires subscription.', expected=True)
75 'Access to this content is restricted. (%s said: %s)' % (self.IE_NAME, err_code), expected=True)
78 (username, password) = self._get_login_info()
88 login_request = VesselIE.make_json_request(self._LOGIN_URL, data)
89 self._download_webpage(login_request, None, False, 'Wrong login info')
91 def _real_initialize(self):
94 def _real_extract(self, url):
95 video_id = self._match_id(url)
97 webpage = self._download_webpage(url, video_id)
98 data = self._parse_json(self._search_regex(
99 r'App\.bootstrapData\((.*?)\);', webpage, 'data'), video_id)
100 asset_id = data['model']['data']['id']
102 req = VesselIE.make_json_request(
103 self._API_URL_TEMPLATE % asset_id, {'client': 'web'})
104 data = self._download_json(req, video_id)
105 video_asset_id = data.get('main_video_asset')
107 self._check_access_rights(data)
111 VesselIE.find_assets(data, 'video', asset_id=video_asset_id))
112 except StopIteration:
113 raise ExtractorError('No video assets found')
116 for f in video_asset.get('sources', []):
117 location = f.get('location')
121 if name == 'hls-index':
122 formats.extend(self._extract_m3u8_formats(
123 location, video_id, ext='mp4',
124 entry_protocol='m3u8_native', m3u8_id='m3u8', fatal=False))
125 elif name == 'dash-index':
126 formats.extend(self._extract_mpd_formats(
127 location, video_id, mpd_id='dash', fatal=False))
131 'tbr': f.get('bitrate'),
132 'height': f.get('height'),
133 'width': f.get('width'),
136 self._sort_formats(formats)
139 for im_asset in VesselIE.find_assets(data, 'image'):
141 'url': im_asset['location'],
142 'width': im_asset.get('width', 0),
143 'height': im_asset.get('height', 0),
148 'title': data['title'],
150 'thumbnails': thumbnails,
151 'description': data.get('short_description'),
152 'duration': data.get('duration'),
153 'comment_count': data.get('comment_count'),
154 'like_count': data.get('like_count'),
155 'view_count': data.get('view_count'),
156 'timestamp': parse_iso8601(data.get('released_at')),