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': '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,
38 def _extract_urls(webpage):
39 return [url for _, url in re.findall(
40 r'<iframe[^>]+src=(["\'])((?:https?:)?//(?:www\.)?vessel\.com/embed/[0-9a-zA-Z]+.*?)\1',
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')
51 def find_assets(data, asset_type, asset_id=None):
52 for asset in data.get('assets', []):
53 if not asset.get('type') == asset_type:
55 elif asset_id is not None and not asset.get('id') == asset_id:
60 def _check_access_rights(self, data):
61 access_info = data.get('__view', {})
62 if not access_info.get('allow_access', True):
63 err_code = access_info.get('error_code') or ''
64 if err_code == 'ITEM_PAID_ONLY':
66 'This video requires subscription.', expected=True)
69 'Access to this content is restricted. (%s said: %s)' % (self.IE_NAME, err_code), expected=True)
72 (username, password) = self._get_login_info()
82 login_request = VesselIE.make_json_request(self._LOGIN_URL, data)
83 self._download_webpage(login_request, None, False, 'Wrong login info')
85 def _real_initialize(self):
88 def _real_extract(self, url):
89 video_id = self._match_id(url)
91 webpage = self._download_webpage(url, video_id)
92 data = self._parse_json(self._search_regex(
93 r'App\.bootstrapData\((.*?)\);', webpage, 'data'), video_id)
94 asset_id = data['model']['data']['id']
96 req = VesselIE.make_json_request(
97 self._API_URL_TEMPLATE % asset_id, {'client': 'web'})
98 data = self._download_json(req, video_id)
99 video_asset_id = data.get('main_video_asset')
101 self._check_access_rights(data)
105 VesselIE.find_assets(data, 'video', asset_id=video_asset_id))
106 except StopIteration:
107 raise ExtractorError('No video assets found')
110 for f in video_asset.get('sources', []):
111 location = f.get('location')
115 if name == 'hls-index':
116 formats.extend(self._extract_m3u8_formats(
117 location, video_id, ext='mp4',
118 entry_protocol='m3u8_native', m3u8_id='m3u8', fatal=False))
119 elif name == 'dash-index':
120 formats.extend(self._extract_mpd_formats(
121 location, video_id, mpd_id='dash', fatal=False))
125 'tbr': f.get('bitrate'),
126 'height': f.get('height'),
127 'width': f.get('width'),
130 self._sort_formats(formats)
133 for im_asset in VesselIE.find_assets(data, 'image'):
135 'url': im_asset['location'],
136 'width': im_asset.get('width', 0),
137 'height': im_asset.get('height', 0),
142 'title': data['title'],
144 'thumbnails': thumbnails,
145 'description': data.get('short_description'),
146 'duration': data.get('duration'),
147 'comment_count': data.get('comment_count'),
148 'like_count': data.get('like_count'),
149 'view_count': data.get('view_count'),
150 'timestamp': parse_iso8601(data.get('released_at')),