- webpage = self._download_webpage(
- url, video_id, note='Downloading video page')
-
- mobj = re.search(
- r'<div class=["\']error-title[^<>]+?>(?P<err>.+?)</div>', webpage, flags=re.DOTALL)
-
- if mobj:
- raise ExtractorError(clean_html(mobj.group('err')), expected=True)
-
- config_js_url = self._search_regex(
- r'src=(["\'])(?P<api_url>.+?/js/config\.js)(?:\?.+?)?\1', webpage, 'config_js',
- group='api_url', default=None)
-
- if not config_js_url:
- # content is from ID, IN, MY
- video_info = self._download_json(
- 'https://www.viu.com/api/clip/load', video_id,
- headers={'X-VIU-AUTH': self._get_viu_auth(video_id)},
- query={'appid': 'viu_desktop', 'fmt': 'json', 'id': video_id},
- note='Downloading video info').get('response', {}).get('item', [{}])[0]
-
- formats = self._extract_m3u8_formats(
- video_info['href'], video_id, 'mp4',
- m3u8_id='hls', fatal=False)
- self._sort_formats(formats)
-
- subtitles = {}
- for key, value in list(video_info.items()):
- mobj = re.match(r'^subtitle_(?P<lang>[^_]+?)_(?P<ext>(vtt|srt))', key)
- if not mobj:
- continue
- if not subtitles.get(mobj.group('lang')):
- subtitles[mobj.group('lang')] = []
- subtitles[mobj.group('lang')].append(
- {'url': value, 'ext': mobj.group('ext')})
-
- title = '%s - Episode %s' % (video_info['moviealbumshowname'],
- video_info.get('episodeno'))
- description = video_info.get('description')
- duration = int_or_none(video_info.get('duration'))
- series = video_info.get('moviealbumshowname')
- episode_title = video_info.get('title')
- episode_num = int_or_none(video_info.get('episodeno'))
-
- return {
- 'id': video_id,
- 'title': title,
- 'description': description,
- 'series': series,
- 'episode': episode_title,
- 'episode_number': episode_num,
- 'duration': duration,
- 'formats': formats,
- 'subtitles': subtitles,
- }
-
- # content from HK, SG
- config_js = self._download_webpage(
- 'http://www.viu.com' + config_js_url, video_id, note='Downloading config js')
-
- # try to strip away commented code which contains test urls
- config_js = re.sub(r'^//.*?$', '', config_js, flags=re.MULTILINE)
- config_js = re.sub(r'/\*.*?\*/', '', config_js, flags=re.DOTALL)
-
- # Slightly different api_url between HK and SG config.js
- # http://www.viu.com/ott/hk/v1/js/config.js => '//www.viu.com/ott/hk/index.php?r='
- # http://www.viu.com/ott/sg/v1/js/config.js => 'http://www.viu.com/ott/sg/index.php?r='
- api_url = self._proto_relative_url(
- self._search_regex(
- r'var\s+api_url\s*=\s*(["\'])(?P<api_url>(?:https?:)?//.+?\?r=)\1',
- config_js, 'api_url', group='api_url'), scheme='http:')
-
- stream_info_url = self._proto_relative_url(
- self._search_regex(
- r'var\s+video_url\s*=\s*(["\'])(?P<video_url>(?:https?:)?//.+?\?ccs_product_id=)\1',
- config_js, 'video_url', group='video_url'), scheme='http:')
-
- if url.startswith('https://'):
- api_url = re.sub('^http://', 'https://', api_url)
-
- video_info = self._download_json(
- api_url + 'vod/ajax-detail&platform_flag_label=web&product_id=' + video_id,
- video_id, note='Downloading video info').get('data', {})
-
- ccs_product_id = video_info.get('current_product', {}).get('ccs_product_id')
-
- if not ccs_product_id:
- raise ExtractorError('This video is not available in your region.', expected=True)
-
- stream_info = self._download_json(
- stream_info_url + ccs_product_id, video_id,
- note='Downloading stream info').get('data', {}).get('stream', {})
-
- formats = []
- for vid_format, stream_url in stream_info.get('url', {}).items():
- br = int_or_none(self._search_regex(
- r's(?P<br>[0-9]+)p', vid_format, 'bitrate', group='br'))
- formats.append({
- 'format_id': vid_format,
- 'url': stream_url,
- 'vbr': br,
- 'ext': 'mp4',
- 'filesize': stream_info.get('size', {}).get(vid_format)
- })
+ video_data = self._call_api(
+ 'clip/load', video_id, 'Downloading video data', query={
+ 'appid': 'viu_desktop',
+ 'fmt': 'json',
+ 'id': video_id
+ })['item'][0]
+
+ title = video_data['title']
+
+ m3u8_url = None
+ url_path = video_data.get('urlpathd') or video_data.get('urlpath')
+ tdirforwhole = video_data.get('tdirforwhole')
+ # #EXT-X-BYTERANGE is not supported by native hls downloader
+ # and ffmpeg (#10955)
+ # hls_file = video_data.get('hlsfile')
+ hls_file = video_data.get('jwhlsfile')
+ if url_path and tdirforwhole and hls_file:
+ m3u8_url = '%s/%s/%s' % (url_path, tdirforwhole, hls_file)
+ else:
+ # m3u8_url = re.sub(
+ # r'(/hlsc_)[a-z]+(\d+\.m3u8)',
+ # r'\1whe\2', video_data['href'])
+ m3u8_url = video_data['href']
+ formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')