fix 删除不限速地址配置
This commit is contained in:
parent
0cf11db76a
commit
f65da9b202
@ -55,8 +55,6 @@ class SpeedLimiter(_PluginBase):
|
|||||||
_allocation_ratio: str = ""
|
_allocation_ratio: str = ""
|
||||||
_auto_limit: bool = False
|
_auto_limit: bool = False
|
||||||
_limit_enabled: bool = False
|
_limit_enabled: bool = False
|
||||||
# 不限速地址
|
|
||||||
_unlimited_ips = {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
|
|
||||||
# 当前限速状态
|
# 当前限速状态
|
||||||
_current_state = ""
|
_current_state = ""
|
||||||
|
|
||||||
@ -81,11 +79,6 @@ class SpeedLimiter(_PluginBase):
|
|||||||
# 限速服务开关
|
# 限速服务开关
|
||||||
self._limit_enabled = True if self._play_up_speed or self._play_down_speed or self._auto_limit else False
|
self._limit_enabled = True if self._play_up_speed or self._play_down_speed or self._auto_limit 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["ipv6"] = config.get("ipv6") or "::/0"
|
|
||||||
if "0.0.0.0/0" in self._unlimited_ips["ipv4"] and "::/0" in self._unlimited_ips["ipv6"]:
|
|
||||||
self._limit_enabled = False
|
|
||||||
self._downloader = config.get("downloader") or []
|
self._downloader = config.get("downloader") or []
|
||||||
if self._downloader:
|
if self._downloader:
|
||||||
if 'qbittorrent' in self._downloader:
|
if 'qbittorrent' in self._downloader:
|
||||||
@ -299,45 +292,6 @@ class SpeedLimiter(_PluginBase):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
'component': 'VRow',
|
|
||||||
'content': [
|
|
||||||
{
|
|
||||||
'component': 'VCol',
|
|
||||||
'props': {
|
|
||||||
'cols': 12,
|
|
||||||
'md': 6
|
|
||||||
},
|
|
||||||
'content': [
|
|
||||||
{
|
|
||||||
'component': 'VTextField',
|
|
||||||
'props': {
|
|
||||||
'model': 'ipv4',
|
|
||||||
'label': '不限速地址范围(ipv4)',
|
|
||||||
'placeholder': '192.168.1.0/24'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'component': 'VCol',
|
|
||||||
'props': {
|
|
||||||
'cols': 12,
|
|
||||||
'md': 6
|
|
||||||
},
|
|
||||||
'content': [
|
|
||||||
{
|
|
||||||
'component': 'VTextField',
|
|
||||||
'props': {
|
|
||||||
'model': 'ipv6',
|
|
||||||
'label': '不限速地址范围(ipv6)',
|
|
||||||
'placeholder': 'FE80::/10'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
], {
|
], {
|
||||||
@ -350,8 +304,6 @@ class SpeedLimiter(_PluginBase):
|
|||||||
"noplay_down_speed": 0,
|
"noplay_down_speed": 0,
|
||||||
"bandwidth": 0,
|
"bandwidth": 0,
|
||||||
"allocation_ratio": "",
|
"allocation_ratio": "",
|
||||||
"ipv4": "",
|
|
||||||
"ipv6": "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_page(self) -> List[dict]:
|
def get_page(self) -> List[dict]:
|
||||||
@ -379,8 +331,7 @@ class SpeedLimiter(_PluginBase):
|
|||||||
if res and res.status_code == 200:
|
if res and res.status_code == 200:
|
||||||
sessions = res.json()
|
sessions = res.json()
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
if not self.__allow_access(self._unlimited_ips, session.get("RemoteEndPoint")) and \
|
if session.get("NowPlayingItem") and not session.get("PlayState", {}).get("IsPaused"):
|
||||||
session.get("NowPlayingItem") and not session.get("PlayState", {}).get("IsPaused"):
|
|
||||||
playing_sessions.append(session)
|
playing_sessions.append(session)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"获取Emby播放会话失败:{str(e)}")
|
logger.error(f"获取Emby播放会话失败:{str(e)}")
|
||||||
@ -396,8 +347,7 @@ class SpeedLimiter(_PluginBase):
|
|||||||
if res and res.status_code == 200:
|
if res and res.status_code == 200:
|
||||||
sessions = res.json()
|
sessions = res.json()
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
if not self.__allow_access(self._unlimited_ips, session.get("RemoteEndPoint")) and \
|
if session.get("NowPlayingItem") and not session.get("PlayState", {}).get("IsPaused"):
|
||||||
session.get("NowPlayingItem") and not session.get("PlayState", {}).get("IsPaused"):
|
|
||||||
playing_sessions.append(session)
|
playing_sessions.append(session)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"获取Jellyfin播放会话失败:{str(e)}")
|
logger.error(f"获取Jellyfin播放会话失败:{str(e)}")
|
||||||
@ -421,8 +371,7 @@ class SpeedLimiter(_PluginBase):
|
|||||||
})
|
})
|
||||||
# 计算有效比特率
|
# 计算有效比特率
|
||||||
for session in playing_sessions:
|
for session in playing_sessions:
|
||||||
if not self.__allow_access(self._unlimited_ips, session.get("address")) and \
|
if IpUtils.is_private_ip(session.get("address")) \
|
||||||
IpUtils.is_private_ip(session.get("address")) \
|
|
||||||
and session.get("type") == "Video":
|
and session.get("type") == "Video":
|
||||||
total_bit_rate += int(session.get("bitrate") or 0)
|
total_bit_rate += int(session.get("bitrate") or 0)
|
||||||
|
|
||||||
@ -527,42 +476,6 @@ class SpeedLimiter(_PluginBase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"设置限速失败:{str(e)}")
|
logger.error(f"设置限速失败:{str(e)}")
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def __allow_access(allow_ips, ip):
|
|
||||||
"""
|
|
||||||
判断IP是否合法
|
|
||||||
:param allow_ips: 充许的IP范围 {"ipv4":, "ipv6":}
|
|
||||||
:param ip: 需要检查的ip
|
|
||||||
"""
|
|
||||||
if not allow_ips:
|
|
||||||
return True
|
|
||||||
try:
|
|
||||||
ipaddr = ipaddress.ip_address(ip)
|
|
||||||
if ipaddr.version == 4:
|
|
||||||
if not allow_ips.get('ipv4'):
|
|
||||||
return True
|
|
||||||
allow_ipv4s = allow_ips.get('ipv4').split(",")
|
|
||||||
for allow_ipv4 in allow_ipv4s:
|
|
||||||
if ipaddr in ipaddress.ip_network(allow_ipv4):
|
|
||||||
return True
|
|
||||||
elif ipaddr.ipv4_mapped:
|
|
||||||
if not allow_ips.get('ipv4'):
|
|
||||||
return True
|
|
||||||
allow_ipv4s = allow_ips.get('ipv4').split(",")
|
|
||||||
for allow_ipv4 in allow_ipv4s:
|
|
||||||
if ipaddr.ipv4_mapped in ipaddress.ip_network(allow_ipv4):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
if not allow_ips.get('ipv6'):
|
|
||||||
return True
|
|
||||||
allow_ipv6s = allow_ips.get('ipv6').split(",")
|
|
||||||
for allow_ipv6 in allow_ipv6s:
|
|
||||||
if ipaddr in ipaddress.ip_network(allow_ipv6):
|
|
||||||
return True
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
return False
|
|
||||||
|
|
||||||
def stop_service(self):
|
def stop_service(self):
|
||||||
"""
|
"""
|
||||||
退出插件
|
退出插件
|
||||||
|
Loading…
x
Reference in New Issue
Block a user