add 正在下载查询

This commit is contained in:
jxxghp
2023-06-15 18:10:04 +08:00
parent 237fe69d82
commit 84e4a4a527
9 changed files with 70 additions and 10 deletions

View File

@ -10,7 +10,7 @@ from app.core.module import ModuleManager
from app.core.context import MediaInfo, TorrentInfo
from app.core.meta import MetaBase
from app.log import logger
from app.schemas.context import TransferInfo, TransferTorrent, ExistMediaInfo
from app.schemas.context import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent
from app.utils.singleton import AbstractSingleton, Singleton
from app.utils.types import TorrentStatus, MediaType
@ -111,7 +111,7 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
return self.run_module("download_added", context=context, torrent_path=torrent_path)
def list_torrents(self, status: TorrentStatus = None,
hashs: Union[list, str] = None) -> Optional[List[TransferTorrent]]:
hashs: Union[list, str] = None) -> Optional[List[Union[TransferTorrent, DownloadingTorrent]]]:
return self.run_module("list_torrents", status=status, hashs=hashs)
def transfer(self, path: Path, mediainfo: MediaInfo) -> Optional[TransferInfo]:

View File

@ -9,7 +9,7 @@ from app.helper.torrent import TorrentHelper
from app.log import logger
from app.schemas.context import ExistMediaInfo, NotExistMediaInfo
from app.utils.string import StringUtils
from app.utils.types import MediaType
from app.utils.types import MediaType, TorrentStatus
class DownloadChain(ChainBase):
@ -473,3 +473,20 @@ class DownloadChain(ChainBase):
return False, no_exists
# 全部存在
return True, no_exists
def get_downloading(self):
"""
查询正在下载的任务,并发送消息
"""
torrents = self.list_torrents(status=TorrentStatus.DOWNLOADING)
if not torrents:
self.post_message(title="没有正在下载的任务!")
return
# 发送消息
title = f"{len(torrents)} 个任务正在下载:"
messages = []
for torrent in torrents:
messages.append(f"{torrent.title} "
f"{StringUtils.str_filesize(torrent.size)} "
f"{round(torrent.progress) * 100}%")
self.post_message(title=title, text="\n".join(messages))