nonebot-plugin-parser 2.0.8__tar.gz → 2.0.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/PKG-INFO +1 -1
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/pyproject.toml +2 -2
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/matchers/__init__.py +2 -2
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/matchers/preprocess.py +13 -13
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/bilibili/__init__.py +19 -31
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/base.py +7 -4
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/README.md +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/__init__.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/config.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/constants.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/download/__init__.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/download/task.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/download/ytdlp.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/exception.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/helper.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/matchers/filter.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/__init__.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/acfun.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/base.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/bilibili/article.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/bilibili/common.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/bilibili/dynamic.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/bilibili/favlist.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/bilibili/live.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/bilibili/opus.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/bilibili/video.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/cookie.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/data.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/douyin/__init__.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/douyin/slides.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/douyin/video.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/kuaishou.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/nga.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/tiktok.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/twitter.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/weibo.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/xiaohongshu.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/youtube.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/__init__.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/common.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/default.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/HYSongYunLangHeiW-1.ttf +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/bilibili.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/douyin.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/kuaishou.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/media_button.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/tiktok.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/twitter.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/weibo.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/xiaohongshu.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/resources/youtube.png +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/templates/weibo.html.jinja +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/renders/weibo.py +0 -0
- {nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: nonebot-plugin-parser
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.9
|
|
4
4
|
Summary: NoneBot2 链接分享解析器自动解析, BV号/链接/小程序/卡片 | B站/抖音/快手/微博/小红书/youtube/tiktok/twitter/acfun
|
|
5
5
|
Keywords: nonebot,nonebot2,video,bilibili,youtube,tiktok,twitter,kuaishou,acfun,weibo,xiaohongshu,nga,douyin
|
|
6
6
|
Author: fllesser
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "nonebot-plugin-parser"
|
|
3
|
-
version = "2.0.
|
|
3
|
+
version = "2.0.9"
|
|
4
4
|
description = "NoneBot2 链接分享解析器自动解析, BV号/链接/小程序/卡片 | B站/抖音/快手/微博/小红书/youtube/tiktok/twitter/acfun"
|
|
5
5
|
authors = [{ "name" = "fllesser", "email" = "fllessive@gmail.com" }]
|
|
6
6
|
readme = "README.md"
|
|
@@ -186,7 +186,7 @@ build-backend = "uv_build"
|
|
|
186
186
|
|
|
187
187
|
|
|
188
188
|
[tool.bumpversion]
|
|
189
|
-
current_version = "2.0.
|
|
189
|
+
current_version = "2.0.9"
|
|
190
190
|
commit = true
|
|
191
191
|
message = "🔖 release: bump vesion from {current_version} to {new_version}"
|
|
192
192
|
tag = true
|
|
@@ -12,7 +12,7 @@ from ..config import pconfig
|
|
|
12
12
|
from ..parsers import BaseParser, ParseResult
|
|
13
13
|
from ..renders import get_renderer
|
|
14
14
|
from ..utils import LimitedSizeDict
|
|
15
|
-
from .preprocess import
|
|
15
|
+
from .preprocess import Keyword, KwdRegexMatched, on_keyword_regex
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def _get_enabled_parser_classes() -> list[type[BaseParser]]:
|
|
@@ -60,7 +60,7 @@ parser_matcher = on_keyword_regex(*_get_enabled_patterns())
|
|
|
60
60
|
async def _(
|
|
61
61
|
event: Event,
|
|
62
62
|
keyword: str = Keyword(),
|
|
63
|
-
matched: re.Match[str] =
|
|
63
|
+
matched: re.Match[str] = KwdRegexMatched(),
|
|
64
64
|
):
|
|
65
65
|
"""统一的解析处理器"""
|
|
66
66
|
# 响应用户处理中
|
|
@@ -13,9 +13,9 @@ from nonebot_plugin_alconna.uniseg import Hyper, UniMsg
|
|
|
13
13
|
|
|
14
14
|
from .filter import is_not_in_disabled_groups
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
PSR_KWD_KEY: Literal["_psr_kwd"] = "_psr_kwd"
|
|
17
|
+
PSR_EXTRACT_KEY: Literal["_psr_extract"] = "_psr_extract"
|
|
18
|
+
PSR_KWD_MATCHED_KEY: Literal["_psr_kwd_matched"] = "_psr_kwd_matched"
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def ExtractText() -> str:
|
|
@@ -23,7 +23,7 @@ def ExtractText() -> str:
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def _extract_text(state: T_State) -> str | None:
|
|
26
|
-
return state.get(
|
|
26
|
+
return state.get(PSR_EXTRACT_KEY)
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def Keyword() -> str:
|
|
@@ -31,15 +31,15 @@ def Keyword() -> str:
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
def _keyword(state: T_State) -> str | None:
|
|
34
|
-
return state.get(
|
|
34
|
+
return state.get(PSR_KWD_KEY)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def
|
|
38
|
-
return Depends(
|
|
37
|
+
def KwdRegexMatched() -> re.Match[str]:
|
|
38
|
+
return Depends(_kwd_regex_matched)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
def
|
|
42
|
-
return state.get(
|
|
41
|
+
def _kwd_regex_matched(state: T_State) -> re.Match[str] | None:
|
|
42
|
+
return state.get(PSR_KWD_MATCHED_KEY)
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
URL_KEY_MAPPING = {
|
|
@@ -104,12 +104,12 @@ def extract_msg_text(message: UniMsg, state: T_State) -> None:
|
|
|
104
104
|
text: str | None = None
|
|
105
105
|
|
|
106
106
|
if hyper := message.get(Hyper, 1):
|
|
107
|
-
state[
|
|
107
|
+
state[PSR_EXTRACT_KEY] = _extract_json_url(hyper.pop())
|
|
108
108
|
return
|
|
109
109
|
|
|
110
110
|
# 提取纯文本
|
|
111
111
|
if text := message.extract_plain_text().strip():
|
|
112
|
-
state[
|
|
112
|
+
state[PSR_EXTRACT_KEY] = text
|
|
113
113
|
|
|
114
114
|
|
|
115
115
|
class KeyPatternList(list[tuple[str, re.Pattern[str]]]):
|
|
@@ -145,8 +145,8 @@ class KeywordRegexRule:
|
|
|
145
145
|
if keyword not in text:
|
|
146
146
|
continue
|
|
147
147
|
if matched := pattern.search(text):
|
|
148
|
-
state[
|
|
149
|
-
state[
|
|
148
|
+
state[PSR_KWD_KEY] = keyword
|
|
149
|
+
state[PSR_KWD_MATCHED_KEY] = matched
|
|
150
150
|
return True
|
|
151
151
|
logger.debug(f"keyword '{keyword}' is in '{text}', but not matched")
|
|
152
152
|
return False
|
|
@@ -61,21 +61,23 @@ class BilibiliParser(BaseParser):
|
|
|
61
61
|
"""
|
|
62
62
|
# 从匹配对象中获取原始URL, 视频ID, 页码
|
|
63
63
|
url, video_id, page_num = str(matched.group(0)), str(matched.group(1)), matched.group(2)
|
|
64
|
-
|
|
65
64
|
# 处理短链
|
|
66
65
|
if "b23.tv" in url or "bili2233.cn" in url:
|
|
67
66
|
url = await self.get_redirect_url(url, self.headers)
|
|
68
67
|
|
|
69
68
|
if not video_id:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
elif _matched := re.search(r"av(\d{6,})[^?]*?(?:\?[^#]*?p=(\d{1,3}))?", url):
|
|
74
|
-
video_id = _matched.group(1)
|
|
75
|
-
page_num = _matched.group(2)
|
|
69
|
+
# https://www.bilibili.com/video/BV1584y167sD?a=20&p=40
|
|
70
|
+
if _matched := re.search(r"(?:(BV[\dA-Za-z]{10})|av(\d{6,}))", url):
|
|
71
|
+
video_id = _matched.group(1) or _matched.group(2)
|
|
76
72
|
else:
|
|
77
73
|
return await self.parse_others(url)
|
|
78
74
|
|
|
75
|
+
# 匹配页码参数
|
|
76
|
+
if _matched := re.search(r"(?:&|\?)p=(\d{1,3})", url):
|
|
77
|
+
page_num = _matched.group(1)
|
|
78
|
+
else:
|
|
79
|
+
page_num = None
|
|
80
|
+
|
|
79
81
|
avid, bvid = None, None
|
|
80
82
|
page_num = int(page_num) if page_num and page_num.isdigit() else 1
|
|
81
83
|
|
|
@@ -282,18 +284,11 @@ class BilibiliParser(BaseParser):
|
|
|
282
284
|
current_text = ""
|
|
283
285
|
|
|
284
286
|
for node in opus_data.gen_text_img():
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
current_text.strip(),
|
|
291
|
-
node.alt,
|
|
292
|
-
)
|
|
293
|
-
)
|
|
294
|
-
current_text = ""
|
|
295
|
-
case TextNode():
|
|
296
|
-
current_text += node.text
|
|
287
|
+
if isinstance(node, ImageNode):
|
|
288
|
+
contents.append(self.create_graphics_content(node.url, current_text.strip(), node.alt))
|
|
289
|
+
current_text = ""
|
|
290
|
+
elif isinstance(node, TextNode):
|
|
291
|
+
current_text += node.text
|
|
297
292
|
|
|
298
293
|
return self.result(
|
|
299
294
|
title=opus_data.title,
|
|
@@ -358,18 +353,11 @@ class BilibiliParser(BaseParser):
|
|
|
358
353
|
contents: list[MediaContent] = []
|
|
359
354
|
current_text = ""
|
|
360
355
|
for child in article_info.gen_text_img():
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
current_text.strip(),
|
|
367
|
-
child.alt,
|
|
368
|
-
)
|
|
369
|
-
)
|
|
370
|
-
current_text = ""
|
|
371
|
-
case TextNode():
|
|
372
|
-
current_text += child.text
|
|
356
|
+
if isinstance(child, ImageNode):
|
|
357
|
+
contents.append(self.create_graphics_content(child.url, current_text.strip(), child.alt))
|
|
358
|
+
current_text = ""
|
|
359
|
+
elif isinstance(child, TextNode):
|
|
360
|
+
current_text += child.text
|
|
373
361
|
|
|
374
362
|
author = self.create_author(*article_info.author_info)
|
|
375
363
|
|
|
@@ -44,6 +44,7 @@ class BaseRenderer(ABC):
|
|
|
44
44
|
"""
|
|
45
45
|
failed_count = 0
|
|
46
46
|
forwardable_segs: list[ForwardNodeInner] = []
|
|
47
|
+
dynamic_segs: list[ForwardNodeInner] = []
|
|
47
48
|
|
|
48
49
|
for cont in chain(result.contents, result.repost.contents if result.repost else ()):
|
|
49
50
|
try:
|
|
@@ -65,7 +66,7 @@ class BaseRenderer(ABC):
|
|
|
65
66
|
case ImageContent():
|
|
66
67
|
forwardable_segs.append(UniHelper.img_seg(path))
|
|
67
68
|
case DynamicContent():
|
|
68
|
-
|
|
69
|
+
dynamic_segs.append(UniHelper.video_seg(path))
|
|
69
70
|
case GraphicsContent() as graphics:
|
|
70
71
|
graphics_msg = UniHelper.img_seg(path)
|
|
71
72
|
if graphics.text is not None:
|
|
@@ -76,11 +77,13 @@ class BaseRenderer(ABC):
|
|
|
76
77
|
|
|
77
78
|
if forwardable_segs:
|
|
78
79
|
if pconfig.need_forward_contents or len(forwardable_segs) > 4:
|
|
79
|
-
forward_msg = UniHelper.construct_forward_message(forwardable_segs)
|
|
80
|
+
forward_msg = UniHelper.construct_forward_message(forwardable_segs + dynamic_segs)
|
|
80
81
|
yield UniMessage(forward_msg)
|
|
81
82
|
else:
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
yield UniMessage(forwardable_segs)
|
|
84
|
+
|
|
85
|
+
if dynamic_segs:
|
|
86
|
+
yield UniMessage(UniHelper.construct_forward_message(dynamic_segs))
|
|
84
87
|
|
|
85
88
|
if failed_count > 0:
|
|
86
89
|
message = f"{failed_count} 项媒体下载失败"
|
|
File without changes
|
{nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/__init__.py
RENAMED
|
File without changes
|
{nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/config.py
RENAMED
|
File without changes
|
{nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/constants.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/exception.py
RENAMED
|
File without changes
|
{nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/helper.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/parsers/nga.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nonebot_plugin_parser-2.0.8 → nonebot_plugin_parser-2.0.9}/src/nonebot_plugin_parser/utils.py
RENAMED
|
File without changes
|