Skip to content

Commit

Permalink
Adds [FR]: Option to completely customize tag name. #551
Browse files Browse the repository at this point in the history
  • Loading branch information
bobokun committed May 20, 2024
1 parent b393431 commit ba40c5c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.5-develop3
4.1.5-develop4
2 changes: 2 additions & 0 deletions config/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ share_limits:
# If the torrent has less number of seeds than the min_num_seeds, the share limits will be changed back to no limits and resume the torrent to continue seeding.
# Will default to 0 if not specified for the group.
min_num_seeds: 0
# <OPTIONAL> custom_tag <str>: Apply a custom tag name for this particular group. **WARNING (This tag MUST be unique as it will be used to determine share limits. Please ensure it does not overlap with any other tags in qbt)**
custom_tag: sharelimits_noHL
cross-seed:
priority: 2
include_all_tags:
Expand Down
24 changes: 24 additions & 0 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def hooks(attr):
self.tracker_error_tag = self.settings["tracker_error_tag"]
self.nohardlinks_tag = self.settings["nohardlinks_tag"]
self.share_limits_tag = self.settings["share_limits_tag"]
self.share_limits_custom_tags = []
self.share_limits_min_seeding_time_tag = self.settings["share_limits_min_seeding_time_tag"]
self.share_limits_min_num_seeds_tag = self.settings["share_limits_min_num_seeds_tag"]
self.share_limits_last_active_tag = self.settings["share_limits_last_active_tag"]
Expand All @@ -204,6 +205,7 @@ def hooks(attr):
self.share_limits_min_seeding_time_tag,
self.share_limits_min_num_seeds_tag,
self.share_limits_last_active_tag,
self.share_limits_tag,
]
# "Migrate settings from v4.0.0 to v4.0.1 and beyond. Convert 'share_limits_suffix_tag' to 'share_limits_tag'"
if "share_limits_suffix_tag" in self.data["settings"]:
Expand Down Expand Up @@ -522,6 +524,28 @@ def _sort_share_limits(share_limits):
do_print=False,
save=False,
)
self.share_limits[group]["custom_tag"] = self.util.check_for_attribute(
self.data,
"custom_tag",
parent="share_limits",
subparent=group,
default_is_none=True,
do_print=False,
save=False,
)
if self.share_limits[group]["custom_tag"]:
if (
self.share_limits[group]["custom_tag"] not in self.share_limits_custom_tags
and self.share_limits[group]["custom_tag"] not in self.default_ignore_tags
):
self.share_limits_custom_tags.append(self.share_limits[group]["custom_tag"])
else:
err = (
f"Config Error: Duplicate custom tag '{self.share_limits[group]['custom_tag']}' "
f"found in share_limits for the grouping '{group}'. Custom tag must be a unique value."
)
self.notify(err, "Config")
raise Failed(err)
self.share_limits[group]["torrents"] = []
if (
self.share_limits[group]["min_seeding_time"] > 0
Expand Down
49 changes: 40 additions & 9 deletions modules/core/share_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, qbit_manager):
self.torrents_updated = [] # list of torrents that have been updated
self.torrent_hash_checked = [] # list of torrent hashes that have been checked for share limits
self.share_limits_tag = qbit_manager.config.share_limits_tag # tag for share limits
self.share_limits_custom_tags = qbit_manager.config.share_limits_custom_tags # All possible custom share limits tags
self.min_seeding_time_tag = qbit_manager.config.share_limits_min_seeding_time_tag # tag for min seeding time
self.min_num_seeds_tag = qbit_manager.config.share_limits_min_num_seeds_tag # tag for min num seeds
self.last_active_tag = qbit_manager.config.share_limits_last_active_tag # tag for last active
Expand Down Expand Up @@ -175,9 +176,13 @@ def update_share_limits_for_group(self, group_name, group_config, torrents):
for torrent in torrents:
t_name = torrent.name
t_hash = torrent.hash
self.group_tag = (
f"{self.share_limits_tag}_{group_config['priority']}.{group_name}" if group_config["add_group_to_tag"] else None
)
if group_config["add_group_to_tag"]:
if group_config["custom_tag"]:
self.group_tag = group_config["custom_tag"]
else:
self.group_tag = f"{self.share_limits_tag}_{group_config['priority']}.{group_name}"
else:
self.group_tag = None
tracker = self.qbt.get_tags(self.qbt.get_tracker_urls(torrent.trackers))
check_max_ratio = group_config["max_ratio"] != torrent.max_ratio
check_max_seeding_time = group_config["max_seeding_time"] != torrent.max_seeding_time
Expand All @@ -195,12 +200,34 @@ def update_share_limits_for_group(self, group_name, group_config, torrents):
group_config["limit_upload_speed"] = round(group_upload_speed / len(torrents))
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 = (
True if self.group_tag and not is_tag_in_torrent(self.group_tag, torrent.tags) else False
)
check_multiple_share_limits_tag = (
self.group_tag and len(is_tag_in_torrent(self.share_limits_tag, torrent.tags, exact=False)) > 1
)

if self.group_tag:
if group_config["custom_tag"] and not is_tag_in_torrent(self.group_tag, torrent.tags):
share_limits_not_yet_tagged = True
elif not group_config["custom_tag"] and not is_tag_in_torrent(self.group_tag, torrent.tags, exact=False):
share_limits_not_yet_tagged = True
else:
share_limits_not_yet_tagged = False

check_multiple_share_limits_tag = False # Default assume no multiple share limits tag

# Check if any of the previous share limits custom tags are there
for custom_tag in self.share_limits_custom_tags:
if custom_tag != self.group_tag and is_tag_in_torrent(custom_tag, torrent.tags):
check_multiple_share_limits_tag = True
break
# Check if there are any other share limits tags in the torrent
if group_config["custom_tag"] and len(is_tag_in_torrent(self.share_limits_tag, torrent.tags, exact=False)) > 0:
check_multiple_share_limits_tag = True
elif (
not group_config["custom_tag"]
and len(is_tag_in_torrent(self.share_limits_tag, torrent.tags, exact=False)) > 1
):
check_multiple_share_limits_tag = True
else:
share_limits_not_yet_tagged = False
check_multiple_share_limits_tag = False

logger.trace(f"Torrent: {t_name} [Hash: {t_hash}]")
logger.trace(f"Torrent Category: {torrent.category}")
logger.trace(f"Torrent Tags: {torrent.tags}")
Expand Down Expand Up @@ -287,6 +314,10 @@ def tag_and_update_share_limits_for_torrent(self, torrent, group_config):
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(
Expand Down
1 change: 0 additions & 1 deletion modules/core/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def __init__(self, qbit_manager):
self.client = qbit_manager.client
self.stats = 0
self.share_limits_tag = qbit_manager.config.share_limits_tag # suffix tag for share limits
self.default_ignore_tags = qbit_manager.config.default_ignore_tags # default ignore tags
self.torrents_updated = [] # List of torrents updated
self.notify_attr = [] # List of single torrent attributes to send to notifiarr

Expand Down

0 comments on commit ba40c5c

Please sign in to comment.