fix: 修复查询下载任务工具访问TransferTorrent不存在字段的问题

This commit is contained in:
jxxghp
2026-03-24 18:53:08 +08:00
parent 1c16b8bfec
commit cfc8d26558
+47 -40
View File
@@ -111,16 +111,18 @@ class QueryDownloadTasksTool(MoviePilotTool):
# 获取下载历史信息 # 获取下载历史信息
history = DownloadHistoryOper().get_by_hash(torrent.hash) history = DownloadHistoryOper().get_by_hash(torrent.hash)
if history: if history:
torrent.media = { if hasattr(torrent, "media"):
"tmdbid": history.tmdbid, torrent.media = {
"type": history.type, "tmdbid": history.tmdbid,
"title": history.title, "type": history.type,
"season": history.seasons, "title": history.title,
"episode": history.episodes, "season": history.seasons,
"image": history.image, "episode": history.episodes,
} "image": history.image,
}
if hasattr(torrent, "username"):
torrent.username = history.username
torrent.userid = history.userid torrent.userid = history.userid
torrent.username = history.username
downloads.append(torrent) downloads.append(torrent)
filtered_downloads = downloads filtered_downloads = downloads
elif title: elif title:
@@ -137,7 +139,7 @@ class QueryDownloadTasksTool(MoviePilotTool):
matched = False matched = False
# 检查torrent的title和name字段 # 检查torrent的title和name字段
if (title_lower in (torrent.title or "").lower()) or \ 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 matched = True
# 检查下载历史中的标题 # 检查下载历史中的标题
if history and history.title: if history and history.title:
@@ -146,16 +148,18 @@ class QueryDownloadTasksTool(MoviePilotTool):
if matched: if matched:
if history: if history:
torrent.media = { if hasattr(torrent, "media"):
"tmdbid": history.tmdbid, torrent.media = {
"type": history.type, "tmdbid": history.tmdbid,
"title": history.title, "type": history.type,
"season": history.seasons, "title": history.title,
"episode": history.episodes, "season": history.seasons,
"image": history.image, "episode": history.episodes,
} "image": history.image,
}
if hasattr(torrent, "username"):
torrent.username = history.username
torrent.userid = history.userid torrent.userid = history.userid
torrent.username = history.username
filtered_downloads.append(torrent) filtered_downloads.append(torrent)
if not filtered_downloads: if not filtered_downloads:
return f"未找到标题包含 '{title}' 的下载任务" return f"未找到标题包含 '{title}' 的下载任务"
@@ -190,16 +194,18 @@ class QueryDownloadTasksTool(MoviePilotTool):
# 获取下载历史信息 # 获取下载历史信息
history = DownloadHistoryOper().get_by_hash(torrent.hash) history = DownloadHistoryOper().get_by_hash(torrent.hash)
if history: if history:
torrent.media = { if hasattr(torrent, "media"):
"tmdbid": history.tmdbid, torrent.media = {
"type": history.type, "tmdbid": history.tmdbid,
"title": history.title, "type": history.type,
"season": history.seasons, "title": history.title,
"episode": history.episodes, "season": history.seasons,
"image": history.image, "episode": history.episodes,
} "image": history.image,
}
if hasattr(torrent, "username"):
torrent.username = history.username
torrent.userid = history.userid torrent.userid = history.userid
torrent.username = history.username
filtered_downloads.append(torrent) filtered_downloads.append(torrent)
# 按tag过滤 # 按tag过滤
if tag and filtered_downloads: if tag and filtered_downloads:
@@ -221,25 +227,26 @@ class QueryDownloadTasksTool(MoviePilotTool):
"downloader": d.downloader, "downloader": d.downloader,
"hash": d.hash, "hash": d.hash,
"title": d.title, "title": d.title,
"name": d.name, "name": getattr(d, "name", None),
"year": d.year, "year": getattr(d, "year", None),
"season_episode": d.season_episode, "season_episode": getattr(d, "season_episode", None),
"size": d.size, "size": d.size,
"progress": self._format_progress(d.progress), "progress": self._format_progress(d.progress),
"state": d.state, "state": d.state,
"upspeed": d.upspeed, "upspeed": getattr(d, "upspeed", None),
"dlspeed": d.dlspeed, "dlspeed": getattr(d, "dlspeed", None),
"tags": d.tags, "tags": d.tags,
"left_time": d.left_time "left_time": getattr(d, "left_time", None)
} }
# 精简 media 字段 # 精简 media 字段
if d.media: media = getattr(d, "media", None)
if media:
simplified["media"] = { simplified["media"] = {
"tmdbid": d.media.get("tmdbid"), "tmdbid": media.get("tmdbid"),
"type": media_type_to_agent(d.media.get("type")), "type": media_type_to_agent(media.get("type")),
"title": d.media.get("title"), "title": media.get("title"),
"season": d.media.get("season"), "season": media.get("season"),
"episode": d.media.get("episode") "episode": media.get("episode")
} }
simplified_downloads.append(simplified) simplified_downloads.append(simplified)
result_json = json.dumps(simplified_downloads, ensure_ascii=False, indent=2) result_json = json.dumps(simplified_downloads, ensure_ascii=False, indent=2)