From cfc8d265587419e7abf1b406a9b794377f4410f3 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 24 Mar 2026 18:53:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E4=BB=BB=E5=8A=A1=E5=B7=A5=E5=85=B7=E8=AE=BF?= =?UTF-8?q?=E9=97=AETransferTorrent=E4=B8=8D=E5=AD=98=E5=9C=A8=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/agent/tools/impl/query_download_tasks.py | 87 +++++++++++--------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/app/agent/tools/impl/query_download_tasks.py b/app/agent/tools/impl/query_download_tasks.py index 184bdb6f..433fed01 100644 --- a/app/agent/tools/impl/query_download_tasks.py +++ b/app/agent/tools/impl/query_download_tasks.py @@ -111,16 +111,18 @@ class QueryDownloadTasksTool(MoviePilotTool): # 获取下载历史信息 history = DownloadHistoryOper().get_by_hash(torrent.hash) if history: - torrent.media = { - "tmdbid": history.tmdbid, - "type": history.type, - "title": history.title, - "season": history.seasons, - "episode": history.episodes, - "image": history.image, - } + if hasattr(torrent, "media"): + torrent.media = { + "tmdbid": history.tmdbid, + "type": history.type, + "title": history.title, + "season": history.seasons, + "episode": history.episodes, + "image": history.image, + } + if hasattr(torrent, "username"): + torrent.username = history.username torrent.userid = history.userid - torrent.username = history.username downloads.append(torrent) filtered_downloads = downloads elif title: @@ -137,7 +139,7 @@ class QueryDownloadTasksTool(MoviePilotTool): matched = False # 检查torrent的title和name字段 if (title_lower in (torrent.title or "").lower()) or \ - (title_lower in (torrent.name or "").lower()): + (title_lower in (getattr(torrent, "name", None) or "").lower()): matched = True # 检查下载历史中的标题 if history and history.title: @@ -146,16 +148,18 @@ class QueryDownloadTasksTool(MoviePilotTool): if matched: if history: - torrent.media = { - "tmdbid": history.tmdbid, - "type": history.type, - "title": history.title, - "season": history.seasons, - "episode": history.episodes, - "image": history.image, - } + if hasattr(torrent, "media"): + torrent.media = { + "tmdbid": history.tmdbid, + "type": history.type, + "title": history.title, + "season": history.seasons, + "episode": history.episodes, + "image": history.image, + } + if hasattr(torrent, "username"): + torrent.username = history.username torrent.userid = history.userid - torrent.username = history.username filtered_downloads.append(torrent) if not filtered_downloads: return f"未找到标题包含 '{title}' 的下载任务" @@ -190,16 +194,18 @@ class QueryDownloadTasksTool(MoviePilotTool): # 获取下载历史信息 history = DownloadHistoryOper().get_by_hash(torrent.hash) if history: - torrent.media = { - "tmdbid": history.tmdbid, - "type": history.type, - "title": history.title, - "season": history.seasons, - "episode": history.episodes, - "image": history.image, - } + if hasattr(torrent, "media"): + torrent.media = { + "tmdbid": history.tmdbid, + "type": history.type, + "title": history.title, + "season": history.seasons, + "episode": history.episodes, + "image": history.image, + } + if hasattr(torrent, "username"): + torrent.username = history.username torrent.userid = history.userid - torrent.username = history.username filtered_downloads.append(torrent) # 按tag过滤 if tag and filtered_downloads: @@ -221,25 +227,26 @@ class QueryDownloadTasksTool(MoviePilotTool): "downloader": d.downloader, "hash": d.hash, "title": d.title, - "name": d.name, - "year": d.year, - "season_episode": d.season_episode, + "name": getattr(d, "name", None), + "year": getattr(d, "year", None), + "season_episode": getattr(d, "season_episode", None), "size": d.size, "progress": self._format_progress(d.progress), "state": d.state, - "upspeed": d.upspeed, - "dlspeed": d.dlspeed, + "upspeed": getattr(d, "upspeed", None), + "dlspeed": getattr(d, "dlspeed", None), "tags": d.tags, - "left_time": d.left_time + "left_time": getattr(d, "left_time", None) } # 精简 media 字段 - if d.media: + media = getattr(d, "media", None) + if media: simplified["media"] = { - "tmdbid": d.media.get("tmdbid"), - "type": media_type_to_agent(d.media.get("type")), - "title": d.media.get("title"), - "season": d.media.get("season"), - "episode": d.media.get("episode") + "tmdbid": media.get("tmdbid"), + "type": media_type_to_agent(media.get("type")), + "title": media.get("title"), + "season": media.get("season"), + "episode": media.get("episode") } simplified_downloads.append(simplified) result_json = json.dumps(simplified_downloads, ensure_ascii=False, indent=2)