feat:增加删除下载任务事件,历史记录中删除源文件时主程序会同步删除种子,同时会发出该事件(以便处理辅种等)

This commit is contained in:
jxxghp
2024-06-01 07:47:00 +08:00
parent acff7e0610
commit 45945bd025
5 changed files with 17 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import time
from pathlib import Path from pathlib import Path
from typing import List, Optional, Tuple, Set, Dict, Union from typing import List, Optional, Tuple, Set, Dict, Union
from app import schemas
from app.chain import ChainBase from app.chain import ChainBase
from app.core.config import settings from app.core.config import settings
from app.core.context import MediaInfo, TorrentInfo, Context from app.core.context import MediaInfo, TorrentInfo, Context
@ -908,4 +909,14 @@ class DownloadChain(ChainBase):
if not hash_str: if not hash_str:
return return
logger.warn(f"检测到下载源文件被删除,删除下载任务(不含文件):{hash_str}") 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} 对应的下载任务")

View File

@ -197,6 +197,7 @@ class QbittorrentModule(_ModuleBase):
title=torrent.get('name'), title=torrent.get('name'),
path=torrent_path, path=torrent_path,
hash=torrent.get('hash'), hash=torrent.get('hash'),
size=torrent.get('total_size'),
tags=torrent.get('tags') tags=torrent.get('tags')
)) ))
elif status == TorrentStatus.TRANSFER: elif status == TorrentStatus.TRANSFER:

View File

@ -185,6 +185,7 @@ class TransmissionModule(_ModuleBase):
title=torrent.name, title=torrent.name,
path=Path(torrent.download_dir) / torrent.name, path=Path(torrent.download_dir) / torrent.name,
hash=torrent.hashString, hash=torrent.hashString,
size=torrent.total_size,
tags=",".join(torrent.labels or []) tags=",".join(torrent.labels or [])
)) ))
elif status == TorrentStatus.TRANSFER: elif status == TorrentStatus.TRANSFER:

View File

@ -12,6 +12,7 @@ class TransferTorrent(BaseModel):
path: Optional[Path] = None path: Optional[Path] = None
hash: Optional[str] = None hash: Optional[str] = None
tags: Optional[str] = None tags: Optional[str] = None
size: Optional[int] = 0
userid: Optional[str] = None userid: Optional[str] = None

View File

@ -32,6 +32,8 @@ class EventType(Enum):
HistoryDeleted = "history.deleted" HistoryDeleted = "history.deleted"
# 删除下载源文件 # 删除下载源文件
DownloadFileDeleted = "downloadfile.deleted" DownloadFileDeleted = "downloadfile.deleted"
# 删除下载任务
DownloadDeleted = "download.deleted"
# 收到用户外来消息 # 收到用户外来消息
UserMessage = "user.message" UserMessage = "user.message"
# 收到Webhook消息 # 收到Webhook消息