Skip to content

Commit

Permalink
fix eps not follow bangumi filter
Browse files Browse the repository at this point in the history
  • Loading branch information
shininome committed Sep 1, 2024
1 parent 04f8e3b commit 2872c9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/src/module/models/bangumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="是否已添加")
Expand Down
22 changes: 16 additions & 6 deletions backend/src/module/searcher/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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]

0 comments on commit 2872c9d

Please sign in to comment.