diff --git a/youtube_dl/extractor/viu.py b/youtube_dl/extractor/viu.py index b809d3d00..68c36cf4b 100644 --- a/youtube_dl/extractor/viu.py +++ b/youtube_dl/extractor/viu.py @@ -13,6 +13,8 @@ from ..compat import ( from ..utils import ( ExtractorError, int_or_none, + smuggle_url, + unsmuggle_url, ) import json @@ -183,6 +185,7 @@ class ViuOTTIE(InfoExtractor): }, 'params': { 'skip_download': 'm3u8 download', + 'noplaylist': True, }, 'skip': 'Geo-restricted to Singapore', }, { @@ -195,6 +198,19 @@ class ViuOTTIE(InfoExtractor): }, 'params': { 'skip_download': 'm3u8 download', + 'noplaylist': True, + }, + 'skip': 'Geo-restricted to Hong Kong', + }, { + 'url': 'https://www.viu.com/ott/hk/zh-hk/vod/68776/%E6%99%82%E5%B0%9A%E5%AA%BD%E5%92%AA', + 'playlist_count': 12, + 'info_dict': { + 'id': '3916', + 'title': '時尚媽咪', + }, + 'params': { + 'skip_download': 'm3u8 download', + 'noplaylist': False, }, 'skip': 'Geo-restricted to Hong Kong', }] @@ -249,6 +265,7 @@ class ViuOTTIE(InfoExtractor): return self._user_info def _real_extract(self, url): + url, idata = unsmuggle_url(url, {}) country_code, lang_code, video_id = re.match(self._VALID_URL, url).groups() query = { @@ -269,6 +286,37 @@ class ViuOTTIE(InfoExtractor): if not video_data: raise ExtractorError('This video is not available in your region.', expected=True) + # return entire series as playlist if not --no-playlist + if not (self._downloader.params.get('noplaylist') or idata.get('force_noplaylist')): + series = product_data.get('series', {}) + 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 + item_id = compat_str(item_id) + entries.append(self.url_result( + smuggle_url( + 'http://www.viu.com/ott/%s/%s/vod/%s/' % (country_code, lang_code, item_id), + {'force_noplaylist': True}), # prevent infinite recursion + 'ViuOTT', + item_id, + entry.get('synopsis', '').strip())) + + return self.playlist_result( + entries, + video_data.get('series_id'), + series.get('name'), + series.get('description')) + # else fall-through + + if self._downloader.params.get('noplaylist'): + self.to_screen( + 'Downloading only video %s in series %s because of --no-playlist' % + (video_id, video_data.get('series_id'))) + duration_limit = False query = { 'ccs_product_id': video_data['ccs_product_id'],