From 9484fcd3dee6c4ce4145b123fd3e32bc5a256580 Mon Sep 17 00:00:00 2001 From: thsrite Date: Tue, 9 Jul 2024 12:12:10 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=A2=9E=E5=8A=A0=E4=BA=91=E7=9B=98?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E7=A9=BA=E9=97=B4=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 3 +- plugins/cd2assistant/__init__.py | 147 ++++++++++++++++++++++++++++++- 3 files changed, 148 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 60937c0..13744c4 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - 目录监控(统一入库消息增强版) v1.0 - Sql执行器 v1.2 - 命令执行器 v1.2 -- CloudDrive2助手 v1.3 +- CloudDrive2助手 v1.4 - 软连接重定向 v1.1 - 云盘同步删除 v1.4 - 媒体库重复媒体检测 v1.9 \ No newline at end of file diff --git a/package.json b/package.json index 13e0d75..3588851 100644 --- a/package.json +++ b/package.json @@ -568,11 +568,12 @@ "name": "CloudDrive2助手", "description": "监控上传任务,检测是否有异常,发送通知。", "labels": "云盘", - "version": "1.3", + "version": "1.4", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/clouddrive.png", "author": "thsrite", "level": 2, "history": { + "v1.4": "增加云盘存储空间展示", "v1.3": "增加云盘Cookie失效检测", "v1.2": "实时速率显示", "v1.1": "交互命令重启cd2、获取cd2系统信息,支持仪表盘", diff --git a/plugins/cd2assistant/__init__.py b/plugins/cd2assistant/__init__.py index 19dc7b3..d537994 100644 --- a/plugins/cd2assistant/__init__.py +++ b/plugins/cd2assistant/__init__.py @@ -25,7 +25,7 @@ class Cd2Assistant(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/clouddrive.png" # 插件版本 - plugin_version = "1.3" + plugin_version = "1.4" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -212,6 +212,26 @@ class Cd2Assistant(_PluginBase): self._client.RestartService() + def __get_cloud_space(self): + """ + 获取云盘空间 + """ + fs = self._cd2_client.fs + if not fs: + logger.error("CloudDrive2连接失败,请检查配置") + return + + _space_info = "\n" + for f in fs.listdir(): + space_info = self._cd2_client.GetSpaceInfo(CloudDrive_pb2.FileRequest(path=f)) + space_info = self.__str_to_dict(space_info) + total = self.__convert_bytes(space_info.get("totalSpace")) + used = self.__convert_bytes(space_info.get("usedSpace")) + free = self.__convert_bytes(space_info.get("freeSpace")) + _space_info += f"{f}:{used}/{total}\n" + + return _space_info + @eventmanager.register(EventType.PluginAction) def cd2_info(self, event: Event = None): """ @@ -236,6 +256,9 @@ class Cd2Assistant(_PluginBase): uploadFileList = self._client.GetUploadFileList(CloudDrive_pb2.GetUploadFileListRequest(getAll=True)) uploadFileList = self.__str_to_dict(uploadFileList) if uploadFileList else {} + # 云盘空间 + cloud_space = self.__get_cloud_space() + system_info_dict = { "cpuUsage": f"{system_info.get('cpuUsage'):.2f}%" if system_info.get( "cpuUsage") else "0.00%" if system_info else None, @@ -255,6 +278,7 @@ class Cd2Assistant(_PluginBase): "globalBytesPerSecond") else "0KB/s" if downloadFileList else "0KB/s", "upload_speed": f"{uploadFileList.get('globalBytesPerSecond') / 1024 / 1024:.2f}MB/s" if uploadFileList.get( "globalBytesPerSecond") else "0KB/s" if uploadFileList else "0KB/s", + "cloud_space": cloud_space } logger.info(f"获取CloudDrive2系统信息:\n{system_info_dict}") @@ -272,10 +296,23 @@ class Cd2Assistant(_PluginBase): f"上传任务数量:{system_info_dict.get('upload_count')}\n" f"下载任务数量:{system_info_dict.get('download_count')}\n" f"下载速度:{system_info_dict.get('download_speed')}\n" - f"上传速度:{system_info_dict.get('upload_speed')}\n") + f"上传速度:{system_info_dict.get('upload_speed')}\n" + f"存储空间:{system_info_dict.get('cloud_space')}\n") return system_info_dict + @staticmethod + def __convert_bytes(size_in_bytes): + """ Convert bytes to the most appropriate unit (PB, TB, GB, etc.) """ + units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] + unit_index = 0 + + while size_in_bytes >= 1024 and unit_index < len(units) - 1: + size_in_bytes /= 1024 + unit_index += 1 + + return f"{size_in_bytes:.2f} {units[unit_index]}" + @staticmethod def __str_to_dict(str_data): """ @@ -576,6 +613,7 @@ class Cd2Assistant(_PluginBase): def get_page(self) -> List[dict]: cd2_info = self.cd2_info() + # 拼装页面 return [ { @@ -1057,6 +1095,59 @@ class Cd2Assistant(_PluginBase): ] } ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4, + 'sm': 6 + }, + 'content': [ + { + 'component': 'VCard', + 'props': { + 'variant': 'tonal', + }, + 'content': [ + { + 'component': 'VCardText', + 'props': { + 'class': 'd-flex align-center', + }, + 'content': [ + { + 'component': 'div', + 'content': [ + { + 'component': 'span', + 'props': { + 'class': 'text-caption' + }, + 'text': '存储空间' + }, + { + 'component': 'div', + 'props': { + 'class': 'd-flex align-center flex-wrap' + }, + 'content': [ + { + 'component': 'span', + 'props': { + 'class': 'text-h6' + }, + 'text': cd2_info.get('cloud_space') + } + ] + } + ] + } + ] + } + ] + } + ] } ] }] @@ -1619,6 +1710,58 @@ class Cd2Assistant(_PluginBase): ] }, ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 6, + 'md': 3 + }, + 'content': [ + { + 'component': 'VCard', + 'props': { + 'variant': 'tonal', + }, + 'content': [ + { + 'component': 'VCardText', + 'props': { + 'class': 'd-flex align-center', + }, + 'content': [ + { + 'component': 'div', + 'content': [ + { + 'component': 'span', + 'props': { + 'class': 'text-caption' + }, + 'text': '存储空间' + }, + { + 'component': 'div', + 'props': { + 'class': 'd-flex align-center flex-wrap' + }, + 'content': [ + { + 'component': 'span', + 'props': { + 'class': 'text-h6' + }, + 'text': cd2_info.get('cloud_space') + } + ] + } + ] + } + ] + } + ] + }, + ] } ] }]