From 2dfe50a30457ff6352efab417dbbedb1053e5c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20M=C3=BCller?= Date: Mon, 24 Nov 2025 17:12:56 +0100 Subject: [PATCH] Pre check if share limits are reached --- modules/core/share_limits.py | 64 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/modules/core/share_limits.py b/modules/core/share_limits.py index c3b057e..d5e83fb 100644 --- a/modules/core/share_limits.py +++ b/modules/core/share_limits.py @@ -333,22 +333,10 @@ class ShareLimits: logger.print_line(logger.insert_space(f"Tracker: {tracker['url']}", 8), self.config.loglevel) if self.group_tag: logger.print_line(logger.insert_space(f"Added Tag: {self.group_tag}", 8), self.config.loglevel) - self.update_share_limits_for_torrent(torrent, group_config, tor_reached_seed_limit, torrent_upload_limit) + self.process_share_limits_for_torrent(torrent, group_config, tor_reached_seed_limit, torrent_upload_limit) self.stats_tagged += 1 self.torrents_updated.append(t_name) - # Take action when torrent meets share limits - if tor_reached_seed_limit: - if group_config["cleanup"]: - # Queue for cleanup (delete .torrent and possibly contents) - if t_hash not in self.tdel_dict: - self.tdel_dict[t_hash] = {} - self.tdel_dict[t_hash]["torrent"] = torrent - self.tdel_dict[t_hash]["content_path"] = util.path_replace( - torrent["content_path"], self.root_dir, self.remote_dir - ) - self.tdel_dict[t_hash]["body"] = tor_reached_seed_limit - self.torrent_hash_checked.append(t_hash) def update_share_limits_tag_for_torrent(self, torrent): @@ -367,28 +355,40 @@ class ShareLimits: if self.group_tag: torrent.add_tags(self.group_tag) - def update_share_limits_for_torrent(self, torrent, group_config, tor_reached_seed_limit, torrent_upload_limit): + def process_share_limits_for_torrent(self, torrent, group_config, tor_reached_seed_limit, torrent_upload_limit): """Updates share limits for a torrent""" + # Take action when torrent meets share limits if tor_reached_seed_limit: - # New behavior: throttle upload speed instead of pausing/removing - throttle_kib = group_config.get("upload_speed_on_limit_reached", 0) - # Apply per-torrent upload throttle (KiB/s) or unlimited if -1/0 - limit_val = -1 if throttle_kib == -1 else throttle_kib * 1024 - if limit_val and throttle_kib != torrent_upload_limit: - logger.print_line( - logger.insert_space("Cleanup: False [Meets Share Limits]", 8), - self.config.loglevel, + if group_config["cleanup"]: + # Queue for cleanup (delete .torrent and possibly contents) + t_hash = torrent.hash + if t_hash not in self.tdel_dict: + self.tdel_dict[t_hash] = {} + self.tdel_dict[t_hash]["torrent"] = torrent + self.tdel_dict[t_hash]["content_path"] = util.path_replace( + torrent["content_path"], self.root_dir, self.remote_dir ) - disp = "unlimited" if throttle_kib == -1 else f"{throttle_kib} kB/s" - logger.print_line( - logger.insert_space(f"Applied upload throttle after limits reached: {disp}", 8), - self.config.loglevel, - ) - # Clear share limits to prevent qBittorrent from pausing again, then apply throttle - if not self.config.dry_run: - # Allow continued seeding by removing share limits - torrent.set_share_limits(ratio_limit=-1, seeding_time_limit=-1, inactive_seeding_time_limit=-1) - torrent.set_upload_limit(limit_val) + self.tdel_dict[t_hash]["body"] = tor_reached_seed_limit + else: + # New behavior: throttle upload speed instead of pausing/removing + throttle_kib = group_config.get("upload_speed_on_limit_reached", 0) + # Apply per-torrent upload throttle (KiB/s) or unlimited if -1/0 + limit_val = -1 if throttle_kib == -1 else throttle_kib * 1024 + if limit_val and throttle_kib != torrent_upload_limit: + logger.print_line( + logger.insert_space("Cleanup: False [Meets Share Limits]", 8), + self.config.loglevel, + ) + disp = "unlimited" if throttle_kib == -1 else f"{throttle_kib} kB/s" + logger.print_line( + logger.insert_space(f"Applied upload throttle after limits reached: {disp}", 8), + self.config.loglevel, + ) + # Clear share limits to prevent qBittorrent from pausing again, then apply throttle + if not self.config.dry_run: + # Allow continued seeding by removing share limits + torrent.set_share_limits(ratio_limit=-1, seeding_time_limit=-1, inactive_seeding_time_limit=-1) + torrent.set_upload_limit(limit_val) else: self.set_limits( torrent=torrent,