add downloader info
This commit is contained in:
@ -31,16 +31,32 @@ def storage(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
查询存储空间信息
|
||||
"""
|
||||
total_storage, used_storage = SystemUtils.space_usage(Path(settings.LIBRARY_PATH))
|
||||
total_storage, free_storage = SystemUtils.space_usage(Path(settings.LIBRARY_PATH))
|
||||
return schemas.Storage(
|
||||
total_storage=total_storage,
|
||||
used_storage=used_storage
|
||||
used_storage=total_storage - free_storage
|
||||
)
|
||||
|
||||
|
||||
@router.get("/processes", summary="进程信息", response_model=List[schemas.ProcessInfo])
|
||||
def processes(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
进程信息
|
||||
查询进程信息
|
||||
"""
|
||||
return SystemUtils.processes()
|
||||
|
||||
|
||||
@router.get("/downloader", summary="下载器信息", response_model=schemas.DownloaderInfo)
|
||||
def downloader(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
查询下载器信息
|
||||
"""
|
||||
transfer_info = DashboardChain().downloader_info()
|
||||
free_space = SystemUtils.free_space(Path(settings.DOWNLOAD_PATH))
|
||||
return schemas.DownloaderInfo(
|
||||
download_speed=transfer_info.download_speed,
|
||||
upload_speed=transfer_info.upload_speed,
|
||||
download_size=transfer_info.download_size,
|
||||
upload_size=transfer_info.upload_size,
|
||||
free_space=free_space
|
||||
)
|
||||
|
@ -11,3 +11,9 @@ class DashboardChain(ChainBase):
|
||||
媒体数量统计
|
||||
"""
|
||||
return self.run_module("media_statistic")
|
||||
|
||||
def downloader_info(self) -> schemas.DownloaderInfo:
|
||||
"""
|
||||
下载器信息
|
||||
"""
|
||||
return self.run_module("downloader_info")
|
||||
|
@ -1,14 +1,15 @@
|
||||
from pathlib import Path
|
||||
from typing import Set, Tuple, Optional, Union, List
|
||||
|
||||
from app import schemas
|
||||
from app.core.config import settings
|
||||
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 import TransferInfo, TransferTorrent, DownloadingTorrent
|
||||
from app.utils.string import StringUtils
|
||||
from app.schemas.types import TorrentStatus
|
||||
from app.utils.string import StringUtils
|
||||
|
||||
|
||||
class QbittorrentModule(_ModuleBase):
|
||||
@ -184,3 +185,16 @@ class QbittorrentModule(_ModuleBase):
|
||||
:return: bool
|
||||
"""
|
||||
return self.qbittorrent.start_torrents(ids=hashs)
|
||||
|
||||
def downloader_info(self) -> schemas.DownloaderInfo:
|
||||
"""
|
||||
下载器信息
|
||||
"""
|
||||
# 调用Qbittorrent API查询实时信息
|
||||
info = self.qbittorrent.transfer_info()
|
||||
return schemas.DownloaderInfo(
|
||||
download_speed=info.get("dl_info_speed"),
|
||||
upload_speed=info.get("up_info_speed"),
|
||||
download_size=info.get("dl_info_data"),
|
||||
upload_size=info.get("up_info_data")
|
||||
)
|
||||
|
@ -4,6 +4,7 @@ from typing import Optional, Union, Tuple, List
|
||||
import qbittorrentapi
|
||||
from qbittorrentapi import TorrentFilesList, TorrentDictionary
|
||||
from qbittorrentapi.client import Client
|
||||
from qbittorrentapi.transfer import TransferInfoDictionary
|
||||
|
||||
from app.core.config import settings
|
||||
from app.log import logger
|
||||
@ -285,3 +286,13 @@ class Qbittorrent(metaclass=Singleton):
|
||||
except Exception as err:
|
||||
logger.error(f"设置种子文件状态出错:{err}")
|
||||
return False
|
||||
|
||||
def transfer_info(self) -> Optional[TransferInfoDictionary]:
|
||||
"""
|
||||
获取传输信息
|
||||
"""
|
||||
try:
|
||||
return self.qbc.transfer_info()
|
||||
except Exception as err:
|
||||
logger.error(f"获取传输信息出错:{err}")
|
||||
return None
|
||||
|
@ -1,6 +1,7 @@
|
||||
from pathlib import Path
|
||||
from typing import Set, Tuple, Optional, Union, List
|
||||
|
||||
from app import schemas
|
||||
from app.core.config import settings
|
||||
from app.core.metainfo import MetaInfo
|
||||
from app.log import logger
|
||||
@ -168,3 +169,15 @@ class TransmissionModule(_ModuleBase):
|
||||
:return: bool
|
||||
"""
|
||||
return self.transmission.start_torrents(ids=hashs)
|
||||
|
||||
def downloader_info(self) -> schemas.DownloaderInfo:
|
||||
"""
|
||||
下载器信息
|
||||
"""
|
||||
info = self.transmission.transfer_info()
|
||||
return schemas.DownloaderInfo(
|
||||
download_speed=info.download_speed,
|
||||
upload_speed=info.upload_speed,
|
||||
download_size=info.current_stats.downloaded_bytes,
|
||||
upload_size=info.current_stats.uploaded_bytes
|
||||
)
|
||||
|
@ -2,6 +2,7 @@ from typing import Optional, Union, Tuple, List
|
||||
|
||||
import transmission_rpc
|
||||
from transmission_rpc import Client, Torrent, File
|
||||
from transmission_rpc.session import SessionStats
|
||||
|
||||
from app.core.config import settings
|
||||
from app.log import logger
|
||||
@ -214,3 +215,13 @@ class Transmission(metaclass=Singleton):
|
||||
except Exception as err:
|
||||
logger.error(f"设置下载文件状态出错:{err}")
|
||||
return False
|
||||
|
||||
def transfer_info(self) -> Optional[SessionStats]:
|
||||
"""
|
||||
获取传输信息
|
||||
"""
|
||||
try:
|
||||
return self.trc.session_stats()
|
||||
except Exception as err:
|
||||
logger.error(f"获取传输信息出错:{err}")
|
||||
return None
|
||||
|
@ -36,3 +36,16 @@ class ProcessInfo(BaseModel):
|
||||
create_time: Optional[float] = 0.0
|
||||
# 进程运行时间 秒
|
||||
run_time: Optional[float] = 0.0
|
||||
|
||||
|
||||
class DownloaderInfo(BaseModel):
|
||||
# 下载速度
|
||||
download_speed: Optional[float] = 0.0
|
||||
# 上传速度
|
||||
upload_speed: Optional[float] = 0.0
|
||||
# 下载量
|
||||
download_size: Optional[float] = 0.0
|
||||
# 上传量
|
||||
upload_size: Optional[float] = 0.0
|
||||
# 剩余空间
|
||||
free_space: Optional[float] = 0.0
|
||||
|
Reference in New Issue
Block a user