From 45945bd025d79133fc1383908b41d827f3aacd44 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 1 Jun 2024 07:47:00 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=A2=9E=E5=8A=A0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=B8=8B=E8=BD=BD=E4=BB=BB=E5=8A=A1=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E4=B8=AD=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=BA=90=E6=96=87=E4=BB=B6=E6=97=B6=E4=B8=BB=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E4=BC=9A=E5=90=8C=E6=AD=A5=E5=88=A0=E9=99=A4=E7=A7=8D?= =?UTF-8?q?=E5=AD=90=EF=BC=8C=E5=90=8C=E6=97=B6=E4=BC=9A=E5=8F=91=E5=87=BA?= =?UTF-8?q?=E8=AF=A5=E4=BA=8B=E4=BB=B6=EF=BC=88=E4=BB=A5=E4=BE=BF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E8=BE=85=E7=A7=8D=E7=AD=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/download.py | 13 ++++++++++++- app/modules/qbittorrent/__init__.py | 1 + app/modules/transmission/__init__.py | 1 + app/schemas/transfer.py | 1 + app/schemas/types.py | 2 ++ 5 files changed, 17 insertions(+), 1 deletion(-) 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消息