添加数据源

数据源应该是可以通过pip安装,由pypi分发的python package。尽量不内置在 BGmi 中。

需要继承 bgmi.protocol.source.Base,并且实现所有的抽象方法,并且提供所有所需的类属性。

确保你的类可以实例化,对应的metaclass会是否实现了所有的抽象方法。

返回的 bgmi.protocol.source.Episode 等数据类型用到了 pydantic。 可以查阅 pydantic的文档 了解更多用法。

from typing import List, Tuple

import bgmi3.protocol.source
from bgmi3.protocol import source


class MySource(source.Base):
    name = "my source"
    id = "my-source"

    def fetch_series_and_subtitle_group(
        self,
    ) -> Tuple[List[source.Series], List[source.Subtitle]]:
        return (
            [
                bgmi3.protocol.source.Series.parse_obj(
                    {
                        "id": "1",
                        "status": 0,
                        "update_time": "mon",
                        "subtitle_group": ["1", "2"],
                        "name": "ID:INVADED",
                    }
                ),
                bgmi3.protocol.source.Series.parse_obj(
                    {
                        "id": "2",
                        "update_time": "Fri",
                        "subtitle_group": ["1"],
                        "name": "科学的超电磁炮T",
                    }
                ),
            ],
            [
                source.Subtitle(id="1", name="subtitle group 1"),
                source.Subtitle(id="2", name="subtitle group 2"),
            ],
        )

    def fetch_episode_of_series(
        self, series_id: str, max_page: int, subtitle_list: List[str] = None
    ) -> List[source.Episode]:
        return [
            source.Episode.parse_obj(
                {
                    "title": "title",
                    "download": "magnet:?xt=urn:btih:233",
                    "episode": 1,
                    "time": 1582200671,
                    "subtitle_group": "1",
                }
            ),
            source.Episode.parse_obj(
                {
                    "title": "title",
                    "download": "https://example.com/a.torrent",
                    "episode": 2,
                    "time": "2019-12-15",
                }
            ),
        ]

    def search_by_keyword(
        self, keyword: str, max_page: int = None
    ) -> List[source.Episode]:
        return [
            source.Episode.parse_obj(
                {
                    "title": "title",
                    "download": "https://example.com/a.torrent",
                    "episode": 2,
                    "time": "2019-12-15",
                }
            ),
        ]

setup.py:

from setuptools import setup

setup(
    name="my plugin name",
    entry_points={"bgmi3.extensions.source": ["my-plugin-id = my_source:MySource"]},
)

待处理

应该有一个github template repo,不应该把 setup.py 的例子也放在这个仓库中