Revert "Revert "Add Aggregate Group Speed Capabilities""

This reverts commit f112b2c92e.
Fixes bug in original commit code
This commit is contained in:
bobokun 2024-04-01 10:18:24 -04:00
parent 3287cc6b37
commit 41d5170ba6
No known key found for this signature in database
GPG key ID: B73932169607D927
4 changed files with 40 additions and 10 deletions

View file

@ -1 +1 @@
4.0.10-develop2
4.0.10-develop3

View file

@ -198,6 +198,8 @@ share_limits:
last_active: 43200
# <OPTIONAL> Limit Upload Speed <int>: Will limit the upload speed KiB/s (KiloBytes/second) (`-1` : No Limit)
limit_upload_speed: 0
# <OPTIONAL> Group Upload Speed <int>: Will limit the group's combined upload speed KiB/s (KiloBytes/second) (`-1` : No Limit)
group_upload_speed: 0
# <OPTIONAL> cleanup <bool>: WARNING!! Setting this as true Will remove and delete contents of any torrents that satisfies the share limits (max time OR max ratio)
cleanup: false
# <OPTIONAL> resume_torrent_after_change <bool>: This variable will resume your torrent after changing share limits. Default is true

View file

@ -465,6 +465,17 @@ class Config:
do_print=False,
save=False,
)
self.share_limits[group]["group_upload_speed"] = self.util.check_for_attribute(
self.data,
"group_upload_speed",
parent="share_limits",
subparent=group,
var_type="int",
min_int=-1,
default_is_none=True,
do_print=False,
save=False,
)
self.share_limits[group]["min_num_seeds"] = self.util.check_for_attribute(
self.data,
"min_num_seeds",

View file

@ -59,6 +59,7 @@ class ShareLimits:
"torrent_min_seeding_time": group_config["min_seeding_time"],
"torrent_min_num_seeds": group_config["min_num_seeds"],
"torrent_limit_upload_speed": group_config["limit_upload_speed"],
"torrent_group_upload_speed": group_config["group_upload_speed"],
"torrent_last_active": group_config["last_active"],
}
if len(self.torrents_updated) > 0:
@ -170,6 +171,8 @@ class ShareLimits:
logger.separator(
f"Updating Share Limits for [Group {group_name}] [Priority {group_config['priority']}]", space=False, border=False
)
if group_config["group_upload_speed"] and group_config["limit_upload_speed"]:
logger.trace("Info: group_upload_speed and limit_upload_speed both specified, ignoring group_upload_speed.")
for torrent in torrents:
t_name = torrent.name
t_hash = torrent.hash
@ -183,6 +186,11 @@ class ShareLimits:
torrent_upload_limit = -1 if round(torrent.up_limit / 1024) == 0 else round(torrent.up_limit / 1024)
if group_config["limit_upload_speed"] == 0:
group_config["limit_upload_speed"] = -1
if group_config["group_upload_speed"]:
group_up_limit = round(group_config["group_upload_speed"] / len(torrents))
else:
group_up_limit = -1
check_group_upload_speed = group_up_limit != torrent_upload_limit
check_limit_upload_speed = group_config["limit_upload_speed"] != torrent_upload_limit
hash_not_prev_checked = t_hash not in self.torrent_hash_checked
share_limits_not_yet_tagged = (
@ -200,15 +208,25 @@ class ShareLimits:
)
logger.trace(f"Config Min Num Seeds vs Torrent Num Seeds: {group_config['min_num_seeds']} vs {torrent.num_complete}")
logger.trace(f"check_max_seeding_time: {check_max_seeding_time}")
logger.trace(
"Config Limit Upload Speed vs Torrent Limit Upload Speed: "
f"{group_config['limit_upload_speed']} vs {torrent_upload_limit}"
)
if group_config["group_upload_speed"]:
logger.trace(
f"Config Group Upload Speed vs Torrent Limit Upload Speed: {group_up_limit} vs {torrent_upload_limit}"
)
else:
logger.trace(
"Config Limit Upload Speed vs Torrent Limit Upload Speed: "
f"{group_config['limit_upload_speed']} vs {torrent_upload_limit}"
)
logger.trace(f"check_limit_upload_speed: {check_limit_upload_speed}")
logger.trace(f"check_group_upload_speed: {check_group_upload_speed}")
logger.trace(f"hash_not_prev_checked: {hash_not_prev_checked}")
logger.trace(f"share_limits_not_yet_tagged: {share_limits_not_yet_tagged}")
if (
check_max_ratio or check_max_seeding_time or check_limit_upload_speed or share_limits_not_yet_tagged
check_max_ratio
or check_max_seeding_time
or check_limit_upload_speed
or check_group_upload_speed
or share_limits_not_yet_tagged
) and hash_not_prev_checked:
if (
not is_tag_in_torrent(self.min_seeding_time_tag, torrent.tags)
@ -219,7 +237,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.tag_and_update_share_limits_for_torrent(torrent, group_config, group_up_limit)
self.stats_tagged += 1
self.torrents_updated.append(t_name)
@ -243,20 +261,19 @@ class ShareLimits:
self.tdel_dict[t_hash]["body"] = tor_reached_seed_limit
self.torrent_hash_checked.append(t_hash)
def tag_and_update_share_limits_for_torrent(self, torrent, group_config):
def tag_and_update_share_limits_for_torrent(self, torrent, group_config, group_up_limit):
"""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)
# 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"],
limit_upload_speed=group_config["limit_upload_speed"] if group_config["limit_upload_speed"] else group_up_limit,
tags=self.group_tag,
)
# Resume torrent if it was paused now that the share limit has changed