refactor: change downloader action,

This commit is contained in:
EstrellaXD
2023-10-12 11:37:08 +08:00
parent 8fe833251a
commit 18ccc11955
2 changed files with 4 additions and 13 deletions

View File

@@ -129,10 +129,11 @@ class BangumiDatabase:
i += 1
return torrent_list
def match_torrent(self, torrent_name: str) -> Optional[Bangumi]:
def match_torrent(self, torrent_name: str, rss_link: str) -> Optional[Bangumi]:
statement = select(Bangumi).where(
and_(
func.instr(torrent_name, Bangumi.title_raw) > 0,
func.instr(Bangumi.rss_link, rss_link),
# use `false()` to avoid E712 checking
# see: https://docs.astral.sh/ruff/rules/true-false-comparison/
Bangumi.deleted == false(),

View File

@@ -17,7 +17,7 @@ class QbDownloader:
data={"username": self.username, "password": self.password},
timeout=5,
)
return resp.text
return resp.text == "Ok."
async def logout(self):
logout_api = "/api/v2/auth/logout"
@@ -131,17 +131,7 @@ class QbDownloader:
self._client = httpx.AsyncClient(
base_url=self.host,
)
try:
authed = await self.auth()
if not authed == "Ok.":
logger.error("[Downloader] Failed authing to qbittorrent.")
logger.warning("[Downloader] Please check username/password in settings.")
raise RuntimeError(authed)
return self
except httpx.ReadTimeout:
logger.error("[Downloader] Failed connecting to qbittorrent.")
logger.warning("[Downloader] Please check host in settings.")
raise RuntimeError("Failed connecting to qbittorrent.")
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.logout()