diff --git a/src/module/models/__init__.py b/src/module/models/__init__.py index 508d68f1..823d65c7 100644 --- a/src/module/models/__init__.py +++ b/src/module/models/__init__.py @@ -3,3 +3,4 @@ from .config import Config from .torrent import EpisodeFile, SubtitleFile from .user import UserLogin from .torrent import TorrentBase +from .rss import RSSTorrents diff --git a/src/module/models/rss.py b/src/module/models/rss.py new file mode 100644 index 00000000..b65e68be --- /dev/null +++ b/src/module/models/rss.py @@ -0,0 +1,10 @@ +from pydantic import BaseModel, Field + + +class RSSTorrents(BaseModel): + name: str = Field(..., alias="item_path") + url: str = Field(..., alias="url") + analyze: bool = Field(..., alias="analyze") + enabled: bool = Field(..., alias="enabled") + torrents: list[str] = Field(..., alias="torrents") + diff --git a/src/module/rss/poller.py b/src/module/rss/poller.py new file mode 100644 index 00000000..604fc0c8 --- /dev/null +++ b/src/module/rss/poller.py @@ -0,0 +1,28 @@ +import re + +from module.database import RSSDatabase +from module.network import RequestContent, TorrentInfo +from module.models import BangumiData, RSSTorrents +from module.conf import settings + + +class RSSPoller(RSSDatabase): + + @staticmethod + def polling(rss_link, req: RequestContent) -> list[TorrentInfo]: + return req.get_torrents(rss_link) + + @staticmethod + def filter_torrent(data: BangumiData, torrent: TorrentInfo) -> bool: + if data.title_raw in torrent.name: + _filter = "|".join(data.filter) + if not re.search(_filter, torrent.name): + return True + else: + return False + + def foo(self): + rss_datas: list[RSSTorrents] = self.get_rss_data() + with RequestContent() as req: + for rss_data in rss_datas: + torrents = self.polling(rss_data.url, req)