From 9cd12f72e2dbff1e19ff6a131e6dbbd737fff6f0 Mon Sep 17 00:00:00 2001 From: garret Date: Thu, 3 Aug 2023 19:19:31 +0100 Subject: [PATCH] throw error on geo-block copied from puhutv extractor --- yt_dlp/extractor/tbsjp.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/yt_dlp/extractor/tbsjp.py b/yt_dlp/extractor/tbsjp.py index 6aa3fd2939c..7dcb2370713 100644 --- a/yt_dlp/extractor/tbsjp.py +++ b/yt_dlp/extractor/tbsjp.py @@ -1,6 +1,7 @@ from .common import InfoExtractor - +from ..networking.exceptions import HTTPError from ..utils import ( + ExtractorError, get_element_text_and_html_by_tag, traverse_obj, unified_timestamp, @@ -56,9 +57,14 @@ def _real_extract(self, url): video_url = self._search_regex(r'videoPlaybackUrl: *[\'"]([^\'"]+)[\'"]', tf_js, 'stream API url') api_key = self._search_regex(r'api_key: *[\'"]([^\'"]+)[\'"]', tf_js, 'stream API key') - source_meta = self._download_json(f'{video_url}ref:{video_id}', video_id, - headers={"X-Streaks-Api-Key": api_key}, - note='Downloading stream metadata') + try: + source_meta = self._download_json(f'{video_url}ref:{video_id}', video_id, + headers={"X-Streaks-Api-Key": api_key}, + note='Downloading stream metadata') + except ExtractorError as e: + if isinstance(e.cause, HTTPError) and e.cause.status == 403: + self.raise_geo_restricted(countries=['JP']) + raise formats = [] subs = []