Pre check if share limits are reached

This commit is contained in:
Erik Müller 2025-11-24 17:12:56 +01:00 committed by bobokun
parent 47308469ed
commit 2dfe50a304

View file

@ -333,22 +333,10 @@ class ShareLimits:
logger.print_line(logger.insert_space(f"Tracker: {tracker['url']}", 8), self.config.loglevel) logger.print_line(logger.insert_space(f"Tracker: {tracker['url']}", 8), self.config.loglevel)
if self.group_tag: if self.group_tag:
logger.print_line(logger.insert_space(f"Added Tag: {self.group_tag}", 8), self.config.loglevel) 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.stats_tagged += 1
self.torrents_updated.append(t_name) 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) self.torrent_hash_checked.append(t_hash)
def update_share_limits_tag_for_torrent(self, torrent): def update_share_limits_tag_for_torrent(self, torrent):
@ -367,28 +355,40 @@ class ShareLimits:
if self.group_tag: if self.group_tag:
torrent.add_tags(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""" """Updates share limits for a torrent"""
# Take action when torrent meets share limits
if tor_reached_seed_limit: if tor_reached_seed_limit:
# New behavior: throttle upload speed instead of pausing/removing if group_config["cleanup"]:
throttle_kib = group_config.get("upload_speed_on_limit_reached", 0) # Queue for cleanup (delete .torrent and possibly contents)
# Apply per-torrent upload throttle (KiB/s) or unlimited if -1/0 t_hash = torrent.hash
limit_val = -1 if throttle_kib == -1 else throttle_kib * 1024 if t_hash not in self.tdel_dict:
if limit_val and throttle_kib != torrent_upload_limit: self.tdel_dict[t_hash] = {}
logger.print_line( self.tdel_dict[t_hash]["torrent"] = torrent
logger.insert_space("Cleanup: False [Meets Share Limits]", 8), self.tdel_dict[t_hash]["content_path"] = util.path_replace(
self.config.loglevel, torrent["content_path"], self.root_dir, self.remote_dir
) )
disp = "unlimited" if throttle_kib == -1 else f"{throttle_kib} kB/s" self.tdel_dict[t_hash]["body"] = tor_reached_seed_limit
logger.print_line( else:
logger.insert_space(f"Applied upload throttle after limits reached: {disp}", 8), # New behavior: throttle upload speed instead of pausing/removing
self.config.loglevel, throttle_kib = group_config.get("upload_speed_on_limit_reached", 0)
) # Apply per-torrent upload throttle (KiB/s) or unlimited if -1/0
# Clear share limits to prevent qBittorrent from pausing again, then apply throttle limit_val = -1 if throttle_kib == -1 else throttle_kib * 1024
if not self.config.dry_run: if limit_val and throttle_kib != torrent_upload_limit:
# Allow continued seeding by removing share limits logger.print_line(
torrent.set_share_limits(ratio_limit=-1, seeding_time_limit=-1, inactive_seeding_time_limit=-1) logger.insert_space("Cleanup: False [Meets Share Limits]", 8),
torrent.set_upload_limit(limit_val) 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: else:
self.set_limits( self.set_limits(
torrent=torrent, torrent=torrent,