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

@ -6,7 +6,7 @@ from ruamel.yaml import CommentedMap
from app.core.context import MediaInfo, TorrentInfo, Context
from app.core.meta import MetaBase
from app.schemas.context import TransferInfo, TransferTorrent, ExistMediaInfo
from app.schemas.context import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent
from app.utils.types import TorrentStatus, MediaType
@ -165,7 +165,7 @@ class _ModuleBase(metaclass=ABCMeta):
pass
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]]]:
"""
获取下载器种子列表
:param status: 种子状态

View File

@ -6,7 +6,7 @@ from app.core.metainfo import MetaInfo
from app.log import logger
from app.modules import _ModuleBase
from app.modules.qbittorrent.qbittorrent import Qbittorrent
from app.schemas.context import TransferInfo, TransferTorrent
from app.schemas.context import TransferInfo, TransferTorrent, DownloadingTorrent
from app.utils.string import StringUtils
from app.utils.types import TorrentStatus
@ -86,7 +86,7 @@ class QbittorrentModule(_ModuleBase):
return torrent_hash, "添加下载成功"
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]]]:
"""
获取下载器种子列表
:param status: 种子状态
@ -128,6 +128,19 @@ class QbittorrentModule(_ModuleBase):
hash=torrent.get('hash'),
tags=torrent.get('tags')
))
elif status == TorrentStatus.DOWNLOADING:
# 获取正在下载的任务
torrents = self.qbittorrent.get_downloading_torrents(tags=settings.TORRENT_TAG)
for torrent in torrents:
meta = MetaInfo(torrent.get('name'))
ret_torrents.append(DownloadingTorrent(
title=torrent.get('name'),
name=meta.name,
year=meta.year,
season_episode=meta.season_episode,
progress=torrent.get('progress'),
size=torrent.get('total_size')
))
else:
return None
return ret_torrents

View File

@ -147,7 +147,8 @@ class Slack:
result = self._client.chat_postMessage(
channel=channel,
text=message_text,
blocks=blocks
blocks=blocks,
mrkdwn=True
)
return True, result
except Exception as msg_e:

View File

@ -6,7 +6,7 @@ from app.core.metainfo import MetaInfo
from app.log import logger
from app.modules import _ModuleBase
from app.modules.transmission.transmission import Transmission
from app.schemas.context import TransferInfo, TransferTorrent
from app.schemas.context import TransferInfo, TransferTorrent, DownloadingTorrent
from app.utils.types import TorrentStatus
@ -73,7 +73,7 @@ class TransmissionModule(_ModuleBase):
return torrent_hash, "添加下载任务成功"
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]]]:
"""
获取下载器种子列表
:param status: 种子状态
@ -110,6 +110,19 @@ class TransmissionModule(_ModuleBase):
hash=torrent.hashString,
tags=torrent.labels
))
elif status == TorrentStatus.DOWNLOADING:
# 获取正在下载的任务
torrents = self.transmission.get_downloading_torrents(tags=settings.TORRENT_TAG)
for torrent in torrents:
meta = MetaInfo(torrent.name)
ret_torrents.append(DownloadingTorrent(
title=torrent.name,
name=meta.name,
year=meta.year,
season_episode=meta.season_episode,
progress=torrent.progress,
size=torrent.total_size
))
else:
return None
return ret_torrents