From bb8e12f8c4c4c2c32f2a5410cd3da06a3c1091e6 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Mon, 13 Jan 2025 00:50:42 +0800 Subject: [PATCH 1/3] feat(BrushFlow): add support for bandwidth sampling --- plugins.v2/brushflow/__init__.py | 41 +++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/plugins.v2/brushflow/__init__.py b/plugins.v2/brushflow/__init__.py index b22c76c..ae93aa3 100644 --- a/plugins.v2/brushflow/__init__.py +++ b/plugins.v2/brushflow/__init__.py @@ -2142,16 +2142,15 @@ class BrushFlow(_PluginBase): ] if include_network_conditions: - downloader_info = self.__get_downloader_info() - if downloader_info: - current_upload_speed = downloader_info.upload_speed or 0 - current_download_speed = downloader_info.download_speed or 0 + # 获取平均带宽 + avg_upload_speed, avg_download_speed = self.__get_average_bandwidth() + if avg_upload_speed is not None and avg_download_speed is not None: reasons.extend([ - ("maxupspeed", lambda config: current_upload_speed >= float(config) * 1024, - lambda config: f"当前总上传带宽 {StringUtils.str_filesize(current_upload_speed)}," + ("maxupspeed", lambda config: avg_upload_speed >= float(config) * 1024, + lambda config: f"当前总上传带宽 {StringUtils.str_filesize(avg_upload_speed)}," f"已达到最大值 {config} KB/s,暂时停止新增任务"), - ("maxdlspeed", lambda config: current_download_speed >= float(config) * 1024, - lambda config: f"当前总下载带宽 {StringUtils.str_filesize(current_download_speed)}," + ("maxdlspeed", lambda config: avg_download_speed >= float(config) * 1024, + lambda config: f"当前总下载带宽 {StringUtils.str_filesize(avg_download_speed)}," f"已达到最大值 {config} KB/s,暂时停止新增任务"), ]) @@ -3508,6 +3507,32 @@ class BrushFlow(_PluginBase): total_size = sum([task.get("size") or 0 for task in task_info.values()]) return total_size + def __get_average_bandwidth(self, sample_count: int = 5, interval: float = 3.0) \ + -> Tuple[Optional[float], Optional[float]]: + """ + 多次采样上传和下载带宽,取平均值 + """ + upload_speeds = [] + download_speeds = [] + start_time = time.time() + for _ in range(sample_count): + downloader_info = self.__get_downloader_info() + if downloader_info: + upload_speeds.append(downloader_info.upload_speed or 0) + download_speeds.append(downloader_info.download_speed or 0) + # 采样间隔 + time.sleep(interval) + end_time = time.time() + total_duration = end_time - start_time + if not upload_speeds or not download_speeds: + return None, None + avg_upload_speed = sum(upload_speeds) / len(upload_speeds) if upload_speeds else 0 + avg_download_speed = sum(download_speeds) / len(download_speeds) if download_speeds else 0 + logger.debug(f"平均上传带宽 {StringUtils.str_filesize(avg_upload_speed)}, " + f"平均下载带宽 {StringUtils.str_filesize(avg_download_speed)}, " + f"采样次数={sample_count}, 时长={total_duration:.2f} 秒") + return avg_upload_speed, avg_download_speed + def __get_downloader_info(self) -> schemas.DownloaderInfo: """ 获取下载器实时信息(所有下载器) From 6288b0b9e8e615e67e34a9442947a005aaf1919b Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Mon, 13 Jan 2025 00:51:18 +0800 Subject: [PATCH 2/3] feat(BrushFlowLowFreq): v4.2 --- package.v2.json | 3 ++- plugins.v2/brushflow/__init__.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.v2.json b/package.v2.json index 57b8699..aeceb13 100644 --- a/package.v2.json +++ b/package.v2.json @@ -20,11 +20,12 @@ "name": "站点刷流", "description": "自动托管刷流,将会提高对应站点的访问频率。", "labels": "刷流,仪表板", - "version": "4.1", + "version": "4.2", "icon": "brush.jpg", "author": "jxxghp,InfinityPacer", "level": 2, "history": { + "v4.2": "支持带宽采样并计算平均值,以优化刷流效率", "v4.1": "支持通过CRON表达式配置开启时间,固定10分钟为执行周期", "v4.0": "站点独立配置项支持配置NexusPHP 站点自动跳过下载提示页", "v3.9": "MoviePilot V2 版本站点刷流插件" diff --git a/plugins.v2/brushflow/__init__.py b/plugins.v2/brushflow/__init__.py index ae93aa3..241f98f 100644 --- a/plugins.v2/brushflow/__init__.py +++ b/plugins.v2/brushflow/__init__.py @@ -251,7 +251,7 @@ class BrushFlow(_PluginBase): # 插件图标 plugin_icon = "brush.jpg" # 插件版本 - plugin_version = "4.1" + plugin_version = "4.2" # 插件作者 plugin_author = "jxxghp,InfinityPacer" # 作者主页 From 1d627415129cbc15716b7c62463f15f688edfb74 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Wed, 15 Jan 2025 00:23:07 +0800 Subject: [PATCH 3/3] feat(BrushFlow): v4.3 --- package.v2.json | 3 ++- plugins.v2/brushflow/__init__.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.v2.json b/package.v2.json index cd7f33b..9b3d321 100644 --- a/package.v2.json +++ b/package.v2.json @@ -20,11 +20,12 @@ "name": "站点刷流", "description": "自动托管刷流,将会提高对应站点的访问频率。", "labels": "刷流,仪表板", - "version": "4.2", + "version": "4.3", "icon": "brush.jpg", "author": "jxxghp,InfinityPacer", "level": 2, "history": { + "v4.3": "支持带宽采样并计算平均值,以优化刷流效率", "v4.2": "优化执行周期输入,需要MoviePilot v2.2.1+", "v4.1": "支持通过CRON表达式配置开启时间,固定10分钟为执行周期", "v4.0": "站点独立配置项支持配置NexusPHP 站点自动跳过下载提示页", diff --git a/plugins.v2/brushflow/__init__.py b/plugins.v2/brushflow/__init__.py index 741a773..bf55f3d 100644 --- a/plugins.v2/brushflow/__init__.py +++ b/plugins.v2/brushflow/__init__.py @@ -251,7 +251,7 @@ class BrushFlow(_PluginBase): # 插件图标 plugin_icon = "brush.jpg" # 插件版本 - plugin_version = "4.2" + plugin_version = "4.3" # 插件作者 plugin_author = "jxxghp,InfinityPacer" # 作者主页