mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-05-11 18:45:58 +08:00
fix: fix bugs.
This commit is contained in:
@@ -1,56 +1,43 @@
|
||||
import logging
|
||||
|
||||
from module.database import BangumiDatabase
|
||||
from module.downloader import DownloadClient
|
||||
from module.models import Bangumi
|
||||
from module.searcher import SearchTorrent
|
||||
from module.rss import RSSEngine
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SeasonCollector(DownloadClient):
|
||||
def add_season_torrents(self, data: Bangumi, torrents, torrent_files=None):
|
||||
if torrent_files:
|
||||
download_info = {
|
||||
"torrent_files": torrent_files,
|
||||
"save_path": self._gen_save_path(data),
|
||||
}
|
||||
return self.add_torrent(download_info)
|
||||
else:
|
||||
download_info = {
|
||||
"urls": [torrent.torrent_link for torrent in torrents],
|
||||
"save_path": self._gen_save_path(data),
|
||||
}
|
||||
return self.add_torrent(download_info)
|
||||
def add_season_torrents(self, bangumi: Bangumi, torrents: list):
|
||||
return self.add_torrent(bangumi=bangumi, torrent=torrents)
|
||||
|
||||
def collect_season(self, data: Bangumi, link: str = None, proxy: bool = False):
|
||||
logger.info(f"Start collecting {data.official_title} Season {data.season}...")
|
||||
def collect_season(self, bangumi: Bangumi, link: str = None):
|
||||
logger.info(
|
||||
f"Start collecting {bangumi.official_title} Season {bangumi.season}..."
|
||||
)
|
||||
with SearchTorrent() as st:
|
||||
if not link:
|
||||
torrents = st.search_season(data)
|
||||
torrents = st.search_season(bangumi)
|
||||
else:
|
||||
torrents = st.get_torrents(link, _filter="|".join(data.filter))
|
||||
torrents = st.get_torrents(link, _filter="|".join(bangumi.filter))
|
||||
torrent_files = None
|
||||
if proxy:
|
||||
torrent_files = [
|
||||
st.get_content(torrent.torrent_link) for torrent in torrents
|
||||
]
|
||||
return self.add_season_torrents(
|
||||
data=data, torrents=torrents, torrent_files=torrent_files
|
||||
)
|
||||
return self.add_season_torrents(bangumi=bangumi, torrents=torrents)
|
||||
|
||||
def subscribe_season(self, data: Bangumi):
|
||||
with BangumiDatabase() as db:
|
||||
@staticmethod
|
||||
def subscribe_season(data: Bangumi):
|
||||
with RSSEngine() as engine:
|
||||
data.added = True
|
||||
data.eps_collect = True
|
||||
self.set_rule(data)
|
||||
db.insert(data)
|
||||
self.add_rss_feed(data.rss_link[0], item_path=data.official_title)
|
||||
engine.add_rss(
|
||||
rss_link=data.rss_link, name=data.official_title, combine=False
|
||||
)
|
||||
engine.bangumi.add(data)
|
||||
|
||||
|
||||
def eps_complete():
|
||||
with BangumiDatabase() as bd:
|
||||
datas = bd.not_complete()
|
||||
with RSSEngine() as engine:
|
||||
datas = engine.bangumi.not_complete()
|
||||
if datas:
|
||||
logger.info("Start collecting full season...")
|
||||
for data in datas:
|
||||
@@ -58,4 +45,4 @@ def eps_complete():
|
||||
with SeasonCollector() as sc:
|
||||
sc.collect_season(data)
|
||||
data.eps_collect = True
|
||||
bd.update_list(datas)
|
||||
engine.bangumi.update_all(datas)
|
||||
|
||||
@@ -2,14 +2,14 @@ import logging
|
||||
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from module.database import BangumiDatabase
|
||||
from module.database import Database
|
||||
from module.downloader import DownloadClient
|
||||
from module.models import Bangumi
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TorrentManager(BangumiDatabase):
|
||||
class TorrentManager(Database):
|
||||
@staticmethod
|
||||
def __match_torrents_list(data: Bangumi) -> list:
|
||||
with DownloadClient() as client:
|
||||
@@ -28,12 +28,12 @@ class TorrentManager(BangumiDatabase):
|
||||
return f"Can't find {data.official_title} torrents."
|
||||
|
||||
def delete_rule(self, _id: int | str, file: bool = False):
|
||||
data = self.search_id(int(_id))
|
||||
data = self.bangumi.search_id(int(_id))
|
||||
if isinstance(data, Bangumi):
|
||||
with DownloadClient() as client:
|
||||
client.remove_rule(data.rule_name)
|
||||
client.remove_rss_feed(data.official_title)
|
||||
self.delete_one(int(_id))
|
||||
self.bangumi.delete_one(int(_id))
|
||||
if file:
|
||||
torrent_message = self.delete_torrents(data, client)
|
||||
return JSONResponse(
|
||||
@@ -53,12 +53,12 @@ class TorrentManager(BangumiDatabase):
|
||||
)
|
||||
|
||||
def disable_rule(self, _id: str | int, file: bool = False):
|
||||
data = self.search_id(int(_id))
|
||||
data = self.bangumi.search_id(int(_id))
|
||||
if isinstance(data, Bangumi):
|
||||
with DownloadClient() as client:
|
||||
client.remove_rule(data.rule_name)
|
||||
data.deleted = True
|
||||
self.update_one(data)
|
||||
self.bangumi.update(data)
|
||||
if file:
|
||||
torrent_message = self.delete_torrents(data, client)
|
||||
return JSONResponse(
|
||||
@@ -80,10 +80,10 @@ class TorrentManager(BangumiDatabase):
|
||||
)
|
||||
|
||||
def enable_rule(self, _id: str | int):
|
||||
data = self.search_id(int(_id))
|
||||
data = self.bangumi.search(int(_id))
|
||||
if isinstance(data, Bangumi):
|
||||
data.deleted = False
|
||||
self.update_one(data)
|
||||
self.bangumi.update(data)
|
||||
with DownloadClient() as client:
|
||||
client.set_rule(data)
|
||||
logger.info(f"[Manager] Enable rule for {data.official_title}")
|
||||
@@ -99,7 +99,7 @@ class TorrentManager(BangumiDatabase):
|
||||
)
|
||||
|
||||
def update_rule(self, data: Bangumi):
|
||||
old_data = self.search_id(data.id)
|
||||
old_data = self.bangumi.search_id(data.id)
|
||||
if not old_data:
|
||||
logger.error(f"[Manager] Can't find data with {data.id}")
|
||||
return JSONResponse(
|
||||
@@ -115,7 +115,7 @@ class TorrentManager(BangumiDatabase):
|
||||
# Set new download rule
|
||||
client.remove_rule(data.rule_name)
|
||||
client.set_rule(data)
|
||||
self.update_one(data)
|
||||
self.bangumi.update(data)
|
||||
return JSONResponse(
|
||||
status_code=200,
|
||||
content={
|
||||
@@ -124,13 +124,13 @@ class TorrentManager(BangumiDatabase):
|
||||
)
|
||||
|
||||
def search_all_bangumi(self):
|
||||
datas = self.search_all()
|
||||
datas = self.bangumi.search_all()
|
||||
if not datas:
|
||||
return []
|
||||
return [data for data in datas if not data.deleted]
|
||||
|
||||
def search_one(self, _id: int | str):
|
||||
data = self.search_id(int(_id))
|
||||
data = self.bangumi.search_id(int(_id))
|
||||
if not data:
|
||||
logger.error(f"[Manager] Can't find data with {_id}")
|
||||
return {"status": "error", "msg": f"Can't find data with {_id}"}
|
||||
|
||||
Reference in New Issue
Block a user