- raise ExtractorError('This video is not available in your region.', expected=True)
-
- stream_data = self._download_json(
- 'https://d1k2us671qcoau.cloudfront.net/distribute_web_%s.php' % country_code,
- video_id, 'Downloading stream info', query={
- 'ccs_product_id': video_data['ccs_product_id'],
- }, headers={
- 'Referer': url,
- 'Origin': re.search(r'https?://[^/]+', url).group(0),
- })['data']['stream']
-
- stream_sizes = stream_data.get('size', {})
+ self.raise_geo_restricted()
+
+ series_id = video_data.get('series_id')
+ if self._yes_playlist(series_id, video_id, idata):
+ series = product_data.get('series') or {}
+ product = series.get('product')
+ if product:
+ entries = []
+ for entry in sorted(product, key=lambda x: int_or_none(x.get('number', 0))):
+ item_id = entry.get('product_id')
+ if not item_id:
+ continue
+ entries.append(self.url_result(
+ smuggle_url(f'http://www.viu.com/ott/{country_code}/{lang_code}/vod/{item_id}/',
+ {'force_noplaylist': True}),
+ ViuOTTIE, str(item_id), entry.get('synopsis', '').strip()))
+
+ return self.playlist_result(entries, series_id, series.get('name'), series.get('description'))
+
+ duration_limit = False
+ query = {
+ 'ccs_product_id': video_data['ccs_product_id'],
+ 'language_flag_id': self._LANGUAGE_FLAG.get(lang_code.lower()) or '3',
+ }
+
+ def download_playback():
+ stream_data = self._download_json(
+ 'https://api-gateway-global.viu.com/api/playback/distribute',
+ video_id=video_id, query=query, fatal=False, note='Downloading stream info',
+ headers={
+ 'Authorization': f'Bearer {self._auth_codes[country_code]}',
+ 'Referer': url,
+ 'Origin': url
+ })
+ return self._detect_error(stream_data).get('stream')
+
+ if not self._auth_codes.get(country_code):
+ self._auth_codes[country_code] = self._get_token(country_code, video_id)
+
+ stream_data = None
+ try:
+ stream_data = download_playback()
+ except (ExtractorError, KeyError):
+ token = self._login(country_code, video_id)
+ if token is not None:
+ query['identity'] = token
+ else:
+ # The content is Preview or for VIP only.
+ # We can try to bypass the duration which is limited to 3mins only
+ duration_limit, query['duration'] = True, '180'
+ try:
+ stream_data = download_playback()
+ except (ExtractorError, KeyError):
+ if token is not None:
+ raise
+ self.raise_login_required(method='password')
+ if not stream_data:
+ raise ExtractorError('Cannot get stream info', expected=True)
+