mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-12-10 13:56:13 +08:00
Fix upload_speed_on_limit_reached toggles share limits
This commit is contained in:
parent
564f9f3fc9
commit
937fc8bed8
1 changed files with 44 additions and 41 deletions
|
|
@ -305,6 +305,10 @@ class ShareLimits:
|
|||
tracker=tracker["url"],
|
||||
reset_upload_speed_on_unmet_minimums=group_config["reset_upload_speed_on_unmet_minimums"],
|
||||
)
|
||||
|
||||
# Update share limits tag if needed
|
||||
self.update_share_limits_tag_for_torrent(torrent)
|
||||
|
||||
# Get updated torrent after checking if the torrent has reached seed limits
|
||||
torrent = self.qbt.get_torrents({"torrent_hashes": t_hash})[0]
|
||||
if (
|
||||
|
|
@ -327,7 +331,7 @@ 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.tag_and_update_share_limits_for_torrent(torrent, group_config)
|
||||
self.update_share_limits_for_torrent(torrent, group_config, tor_reached_seed_limit, torrent_upload_limit)
|
||||
self.stats_tagged += 1
|
||||
self.torrents_updated.append(t_name)
|
||||
|
||||
|
|
@ -342,21 +346,39 @@ class ShareLimits:
|
|||
torrent["content_path"], self.root_dir, self.remote_dir
|
||||
)
|
||||
self.tdel_dict[t_hash]["body"] = tor_reached_seed_limit
|
||||
else:
|
||||
|
||||
self.torrent_hash_checked.append(t_hash)
|
||||
|
||||
def update_share_limits_tag_for_torrent(self, torrent):
|
||||
"""Updates share limits tag for a torrent if needed"""
|
||||
# Check if the share limits tag needs to be updated
|
||||
if not self.config.dry_run:
|
||||
# Remove previous share_limits tag
|
||||
tag = is_tag_in_torrent(self.share_limits_tag, torrent.tags, exact=False)
|
||||
if tag:
|
||||
torrent.remove_tags(tag)
|
||||
# Check if any of the previous share limits custom tags are there
|
||||
for custom_tag in self.share_limits_custom_tags:
|
||||
if is_tag_in_torrent(custom_tag, torrent.tags):
|
||||
torrent.remove_tags(custom_tag)
|
||||
# Will tag the torrent with the group name if add_group_to_tag is True
|
||||
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):
|
||||
"""Updates share limits for a torrent"""
|
||||
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:
|
||||
body = []
|
||||
body += logger.print_line(logger.insert_space(f"Torrent Name: {t_name}", 3), self.config.loglevel)
|
||||
body += logger.print_line(logger.insert_space(f"Tracker: {tracker['url']}", 8), self.config.loglevel)
|
||||
body += logger.print_line(
|
||||
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"
|
||||
body += logger.print_line(
|
||||
logger.print_line(
|
||||
logger.insert_space(f"Applied upload throttle after limits reached: {disp}", 8),
|
||||
self.config.loglevel,
|
||||
)
|
||||
|
|
@ -365,31 +387,14 @@ class ShareLimits:
|
|||
# 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)
|
||||
# Optionally resume if configured
|
||||
if group_config["resume_torrent_after_change"] and torrent.state_enum.is_complete:
|
||||
torrent.resume()
|
||||
self.torrent_hash_checked.append(t_hash)
|
||||
|
||||
def tag_and_update_share_limits_for_torrent(self, torrent, group_config):
|
||||
"""Removes previous share limits tag, updates tag and share limits for a torrent, and resumes the torrent"""
|
||||
# Remove previous share_limits tag
|
||||
if not self.config.dry_run:
|
||||
tag = is_tag_in_torrent(self.share_limits_tag, torrent.tags, exact=False)
|
||||
if tag:
|
||||
torrent.remove_tags(tag)
|
||||
# Check if any of the previous share limits custom tags are there
|
||||
for custom_tag in self.share_limits_custom_tags:
|
||||
if is_tag_in_torrent(custom_tag, torrent.tags):
|
||||
torrent.remove_tags(custom_tag)
|
||||
|
||||
# Will tag the torrent with the group name if add_group_to_tag is True and set the share limits
|
||||
self.set_tags_and_limits(
|
||||
else:
|
||||
self.set_limits(
|
||||
torrent=torrent,
|
||||
max_ratio=group_config["max_ratio"],
|
||||
max_seeding_time=group_config["max_seeding_time"],
|
||||
limit_upload_speed=group_config["limit_upload_speed"],
|
||||
tags=self.group_tag,
|
||||
)
|
||||
|
||||
# Resume torrent if it was paused now that the share limit has changed
|
||||
if torrent.state_enum.is_complete and group_config["resume_torrent_after_change"]:
|
||||
if not self.config.dry_run:
|
||||
|
|
@ -501,7 +506,7 @@ class ShareLimits:
|
|||
|
||||
return None
|
||||
|
||||
def set_tags_and_limits(self, torrent, max_ratio, max_seeding_time, limit_upload_speed=None, tags=None, do_print=True):
|
||||
def set_limits(self, torrent, max_ratio, max_seeding_time, limit_upload_speed=None, do_print=True):
|
||||
"""Set tags and limits for a torrent"""
|
||||
body = []
|
||||
if limit_upload_speed is not None:
|
||||
|
|
@ -529,8 +534,6 @@ class ShareLimits:
|
|||
body.append(msg)
|
||||
# Update Torrents
|
||||
if not self.config.dry_run:
|
||||
if tags:
|
||||
torrent.add_tags(tags)
|
||||
torrent_upload_limit = -1 if round(torrent.up_limit / 1024) == 0 else round(torrent.up_limit / 1024)
|
||||
if limit_upload_speed is not None and limit_upload_speed != torrent_upload_limit:
|
||||
if limit_upload_speed == -1:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue