diff --git a/app/chain/download.py b/app/chain/download.py index 0b8adcad..76878a31 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -6,6 +6,7 @@ import time from pathlib import Path from typing import List, Optional, Tuple, Set, Dict, Union +from app import schemas from app.chain import ChainBase from app.core.config import settings from app.core.context import MediaInfo, TorrentInfo, Context @@ -908,4 +909,14 @@ class DownloadChain(ChainBase): if not hash_str: return logger.warn(f"检测到下载源文件被删除,删除下载任务(不含文件):{hash_str}") - self.remove_torrents(hashs=[hash_str], delete_file=False) + # 先查询种子 + torrents: List[schemas.TransferTorrent] = self.list_torrents(hashs=[hash_str]) + if torrents: + self.remove_torrents(hashs=[hash_str], delete_file=False) + # 发出下载任务删除事件,如需处理辅种,可监听该事件 + self.eventmanager.send_event(EventType.DownloadDeleted, { + "hash": hash_str, + "torrents": [torrent.dict() for torrent in torrents] + }) + else: + logger.info(f"没有在下载器中查询到 {hash_str} 对应的下载任务") diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index ac7cdae3..31cfa8e7 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -197,6 +197,7 @@ class QbittorrentModule(_ModuleBase): title=torrent.get('name'), path=torrent_path, hash=torrent.get('hash'), + size=torrent.get('total_size'), tags=torrent.get('tags') )) elif status == TorrentStatus.TRANSFER: diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index bb8f79fc..1e0dc624 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -185,6 +185,7 @@ class TransmissionModule(_ModuleBase): title=torrent.name, path=Path(torrent.download_dir) / torrent.name, hash=torrent.hashString, + size=torrent.total_size, tags=",".join(torrent.labels or []) )) elif status == TorrentStatus.TRANSFER: diff --git a/app/schemas/transfer.py b/app/schemas/transfer.py index 6fb5e4d4..39b10eeb 100644 --- a/app/schemas/transfer.py +++ b/app/schemas/transfer.py @@ -12,6 +12,7 @@ class TransferTorrent(BaseModel): path: Optional[Path] = None hash: Optional[str] = None tags: Optional[str] = None + size: Optional[int] = 0 userid: Optional[str] = None diff --git a/app/schemas/types.py b/app/schemas/types.py index 1a91ac4b..cde3ec20 100644 --- a/app/schemas/types.py +++ b/app/schemas/types.py @@ -32,6 +32,8 @@ class EventType(Enum): HistoryDeleted = "history.deleted" # 删除下载源文件 DownloadFileDeleted = "downloadfile.deleted" + # 删除下载任务 + DownloadDeleted = "download.deleted" # 收到用户外来消息 UserMessage = "user.message" # 收到Webhook消息