From 596e3d4bd6ac3546fc06e0ecc5fe161a717fa599 Mon Sep 17 00:00:00 2001 From: mozbugbox Date: Sat, 28 May 2022 13:19:45 +0800 Subject: [PATCH] [bilibili] Handle bvid on embed player --- yt_dlp/extractor/bilibili.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/yt_dlp/extractor/bilibili.py b/yt_dlp/extractor/bilibili.py index ead0dd88b..6fa15fa4c 100644 --- a/yt_dlp/extractor/bilibili.py +++ b/yt_dlp/extractor/bilibili.py @@ -746,16 +746,29 @@ def _real_extract(self, url): class BiliBiliPlayerIE(InfoExtractor): - _VALID_URL = r'https?://player\.bilibili\.com/player\.html\?.*?\baid=(?P\d+)' - _TEST = { + _VALID_URL = r'https?://player\.bilibili\.com/player\.html\?.*?\b(aid=(?P\d+)|bvid=(?P[^/?#&=]+))' + _TESTS = [{ 'url': 'http://player.bilibili.com/player.html?aid=92494333&cid=157926707&page=1', 'only_matching': True, - } + }, { + 'url': 'https://player.bilibili.com/player.html?aid=996153&bvid=BV1bs411Z7nC&cid=1440287&page=1', + 'only_matching': True, + }] def _real_extract(self, url): - video_id = self._match_id(url) + u = compat_urllib_parse_urlparse(url) + query = compat_parse_qs(u.query) + if "bvid" in query: + video_id = query["bvid"][0] + real_url = 'https://www.bilibili.com/video/%s' % video_id + elif "aid" in query: + video_id = query["aid"][0] + real_url = 'https://www.bilibili.com/video/av%s' % video_id + + if "page" in query: + real_url = '%s?p=%s' % (real_url, query["page"][0]) return self.url_result( - 'http://www.bilibili.tv/video/av%s/' % video_id, + real_url, ie=BiliBiliIE.ie_key(), video_id=video_id)