diff --git a/app/modules/qbittorrent/qbittorrent.py b/app/modules/qbittorrent/qbittorrent.py index 8ed72504..ba385d0c 100644 --- a/app/modules/qbittorrent/qbittorrent.py +++ b/app/modules/qbittorrent/qbittorrent.py @@ -339,6 +339,7 @@ class Qbittorrent(metaclass=Singleton): try: self.qbc.transfer.upload_limit = int(upload_limit) self.qbc.transfer.download_limit = int(download_limit) + return True except Exception as err: logger.error(f"设置速度限制出错:{err}") return False diff --git a/app/modules/transmission/transmission.py b/app/modules/transmission/transmission.py index e9013b4e..38deeafe 100644 --- a/app/modules/transmission/transmission.py +++ b/app/modules/transmission/transmission.py @@ -243,14 +243,14 @@ class Transmission(metaclass=Singleton): logger.error(f"获取传输信息出错:{err}") return None - def set_speed_limit(self, download_limit: float = None, upload_limit: float = None): + def set_speed_limit(self, download_limit: float = None, upload_limit: float = None) -> bool: """ 设置速度限制 :param download_limit: 下载速度限制,单位KB/s :param upload_limit: 上传速度限制,单位kB/s """ if not self.trc: - return + return False try: download_limit_enabled = True if download_limit else False upload_limit_enabled = True if upload_limit else False @@ -260,6 +260,7 @@ class Transmission(metaclass=Singleton): speed_limit_down_enabled=download_limit_enabled, speed_limit_up_enabled=upload_limit_enabled ) + return True except Exception as err: logger.error(f"设置速度限制出错:{err}") return False diff --git a/app/plugins/speedlimiter/__init__.py b/app/plugins/speedlimiter/__init__.py index 1ee65415..fafce52e 100644 --- a/app/plugins/speedlimiter/__init__.py +++ b/app/plugins/speedlimiter/__init__.py @@ -539,25 +539,25 @@ class SpeedLimiter(_PluginBase): title=title, text=f"Qbittorrent 已取消限速" ) - else: - if self._tr: - self._tr.set_speed_limit(download_limit=download_limit, upload_limit=upload_limit) - # 发送通知 - if self._notify: - title = "【播放限速】" - if upload_limit or download_limit: - subtitle = f"Transmission 开始{limit_type}限速" - self.post_message( - mtype=NotificationType.MediaServer, - title=title, - text=f"{subtitle}\n{text}" - ) - else: - self.post_message( - mtype=NotificationType.MediaServer, - title=title, - text=f"Transmission 已取消限速" - ) + else: + if self._tr: + self._tr.set_speed_limit(download_limit=download_limit, upload_limit=upload_limit) + # 发送通知 + if self._notify: + title = "【播放限速】" + if upload_limit or download_limit: + subtitle = f"Transmission 开始{limit_type}限速" + self.post_message( + mtype=NotificationType.MediaServer, + title=title, + text=f"{subtitle}\n{text}" + ) + else: + self.post_message( + mtype=NotificationType.MediaServer, + title=title, + text=f"Transmission 已取消限速" + ) except Exception as e: logger.error(f"设置限速失败:{str(e)}")