From 2872c9d59a836cdead78cfaad53b58405cff3f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=B1=E9=9B=B2=E6=9F=8A?= Date: Sun, 1 Sep 2024 23:16:45 +0800 Subject: [PATCH] fix eps not follow bangumi filter --- backend/src/module/models/bangumi.py | 2 +- backend/src/module/searcher/searcher.py | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/backend/src/module/models/bangumi.py b/backend/src/module/models/bangumi.py index 0eca0b0c..28f60b58 100644 --- a/backend/src/module/models/bangumi.py +++ b/backend/src/module/models/bangumi.py @@ -19,7 +19,7 @@ class Bangumi(SQLModel, table=True): subtitle: str|None = Field(default=None,alias="subtitle", title="字幕") eps_collect: bool = Field(default=False, alias="eps_collect", title="是否已收集") offset: int = Field(default=0, alias="offset", title="番剧偏移量") - filter: str = Field(default="720,\\d+-\\d+", alias="filter", title="番剧过滤器") + filter: str = Field(default="", alias="filter", title="番剧过滤器") rss_link: str = Field(default="", alias="rss_link", title="番剧RSS链接") poster_link: str|None = Field(default=None,alias="poster_link", title="番剧海报链接") added: bool = Field(default=False, alias="added", title="是否已添加") diff --git a/backend/src/module/searcher/searcher.py b/backend/src/module/searcher/searcher.py index 8fe45f7f..44f69b29 100644 --- a/backend/src/module/searcher/searcher.py +++ b/backend/src/module/searcher/searcher.py @@ -4,7 +4,7 @@ from typing import TypeAlias from module.conf import settings -from module.models import Bangumi, RSSItem, Torrent +from module.models import Bangumi, RSSItem, Torrent, bangumi from module.network import RequestContent from module.parser.title_parser import RawParser from module.rss.engine import RSSEngine @@ -27,13 +27,14 @@ class SearchTorrent: def __init__(self) -> None: self.req = RequestContent - async def search_torrents(self, rss_item: RSSItem) -> list[Torrent]: + async def search_torrents(self, rss_item: RSSItem,bangumi_item:Bangumi|None=None) -> list[Torrent]: async with self.req() as req: torrents = await req.get_torrents(rss_item.url) - new_torrents = [] - - filter = "|".join(settings.rss_parser.filter) + if bangumi_item: + filter = "|".join(bangumi_item.filter.split(",")) + else: + filter = "|".join(settings.rss_parser.filter) for torrent in torrents: if RSSEngine().match_torrent(torrent, bangumi=Bangumi(filter=filter)): new_torrents.append(torrent) @@ -90,7 +91,16 @@ def special_url(data: Bangumi, site: str) -> RSSItem: return url async def search_season(self, data: Bangumi, site: str = "mikan") -> list[Torrent]: + """for eps + + Args: + data: [TODO:description] + site: [TODO:description] + + Returns: + [TODO:return] + """ rss_item = self.special_url(data, site) - torrents = await self.search_torrents(rss_item) + torrents = await self.search_torrents(rss_item,data) return [torrent for torrent in torrents if data.title_raw in torrent.name]