mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-05-11 18:45:58 +08:00
fix: engine bugs
This commit is contained in:
@@ -89,7 +89,7 @@ class BangumiDatabase:
|
||||
def match_poster(self, bangumi_name: str) -> str:
|
||||
# Use like to match
|
||||
statement = select(Bangumi).where(
|
||||
func.instr(bangumi_name, Bangumi.title_raw) > 0
|
||||
func.instr(bangumi_name, Bangumi.official_title) > 0
|
||||
)
|
||||
data = self.session.exec(statement).first()
|
||||
if data:
|
||||
|
||||
@@ -20,7 +20,7 @@ class Bangumi(SQLModel, table=True):
|
||||
subtitle: Optional[str] = Field(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="720,\\d+-\\d+", alias="filter", title="番剧过滤器")
|
||||
rss_link: str = Field(default="", alias="rss_link", title="番剧RSS链接")
|
||||
poster_link: Optional[str] = Field(alias="poster_link", title="番剧海报链接")
|
||||
added: bool = Field(default=False, alias="added", title="是否已添加")
|
||||
|
||||
@@ -44,17 +44,18 @@ class RSSEngine(Database):
|
||||
def match_torrent(self, torrent: Torrent):
|
||||
matched: Bangumi = self.bangumi.match_torrent(torrent.name)
|
||||
if matched:
|
||||
torrent.refer_id = matched.id
|
||||
torrent.save_path = matched.save_path
|
||||
with RequestContent() as req:
|
||||
torrent_file = req.get_content(torrent.url)
|
||||
with DownloadClient() as client:
|
||||
client.add_torrent(
|
||||
{"torrent_files": torrent_file, "save_path": torrent.save_path}
|
||||
)
|
||||
torrent.downloaded = True
|
||||
_filter = matched.filter.replace(",", "|")
|
||||
if re.search(_filter, torrent.name, re.IGNORECASE):
|
||||
torrent.refer_id = matched.id
|
||||
torrent.save_path = matched.save_path
|
||||
with RequestContent() as req:
|
||||
torrent_file = req.get_content(torrent.url)
|
||||
return {
|
||||
"torrent_files": torrent_file,
|
||||
"save_path": torrent.save_path,
|
||||
}
|
||||
|
||||
def run(self):
|
||||
def run(self, client: DownloadClient):
|
||||
# Get All RSS Items
|
||||
rss_items: list[RSSItem] = self.rss.search_active()
|
||||
# From RSS Items, get all torrents
|
||||
@@ -62,7 +63,10 @@ class RSSEngine(Database):
|
||||
new_torrents = self.pull_rss(rss_item)
|
||||
# Get all enabled bangumi data
|
||||
for torrent in new_torrents:
|
||||
self.match_torrent(torrent)
|
||||
download_info = self.match_torrent(torrent)
|
||||
client.add_torrent(download_info)
|
||||
torrent.downloaded = True
|
||||
# Add all torrents to database
|
||||
self.torrent.add_all(new_torrents)
|
||||
|
||||
|
||||
|
||||
@@ -13,15 +13,15 @@ engine = create_engine(
|
||||
|
||||
def test_bangumi_database():
|
||||
test_data = Bangumi(
|
||||
official_title="test",
|
||||
official_title="无职转生,到了异世界就拿出真本事",
|
||||
year="2021",
|
||||
title_raw="test",
|
||||
title_raw="Mushoku Tensei",
|
||||
season=1,
|
||||
season_raw="第一季",
|
||||
group_name="test",
|
||||
dpi="720p",
|
||||
source="test",
|
||||
subtitle="test",
|
||||
season_raw="",
|
||||
group_name="Lilith-Raws",
|
||||
dpi="1080p",
|
||||
source="Baha",
|
||||
subtitle="CHT",
|
||||
eps_collect=False,
|
||||
offset=0,
|
||||
filter="720p,\\d+-\\d+",
|
||||
@@ -29,7 +29,7 @@ def test_bangumi_database():
|
||||
poster_link="/test/test.jpg",
|
||||
added=False,
|
||||
rule_name=None,
|
||||
save_path=None,
|
||||
save_path="downloads/无职转生,到了异世界就拿出真本事/Season 1",
|
||||
deleted=False,
|
||||
)
|
||||
with Database(engine) as db:
|
||||
@@ -39,16 +39,16 @@ def test_bangumi_database():
|
||||
assert db.bangumi.search_id(1) == test_data
|
||||
|
||||
# update
|
||||
test_data.official_title = "test2"
|
||||
test_data.official_title = "无职转生,到了异世界就拿出真本事II"
|
||||
db.bangumi.update(test_data)
|
||||
assert db.bangumi.search_id(1) == test_data
|
||||
|
||||
# search poster
|
||||
assert db.bangumi.match_poster("test2 (2021)") == "/test/test.jpg"
|
||||
assert db.bangumi.match_poster("无职转生,到了异世界就拿出真本事II (2021)") == "/test/test.jpg"
|
||||
|
||||
# match torrent
|
||||
result = db.bangumi.match_torrent("[Sub Group]test S02 01 [720p].mkv")
|
||||
assert result.official_title == "test2"
|
||||
result = db.bangumi.match_torrent("[Lilith-Raws] 无职转生,到了异世界就拿出真本事 / Mushoku Tensei - 11 [Baha][WEB-DL][1080p][AVC AAC][CHT][MP4]")
|
||||
assert result.official_title == "无职转生,到了异世界就拿出真本事II"
|
||||
|
||||
# delete
|
||||
db.bangumi.delete_one(1)
|
||||
|
||||
@@ -10,13 +10,9 @@ def test_rss_engine():
|
||||
engine.add_rss(rss_link, combine=False)
|
||||
|
||||
result = engine.rss.search_active()
|
||||
|
||||
assert result[1].item_path == "Mikan Project - 无职转生~到了异世界就拿出真本事~"
|
||||
|
||||
new_torrents = engine.pull_rss(result[1])
|
||||
torrent = new_torrents[0]
|
||||
|
||||
assert torrent.name == "[Lilith-Raws] 无职转生,到了异世界就拿出真本事 / Mushoku Tensei - 11 [Baha][WEB-DL][1080p][AVC AAC][CHT][MP4]"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user