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,