~cytrogen/kobo-manga

ref: feat/web-ui kobo-manga/src/kobo_manga/utils.py -rw-r--r-- 525 bytes
72dde718 — HallowDem feat(web): FastAPI UI and Kobo sync protocol endpoints 14 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""共享工具函数"""


def sanitize_filename(name: str) -> str:
    """清理文件名中的非法字符。"""
    return "".join(
        c if c.isalnum() or c in " _-()()【】" else "_" for c in name
    )


def parse_chapter_range(chapters: str) -> tuple[float, float]:
    """解析章节范围字符串。

    支持格式: "1-10", "5", "0-2.5"
    """
    if "-" in chapters:
        parts = chapters.split("-", 1)
        return float(parts[0]), float(parts[1])
    num = float(chapters)
    return num, num