fix SpeedLimiter 通知
This commit is contained in:
parent
0a8b667819
commit
7b07776ef2
@ -50,6 +50,8 @@ class SpeedLimiter(_PluginBase):
|
|||||||
_play_down_speed: float = 0
|
_play_down_speed: float = 0
|
||||||
_noplay_up_speed: float = 0
|
_noplay_up_speed: float = 0
|
||||||
_noplay_down_speed: float = 0
|
_noplay_down_speed: float = 0
|
||||||
|
# 当前限速状态
|
||||||
|
_current_state = ""
|
||||||
|
|
||||||
def init_plugin(self, config: dict = None):
|
def init_plugin(self, config: dict = None):
|
||||||
# 读取配置
|
# 读取配置
|
||||||
@ -330,6 +332,13 @@ class SpeedLimiter(_PluginBase):
|
|||||||
"""
|
"""
|
||||||
if not self._qb and not self._tr:
|
if not self._qb and not self._tr:
|
||||||
return
|
return
|
||||||
|
state = f"U:{upload_limit},D:{download_limit}"
|
||||||
|
if self._current_state == state:
|
||||||
|
# 限速状态没有改变
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self._current_state = state
|
||||||
|
|
||||||
if upload_limit:
|
if upload_limit:
|
||||||
text = f"上传:{upload_limit} KB/s"
|
text = f"上传:{upload_limit} KB/s"
|
||||||
else:
|
else:
|
||||||
@ -342,22 +351,38 @@ class SpeedLimiter(_PluginBase):
|
|||||||
if self._qb:
|
if self._qb:
|
||||||
self._qb.set_speed_limit(download_limit=download_limit, upload_limit=upload_limit)
|
self._qb.set_speed_limit(download_limit=download_limit, upload_limit=upload_limit)
|
||||||
# 发送通知
|
# 发送通知
|
||||||
if self._notify and (upload_limit or download_limit):
|
if self._notify:
|
||||||
title = f"Qbittorrent 开始{limit_type}限速"
|
title = "【播放限速】"
|
||||||
|
if upload_limit or download_limit:
|
||||||
|
subtitle = f"Qbittorrent 开始{limit_type}限速"
|
||||||
self.post_message(
|
self.post_message(
|
||||||
mtype=NotificationType.MediaServer,
|
mtype=NotificationType.MediaServer,
|
||||||
title=title,
|
title=title,
|
||||||
text=text
|
text=f"{subtitle}\n{text}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.post_message(
|
||||||
|
mtype=NotificationType.MediaServer,
|
||||||
|
title=title,
|
||||||
|
text=f"Qbittorrent 已取消限速"
|
||||||
)
|
)
|
||||||
if self._tr:
|
if self._tr:
|
||||||
self._tr.set_speed_limit(download_limit=download_limit, upload_limit=upload_limit)
|
self._tr.set_speed_limit(download_limit=download_limit, upload_limit=upload_limit)
|
||||||
# 发送通知
|
# 发送通知
|
||||||
if self._notify and (upload_limit or download_limit):
|
if self._notify:
|
||||||
title = f"Transmission 开始{limit_type}限速"
|
title = "【播放限速】"
|
||||||
|
if upload_limit or download_limit:
|
||||||
|
subtitle = f"Transmission 开始{limit_type}限速"
|
||||||
self.post_message(
|
self.post_message(
|
||||||
mtype=NotificationType.MediaServer,
|
mtype=NotificationType.MediaServer,
|
||||||
title=title,
|
title=title,
|
||||||
text=text
|
text=f"{subtitle}\n{text}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.post_message(
|
||||||
|
mtype=NotificationType.MediaServer,
|
||||||
|
title=title,
|
||||||
|
text=f"Transmission 已取消限速"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"设置限速失败:{str(e)}")
|
logger.error(f"设置限速失败:{str(e)}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user