From 13ed5741689aec27b73cf6a3b762a6d70f9f525b Mon Sep 17 00:00:00 2001 From: grqx_wsl <173253225+grqx@users.noreply.github.com> Date: Tue, 20 Aug 2024 00:46:21 +1200 Subject: [PATCH] [BiliBiliBangumiIE] supports play_info extraction from webpage - i.e. extracts premiums formats with logged-in cookies, haven't tested with format `12240` yet. * test url: https://www.bilibili.com/bangumi/play/ep829434, cookies: logged-in, non-premium --- yt_dlp/extractor/bilibili.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/yt_dlp/extractor/bilibili.py b/yt_dlp/extractor/bilibili.py index 39d9e5c5a..cf6ebc0a5 100644 --- a/yt_dlp/extractor/bilibili.py +++ b/yt_dlp/extractor/bilibili.py @@ -864,10 +864,16 @@ class BiliBiliBangumiIE(BilibiliBaseIE): self.raise_login_required('This video is for premium members only') headers['Referer'] = url - play_info = self._download_json( - 'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id, - 'Extracting episode', query={'fnval': 12240, 'ep_id': episode_id}, - headers=headers) + + play_info = self._search_json( + r'playurlSSRData\s*?=\s*?', webpage, 'embedded page info', episode_id, + end_pattern='\n', default=None) + if not play_info: + play_info = self._download_json( + 'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id, + 'Extracting episode', query={'fnval': 12240, 'ep_id': episode_id}, + headers=headers) + premium_only = play_info.get('code') == -10403 play_info = traverse_obj(play_info, ('result', 'video_info', {dict})) or {}