Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/nonebot_plugin_parser/parsers/acfun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/nonebot_plugin_parser/parsers/acfun/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion src/nonebot_plugin_parser/renders/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading