~cytrogen/kobo-manga

ref: 4e504823f4bf8d2b5f4279da3f4d4ebe98fc97ad kobo-manga/src/kobo_manga/sources/base.py -rw-r--r-- 1000 bytes
4e504823 — HallowDem Initial commit: kobo-manga pipeline a day ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""漫画源适配器基类

定义所有漫画源必须实现的接口。
"""

from abc import ABC, abstractmethod

from kobo_manga.models import Chapter, MangaInfo, PageImage


class BaseSource(ABC):
    """漫画源适配器抽象基类。"""

    name: str  # 子类必须声明,如 "manhuagui"
    URL_PATTERNS: list[str] = []  # 可选,用于从 URL 推断源,如 ["mangadex.org"]

    @abstractmethod
    async def search(self, keyword: str) -> list[MangaInfo]:
        """搜索漫画。"""

    @abstractmethod
    async def get_manga_info(self, manga_url: str) -> MangaInfo:
        """获取漫画详情(含章节列表)。"""

    @abstractmethod
    async def get_chapter_images(self, chapter: Chapter) -> list[PageImage]:
        """获取章节的图片列表。"""

    async def close(self) -> None:
        """释放资源(如 HTTP 客户端)。"""

    async def __aenter__(self):
        return self

    async def __aexit__(self, *args):
        await self.close()