Update __init__.py

This commit is contained in:
thsrite 2023-08-31 19:01:14 +08:00 committed by GitHub
parent 93ec8df713
commit 7baa07474c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,7 +54,7 @@ class SpeedLimiter(_PluginBase):
_bandwidth: float = 0 _bandwidth: float = 0
_allocation_ratio: str = "" _allocation_ratio: str = ""
_auto_limit: bool = False _auto_limit: bool = False
_limit_enabled: bool = False _limit_enabled: bool = True
# 不限速地址 # 不限速地址
_unlimited_ips = {"ipv4": "0.0.0.0/0", "ipv6": "::/0"} _unlimited_ips = {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
# 当前限速状态 # 当前限速状态
@ -72,10 +72,10 @@ class SpeedLimiter(_PluginBase):
try: try:
# 总带宽 # 总带宽
self._bandwidth = int(float(config.get("bandwidth") or 0)) * 1000000 self._bandwidth = int(float(config.get("bandwidth") or 0)) * 1000000
# 自动限速开关
self._auto_limit = True
except Exception: except Exception:
self._bandwidth = 0 self._bandwidth = 0
# 自动限速开关
self._auto_limit = True if self._bandwidth else False
self._allocation_ratio = config.get("allocation_ratio") or "" self._allocation_ratio = config.get("allocation_ratio") or ""
# 不限速地址 # 不限速地址
self._unlimited_ips["ipv4"] = config.get("ipv4") or "0.0.0.0/0" self._unlimited_ips["ipv4"] = config.get("ipv4") or "0.0.0.0/0"
@ -425,13 +425,15 @@ class SpeedLimiter(_PluginBase):
if total_bit_rate: if total_bit_rate:
# 开启智能限速计算上传限速 # 开启智能限速计算上传限速
if self._auto_limit: if self._auto_limit:
self.__calc_limit(total_bit_rate) play_up_speed = self.__calc_limit(total_bit_rate)
else:
play_up_speed = self._play_up_speed
# 当前正在播放,开始限速 # 当前正在播放,开始限速
self.__set_limiter(limit_type="播放", upload_limit=self._play_up_speed, self.__set_limiter(limit_type="播放", upload_limit=play_up_speed,
download_limit=self._play_down_speed) download_limit=self._play_down_speed)
else: else:
# 当前没有播放,开始限速 # 当前没有播放,取消限速
self.__set_limiter(limit_type="未播放", upload_limit=self._noplay_up_speed, self.__set_limiter(limit_type="未播放", upload_limit=self._noplay_up_speed,
download_limit=self._noplay_down_speed) download_limit=self._noplay_down_speed)
@ -441,9 +443,11 @@ class SpeedLimiter(_PluginBase):
""" """
residual_bandwidth = (self._bandwidth - total_bit_rate) residual_bandwidth = (self._bandwidth - total_bit_rate)
if residual_bandwidth < 0: if residual_bandwidth < 0:
self._play_up_speed = 10 play_up_speed = 10
else: else:
self._play_up_speed = residual_bandwidth / 8 / 1024 play_up_speed = residual_bandwidth / 8 / 1024
return play_up_speed
def __set_limiter(self, limit_type: str, upload_limit: float, download_limit: float): def __set_limiter(self, limit_type: str, upload_limit: float, download_limit: float):
""" """