From d93663451dc45f1d4e8d200ab23b535bffaa913d Mon Sep 17 00:00:00 2001 From: _Grqz <173015200+grqz@users.noreply.github.com> Date: Mon, 14 Jul 2025 22:11:19 +1200 Subject: [PATCH] raise early on playinfo unavailable --- yt_dlp/extractor/bilibili.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/yt_dlp/extractor/bilibili.py b/yt_dlp/extractor/bilibili.py index 3c1e57baa4..668d80296e 100644 --- a/yt_dlp/extractor/bilibili.py +++ b/yt_dlp/extractor/bilibili.py @@ -175,9 +175,14 @@ def _download_playinfo(self, bvid, cid, headers=None, query=None): else: note = f'Downloading video formats for cid {cid}' - return self._download_json( + playurl_raw = self._download_json( 'https://api.bilibili.com/x/player/wbi/playurl', bvid, - query=self._sign_wbi(params, bvid), headers=headers, note=note)['data'] + query=self._sign_wbi(params, bvid), headers=headers, note=note) + if playurl_raw.get('v_voucher'): + return playurl_raw['data'] + else: + self.report_warning('Received a captcha from Bilibili while downloading play info') + return None def json2srt(self, json_data): srt_data = '' @@ -724,11 +729,10 @@ def _real_extract(self, url): self._search_json(r'window\.__playinfo__\s*=', webpage, 'play info', video_id, default=None), ('data', {dict})) if not self.is_logged_in or not play_info: - dl_play_info = self._download_playinfo(video_id, cid, headers=headers, query={'try_look': 1}) - if not dl_play_info.get('v_voucher'): + if dl_play_info := self._download_playinfo(video_id, cid, headers=headers, query={'try_look': 1}): play_info = dl_play_info - else: - self.report_warning('Failed to download play info, falling back to the playinfo embedded in the webpage.', video_id=video_id) + if not play_info: + raise ExtractorError('Unable to download play info') formats = self.extract_formats(play_info) if video_data.get('is_upower_exclusive'):