mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-12-11 22:36:58 +08:00
Fix upload_speed_on_limit_reached toggles share limits
This commit is contained in:
parent
078bbbfbb8
commit
679d2e8656
1 changed files with 44 additions and 41 deletions
|
|
@ -305,6 +305,10 @@ class ShareLimits:
|
||||||
tracker=tracker["url"],
|
tracker=tracker["url"],
|
||||||
reset_upload_speed_on_unmet_minimums=group_config["reset_upload_speed_on_unmet_minimums"],
|
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
|
# Get updated torrent after checking if the torrent has reached seed limits
|
||||||
torrent = self.qbt.get_torrents({"torrent_hashes": t_hash})[0]
|
torrent = self.qbt.get_torrents({"torrent_hashes": t_hash})[0]
|
||||||
if (
|
if (
|
||||||
|
|
@ -327,7 +331,7 @@ 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.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.stats_tagged += 1
|
||||||
self.torrents_updated.append(t_name)
|
self.torrents_updated.append(t_name)
|
||||||
|
|
||||||
|
|
@ -342,38 +346,14 @@ class ShareLimits:
|
||||||
torrent["content_path"], self.root_dir, self.remote_dir
|
torrent["content_path"], self.root_dir, self.remote_dir
|
||||||
)
|
)
|
||||||
self.tdel_dict[t_hash]["body"] = tor_reached_seed_limit
|
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:
|
|
||||||
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.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.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)
|
|
||||||
# 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)
|
self.torrent_hash_checked.append(t_hash)
|
||||||
|
|
||||||
def tag_and_update_share_limits_for_torrent(self, torrent, group_config):
|
def update_share_limits_tag_for_torrent(self, torrent):
|
||||||
"""Removes previous share limits tag, updates tag and share limits for a torrent, and resumes the torrent"""
|
"""Updates share limits tag for a torrent if needed"""
|
||||||
# Remove previous share_limits tag
|
# Check if the share limits tag needs to be updated
|
||||||
if not self.config.dry_run:
|
if not self.config.dry_run:
|
||||||
|
# Remove previous share_limits tag
|
||||||
tag = is_tag_in_torrent(self.share_limits_tag, torrent.tags, exact=False)
|
tag = is_tag_in_torrent(self.share_limits_tag, torrent.tags, exact=False)
|
||||||
if tag:
|
if tag:
|
||||||
torrent.remove_tags(tag)
|
torrent.remove_tags(tag)
|
||||||
|
|
@ -381,15 +361,40 @@ class ShareLimits:
|
||||||
for custom_tag in self.share_limits_custom_tags:
|
for custom_tag in self.share_limits_custom_tags:
|
||||||
if is_tag_in_torrent(custom_tag, torrent.tags):
|
if is_tag_in_torrent(custom_tag, torrent.tags):
|
||||||
torrent.remove_tags(custom_tag)
|
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:
|
||||||
|
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,
|
||||||
|
max_ratio=group_config["max_ratio"],
|
||||||
|
max_seeding_time=group_config["max_seeding_time"],
|
||||||
|
limit_upload_speed=group_config["limit_upload_speed"],
|
||||||
|
)
|
||||||
|
|
||||||
# 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(
|
|
||||||
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
|
# 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 torrent.state_enum.is_complete and group_config["resume_torrent_after_change"]:
|
||||||
if not self.config.dry_run:
|
if not self.config.dry_run:
|
||||||
|
|
@ -501,7 +506,7 @@ class ShareLimits:
|
||||||
|
|
||||||
return None
|
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"""
|
"""Set tags and limits for a torrent"""
|
||||||
body = []
|
body = []
|
||||||
if limit_upload_speed is not None:
|
if limit_upload_speed is not None:
|
||||||
|
|
@ -529,8 +534,6 @@ class ShareLimits:
|
||||||
body.append(msg)
|
body.append(msg)
|
||||||
# Update Torrents
|
# Update Torrents
|
||||||
if not self.config.dry_run:
|
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)
|
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 is not None and limit_upload_speed != torrent_upload_limit:
|
||||||
if limit_upload_speed == -1:
|
if limit_upload_speed == -1:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue