From f92dedc92a3356958f986ffc145e61a39d554945 Mon Sep 17 00:00:00 2001 From: HobbyistDev Date: Thu, 11 Apr 2024 07:13:34 +0800 Subject: [PATCH] handle `_download_json` error correctly This commit will fallback to webpage extraction if the API url is not found in particular regiom --- yt_dlp/extractor/viu.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/yt_dlp/extractor/viu.py b/yt_dlp/extractor/viu.py index 794550c3e..cc757eab8 100644 --- a/yt_dlp/extractor/viu.py +++ b/yt_dlp/extractor/viu.py @@ -6,8 +6,8 @@ import urllib.parse from .common import InfoExtractor from ..compat import compat_str +from ..networking.exceptions import HTTPError from ..utils import ( - DownloadError, ExtractorError, int_or_none, merge_dicts, @@ -304,10 +304,12 @@ class ViuOTTIE(InfoExtractor): try: product_data = self._download_json( f'http://www.viu.com/ott/{country_code}/index.php', video_id, - 'Downloading video info', query=query, fatal=False)['data'] + 'Downloading video info', query=query)['data'] # The `fatal` in `_download_json` didn't prevent json error # FIXME: probably the error still too broad - except (DownloadError, ExtractorError): + except ExtractorError as e: + if not isinstance(e.cause, (json.JSONDecodeError, HTTPError)): + raise # NOTE: some geo-blocked like https://www.viu.com/ott/sg/en/vod/108599/The-Beauty-Inside actually can bypassed # on other region (like in ID) product_data = traverse_obj(