mirror of
https://github.com/d0zingcat/MoviePilot-Plugins.git
synced 2026-05-13 23:16:47 +00:00
Merge pull request #644 from InfinityPacer/main
This commit is contained in:
@@ -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 站点自动跳过下载提示页",
|
||||
|
||||
@@ -251,7 +251,7 @@ class BrushFlow(_PluginBase):
|
||||
# 插件图标
|
||||
plugin_icon = "brush.jpg"
|
||||
# 插件版本
|
||||
plugin_version = "4.2"
|
||||
plugin_version = "4.3"
|
||||
# 插件作者
|
||||
plugin_author = "jxxghp,InfinityPacer"
|
||||
# 作者主页
|
||||
@@ -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:
|
||||
"""
|
||||
获取下载器实时信息(所有下载器)
|
||||
|
||||
Reference in New Issue
Block a user