-
Notifications
You must be signed in to change notification settings - Fork 23
feat(bilibili): 增强哔哩哔哩图文动态解析 #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+28
−70
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9e3bbb
feat(bilibili): 增强哔哩哔哩图文动态解析&修复字体占用
molanp 82c55af
chore: auto fix by pre-commit hooks
pre-commit-ci[bot] cfc958d
fix(tests): 修复bilibili测试用例
molanp 44d456f
chore: auto fix by pre-commit hooks
pre-commit-ci[bot] 3c8e196
test(bilibili): 移除动态解析测试中的标题断言
molanp 4d60f93
移除自动格式化的换行
molanp 4da618c
Revert common
fllesser 2bace28
Tweaks
fllesser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,10 @@ async def _parse_short_link(self, searched: Match[str]): | |
| return await self.parse_with_redirect(url) | ||
|
|
||
| @handle("BV", r"^(?P<bvid>BV[0-9a-zA-Z]{10})(?:\s)?(?P<page_num>\d{1,3})?$") | ||
| @handle("/BV", r"bilibili\.com(?:/video)?/(?P<bvid>BV[0-9a-zA-Z]{10})(?:\?p=(?P<page_num>\d{1,3}))?") | ||
| @handle( | ||
| "/BV", | ||
| r"bilibili\.com(?:/video)?/(?P<bvid>BV[0-9a-zA-Z]{10})(?:\?p=(?P<page_num>\d{1,3}))?", | ||
| ) | ||
| async def _parse_bv(self, searched: Match[str]): | ||
| """解析视频信息""" | ||
| bvid = str(searched.group("bvid")) | ||
|
|
@@ -57,7 +60,10 @@ async def _parse_bv(self, searched: Match[str]): | |
| return await self.parse_video(bvid=bvid, page_num=page_num) | ||
|
|
||
| @handle("av", r"^av(?P<avid>\d{6,})(?:\s)?(?P<page_num>\d{1,3})?$") | ||
| @handle("/av", r"bilibili\.com(?:/video)?/av(?P<avid>\d{6,})(?:\?p=(?P<page_num>\d{1,3}))?") | ||
| @handle( | ||
| "/av", | ||
| r"bilibili\.com(?:/video)?/av(?P<avid>\d{6,})(?:\?p=(?P<page_num>\d{1,3}))?", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同 |
||
| ) | ||
| async def _parse_av(self, searched: Match[str]): | ||
| """解析视频信息""" | ||
| avid = int(searched.group("avid")) | ||
|
|
@@ -67,10 +73,11 @@ async def _parse_av(self, searched: Match[str]): | |
|
|
||
| @handle("/dynamic/", r"bilibili\.com/dynamic/(?P<dynamic_id>\d+)") | ||
| @handle("t.bili", r"t\.bilibili\.com/(?P<dynamic_id>\d+)") | ||
| @handle("/opus/", r"bilibili\.com/opus/(?P<dynamic_id>\d+)") | ||
| async def _parse_dynamic(self, searched: Match[str]): | ||
| """解析动态信息""" | ||
| dynamic_id = int(searched.group("dynamic_id")) | ||
| return await self.parse_dynamic(dynamic_id) | ||
| return await self.parse_dynamic_or_opus(dynamic_id) | ||
|
|
||
| @handle("live.bili", r"live\.bilibili\.com/(?P<room_id>\d+)") | ||
| async def _parse_live(self, searched: Match[str]): | ||
|
|
@@ -88,13 +95,7 @@ async def _parse_favlist(self, searched: Match[str]): | |
| async def _parse_read(self, searched: Match[str]): | ||
| """解析专栏信息""" | ||
| read_id = int(searched.group("read_id")) | ||
| return await self.parse_read_with_opus(read_id) | ||
|
|
||
| @handle("/opus/", r"bilibili\.com/opus/(?P<opus_id>\d+)") | ||
| async def _parse_opus(self, searched: Match[str]): | ||
|
molanp marked this conversation as resolved.
|
||
| """解析图文动态信息""" | ||
| opus_id = int(searched.group("opus_id")) | ||
| return await self.parse_opus(opus_id) | ||
| return await self.parse_read(read_id) | ||
|
|
||
| async def parse_video( | ||
| self, | ||
|
|
@@ -167,8 +168,8 @@ async def download_video(): | |
| extra={"info": ai_summary}, | ||
| ) | ||
|
|
||
| async def parse_dynamic(self, dynamic_id: int): | ||
| """解析动态信息 | ||
| async def parse_dynamic_or_opus(self, dynamic_id: int): | ||
| """解析动态和图文信息 | ||
|
|
||
| Args: | ||
| url (str): 动态链接 | ||
|
|
@@ -178,6 +179,8 @@ async def parse_dynamic(self, dynamic_id: int): | |
| from .dynamic import DynamicData | ||
|
|
||
| dynamic = Dynamic(dynamic_id, await self.credential) | ||
| if await dynamic.is_article(): | ||
| return await self._parse_opus_obj(dynamic.turn_to_opus()) | ||
| dynamic_info = convert(await dynamic.get_info(), DynamicData).item | ||
|
|
||
| author = self.create_author(dynamic_info.name, dynamic_info.avatar) | ||
|
|
@@ -205,7 +208,7 @@ async def parse_opus(self, opus_id: int): | |
| opus = Opus(opus_id, await self.credential) | ||
| return await self._parse_opus_obj(opus) | ||
|
|
||
| async def parse_read_with_opus(self, read_id: int): | ||
| async def parse_read(self, read_id: int): | ||
| """解析专栏信息, 使用 Opus 接口 | ||
|
|
||
| Args: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么要换行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式化插件自动的