From 5294d573fb469422d9852bd7bffbd178da704b30 Mon Sep 17 00:00:00 2001 From: fllesser Date: Thu, 1 Jan 2026 23:23:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20BytesIO=20=E9=A2=84?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=AD=97=E4=BD=93=EF=BC=8C=E4=BB=A5=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=AD=97=E4=BD=93=E6=8C=81=E7=BB=AD=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nonebot_plugin_parser/parsers/acfun/__init__.py | 4 +--- src/nonebot_plugin_parser/parsers/acfun/video.py | 5 ----- src/nonebot_plugin_parser/renders/common.py | 8 +++++++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/nonebot_plugin_parser/parsers/acfun/__init__.py b/src/nonebot_plugin_parser/parsers/acfun/__init__.py index 33be974e..3061575a 100644 --- a/src/nonebot_plugin_parser/parsers/acfun/__init__.py +++ b/src/nonebot_plugin_parser/parsers/acfun/__init__.py @@ -139,10 +139,8 @@ async def _get_m3u8_slices(self, m3u8_url: str): response = await client.get(m3u8_url) response.raise_for_status() - slices_text = response.text - slices: list[str] = [] - for line in slices_text.splitlines(): + for line in response.text.splitlines(): line = line.strip() if not line or line.startswith("#"): continue diff --git a/src/nonebot_plugin_parser/parsers/acfun/video.py b/src/nonebot_plugin_parser/parsers/acfun/video.py index 6cd8d64f..b9b58fed 100644 --- a/src/nonebot_plugin_parser/parsers/acfun/video.py +++ b/src/nonebot_plugin_parser/parsers/acfun/video.py @@ -9,13 +9,8 @@ class User(Struct): class Representation(Struct): url: str - m3u8Slice: str qualityType: str - @property - def m3u8_slice(self) -> str: - return self.m3u8Slice.replace("\\\\n", "\n") - class AdaptationSet(Struct): representation: list[Representation] diff --git a/src/nonebot_plugin_parser/renders/common.py b/src/nonebot_plugin_parser/renders/common.py index fff98147..f3bf9412 100644 --- a/src/nonebot_plugin_parser/renders/common.py +++ b/src/nonebot_plugin_parser/renders/common.py @@ -128,9 +128,15 @@ class FontSet: @classmethod def new(cls, font_path: Path): + # 预加载字体文件到内存,避免持续占用文件句柄 + with open(font_path, "rb") as f: + font_data = BytesIO(f.read()) + font_infos: dict[str, FontInfo] = {} for name, size, fill in cls._FONT_INFOS: - font = ImageFont.truetype(font_path, size) + # 每次使用都需要 seek(0) 重置指针,因为多个 truetype 调用共享同一个 BytesIO 对象 + font_data.seek(0) + font = ImageFont.truetype(font_data, size) height = get_font_height(font) font_infos[name] = FontInfo( font=font,