mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-09-12 08:04:35 +08:00
adds support for custom noHL tag #210
This commit is contained in:
parent
61c42e7f5b
commit
d1c26fffa6
4 changed files with 37 additions and 24 deletions
|
@ -25,6 +25,7 @@ qbt:
|
||||||
settings:
|
settings:
|
||||||
force_auto_tmm: False # Will force qBittorrent to enable Automatic Torrent Management for each torrent.
|
force_auto_tmm: False # Will force qBittorrent to enable Automatic Torrent Management for each torrent.
|
||||||
tracker_error_tag: issue # Will set the tag of any torrents that do not have a working tracker.
|
tracker_error_tag: issue # Will set the tag of any torrents that do not have a working tracker.
|
||||||
|
nohardlinks_tag: noHL # Will set the tag of any torrents with no hardlinks.
|
||||||
ignoreTags_OnUpdate: # When running tag-update function, it will update torrent tags for a given torrent even if the torrent has at least one or more of the tags defined here. Otherwise torrents will not be tagged if tags exist.
|
ignoreTags_OnUpdate: # When running tag-update function, it will update torrent tags for a given torrent even if the torrent has at least one or more of the tags defined here. Otherwise torrents will not be tagged if tags exist.
|
||||||
- noHL
|
- noHL
|
||||||
- issue
|
- issue
|
||||||
|
|
|
@ -146,8 +146,13 @@ class Config:
|
||||||
"tracker_error_tag": self.util.check_for_attribute(
|
"tracker_error_tag": self.util.check_for_attribute(
|
||||||
self.data, "tracker_error_tag", parent="settings", default="issue"
|
self.data, "tracker_error_tag", parent="settings", default="issue"
|
||||||
),
|
),
|
||||||
|
"nohardlinks_tag": self.util.check_for_attribute(self.data, "nohardlinks_tag", parent="settings", default="noHL"),
|
||||||
}
|
}
|
||||||
default_ignore_tags = ["noHL", self.settings["tracker_error_tag"], "cross-seed"]
|
|
||||||
|
self.tracker_error_tag = self.settings["tracker_error_tag"]
|
||||||
|
self.nohardlinks_tag = self.settings["nohardlinks_tag"]
|
||||||
|
|
||||||
|
default_ignore_tags = [self.nohardlinks_tag, self.tracker_error_tag, "cross-seed"]
|
||||||
self.settings["ignoreTags_OnUpdate"] = self.util.check_for_attribute(
|
self.settings["ignoreTags_OnUpdate"] = self.util.check_for_attribute(
|
||||||
self.data, "ignoreTags_OnUpdate", parent="settings", default=default_ignore_tags, var_type="list"
|
self.data, "ignoreTags_OnUpdate", parent="settings", default=default_ignore_tags, var_type="list"
|
||||||
)
|
)
|
||||||
|
|
|
@ -402,6 +402,8 @@ class Qbt:
|
||||||
def _has_reached_min_seeding_time_limit():
|
def _has_reached_min_seeding_time_limit():
|
||||||
print_log = []
|
print_log = []
|
||||||
if torrent.seeding_time >= min_seeding_time * 60:
|
if torrent.seeding_time >= min_seeding_time * 60:
|
||||||
|
if "MinSeedTimeNotReached" in torrent.tags:
|
||||||
|
torrent.remove_tags(tags="MinSeedTimeNotReached")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print_log += logger.print_line(logger.insert_space(f"Torrent Name: {torrent.name}", 3), self.config.loglevel)
|
print_log += logger.print_line(logger.insert_space(f"Torrent Name: {torrent.name}", 3), self.config.loglevel)
|
||||||
|
@ -468,12 +470,12 @@ class Qbt:
|
||||||
num_untag = 0 # counter for number of torrents that previously had no hardlinks but now have hardlinks
|
num_untag = 0 # counter for number of torrents that previously had no hardlinks but now have hardlinks
|
||||||
|
|
||||||
def add_tag_no_hl(add_tag=True):
|
def add_tag_no_hl(add_tag=True):
|
||||||
"""Add tag noHL to torrents with no hardlinks"""
|
"""Add tag nohardlinks_tag to torrents with no hardlinks"""
|
||||||
nonlocal num_tags, torrent, tracker, nohardlinks, category, max_ratio, max_seeding_time
|
nonlocal num_tags, torrent, tracker, nohardlinks, category, max_ratio, max_seeding_time
|
||||||
body = []
|
body = []
|
||||||
body.append(logger.insert_space(f"Torrent Name: {torrent.name}", 3))
|
body.append(logger.insert_space(f"Torrent Name: {torrent.name}", 3))
|
||||||
if add_tag:
|
if add_tag:
|
||||||
body.append(logger.insert_space("Added Tag: noHL", 6))
|
body.append(logger.insert_space(f"Added Tag: {self.config.nohardlinks_tag}", 6))
|
||||||
title = "Tagging Torrents with No Hardlinks"
|
title = "Tagging Torrents with No Hardlinks"
|
||||||
else:
|
else:
|
||||||
title = "Changing Share Ratio of Torrents with No Hardlinks"
|
title = "Changing Share Ratio of Torrents with No Hardlinks"
|
||||||
|
@ -483,13 +485,13 @@ class Qbt:
|
||||||
max_ratio,
|
max_ratio,
|
||||||
max_seeding_time,
|
max_seeding_time,
|
||||||
nohardlinks[category]["limit_upload_speed"],
|
nohardlinks[category]["limit_upload_speed"],
|
||||||
tags="noHL",
|
tags=self.config.nohardlinks_tag,
|
||||||
do_print=False,
|
do_print=False,
|
||||||
)
|
)
|
||||||
if body_tags_and_limits or add_tag:
|
if body_tags_and_limits or add_tag:
|
||||||
num_tags += 1
|
num_tags += 1
|
||||||
# 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 == "pausedUP" and nohardlinks[category]["resume_torrent_after_untagging_noHL"]:
|
if torrent.state_enum.is_complete and nohardlinks[category]["resume_torrent_after_untagging_noHL"]:
|
||||||
if not self.config.dry_run:
|
if not self.config.dry_run:
|
||||||
torrent.resume()
|
torrent.resume()
|
||||||
body.extend(body_tags_and_limits)
|
body.extend(body_tags_and_limits)
|
||||||
|
@ -501,7 +503,7 @@ class Qbt:
|
||||||
"body": "\n".join(body),
|
"body": "\n".join(body),
|
||||||
"torrent_name": torrent.name,
|
"torrent_name": torrent.name,
|
||||||
"torrent_category": torrent.category,
|
"torrent_category": torrent.category,
|
||||||
"torrent_tag": "noHL",
|
"torrent_tag": self.config.nohardlinks_tag,
|
||||||
"torrent_tracker": tracker["url"],
|
"torrent_tracker": tracker["url"],
|
||||||
"notifiarr_indexer": tracker["notifiarr"],
|
"notifiarr_indexer": tracker["notifiarr"],
|
||||||
"torrent_max_ratio": max_ratio,
|
"torrent_max_ratio": max_ratio,
|
||||||
|
@ -535,7 +537,7 @@ class Qbt:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
# Checks for any hardlinks and not already tagged
|
# Checks for any hardlinks and not already tagged
|
||||||
# Cleans up previously tagged noHL torrents that no longer have hardlinks
|
# Cleans up previously tagged nohardlinks_tag torrents that no longer have hardlinks
|
||||||
if has_nohardlinks:
|
if has_nohardlinks:
|
||||||
tracker = self.config.get_tags(torrent.trackers)
|
tracker = self.config.get_tags(torrent.trackers)
|
||||||
# Determine min_seeding_time.
|
# Determine min_seeding_time.
|
||||||
|
@ -575,8 +577,8 @@ class Qbt:
|
||||||
elif nohardlinks[category]["max_seeding_time"]:
|
elif nohardlinks[category]["max_seeding_time"]:
|
||||||
max_seeding_time = nohardlinks[category]["max_seeding_time"]
|
max_seeding_time = nohardlinks[category]["max_seeding_time"]
|
||||||
|
|
||||||
# Will only tag new torrents that don't have noHL tag
|
# Will only tag new torrents that don't have nohardlinks_tag tag
|
||||||
if "noHL" not in torrent.tags:
|
if self.config.nohardlinks_tag not in torrent.tags:
|
||||||
add_tag_no_hl(add_tag=True)
|
add_tag_no_hl(add_tag=True)
|
||||||
|
|
||||||
# Deletes torrent with data if cleanup is set to true and meets the ratio/seeding requirements
|
# Deletes torrent with data if cleanup is set to true and meets the ratio/seeding requirements
|
||||||
|
@ -599,16 +601,20 @@ class Qbt:
|
||||||
else:
|
else:
|
||||||
# Updates torrent to see if "MinSeedTimeNotReached" tag has been added
|
# Updates torrent to see if "MinSeedTimeNotReached" tag has been added
|
||||||
torrent = self.get_torrents({"torrent_hashes": [torrent.hash]}).data[0]
|
torrent = self.get_torrents({"torrent_hashes": [torrent.hash]}).data[0]
|
||||||
# Checks to see if previously noHL share limits have changed.
|
# Checks to see if previously nohardlinks_tag share limits have changed.
|
||||||
add_tag_no_hl(add_tag=False)
|
add_tag_no_hl(add_tag=False)
|
||||||
# Checks to see if previous noHL tagged torrents now have hardlinks.
|
# Checks to see if previous nohardlinks_tag tagged torrents now have hardlinks.
|
||||||
if not (has_nohardlinks) and ("noHL" in torrent.tags):
|
if not (has_nohardlinks) and (self.config.nohardlinks_tag in torrent.tags):
|
||||||
num_untag += 1
|
num_untag += 1
|
||||||
body = []
|
body = []
|
||||||
body += logger.print_line(
|
body += logger.print_line(
|
||||||
f"Previous Tagged noHL Torrent Name: {torrent.name} has hardlinks found now.", self.config.loglevel
|
f"Previous Tagged {self.config.nohardlinks_tag} "
|
||||||
|
f"Torrent Name: {torrent.name} has hardlinks found now.",
|
||||||
|
self.config.loglevel,
|
||||||
|
)
|
||||||
|
body += logger.print_line(
|
||||||
|
logger.insert_space(f"Removed Tag: {self.config.nohardlinks_tag}", 6), self.config.loglevel
|
||||||
)
|
)
|
||||||
body += logger.print_line(logger.insert_space("Removed Tag: noHL", 6), 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(f'Tracker: {tracker["url"]}', 8), self.config.loglevel)
|
||||||
body += logger.print_line(
|
body += logger.print_line(
|
||||||
f"{'Not Reverting' if self.config.dry_run else 'Reverting'} to tracker or Global share limits.",
|
f"{'Not Reverting' if self.config.dry_run else 'Reverting'} to tracker or Global share limits.",
|
||||||
|
@ -624,13 +630,13 @@ class Qbt:
|
||||||
if restore_limit_upload_speed is None:
|
if restore_limit_upload_speed is None:
|
||||||
restore_limit_upload_speed = -1
|
restore_limit_upload_speed = -1
|
||||||
if not self.config.dry_run:
|
if not self.config.dry_run:
|
||||||
torrent.remove_tags(tags="noHL")
|
torrent.remove_tags(tags=self.config.nohardlinks_tag)
|
||||||
body.extend(
|
body.extend(
|
||||||
self.set_tags_and_limits(
|
self.set_tags_and_limits(
|
||||||
torrent, restore_max_ratio, restore_max_seeding_time, restore_limit_upload_speed, restore=True
|
torrent, restore_max_ratio, restore_max_seeding_time, restore_limit_upload_speed, restore=True
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if torrent.state == "pausedUP" and nohardlinks[category]["resume_torrent_after_untagging_noHL"]:
|
if torrent.state_enum.is_complete and nohardlinks[category]["resume_torrent_after_untagging_noHL"]:
|
||||||
torrent.resume()
|
torrent.resume()
|
||||||
attr = {
|
attr = {
|
||||||
"function": "untag_nohardlinks",
|
"function": "untag_nohardlinks",
|
||||||
|
@ -638,7 +644,7 @@ class Qbt:
|
||||||
"body": "\n".join(body),
|
"body": "\n".join(body),
|
||||||
"torrent_name": torrent.name,
|
"torrent_name": torrent.name,
|
||||||
"torrent_category": torrent.category,
|
"torrent_category": torrent.category,
|
||||||
"torrent_tag": "noHL",
|
"torrent_tag": self.config.nohardlinks_tag,
|
||||||
"torrent_tracker": tracker["url"],
|
"torrent_tracker": tracker["url"],
|
||||||
"notifiarr_indexer": tracker["notifiarr"],
|
"notifiarr_indexer": tracker["notifiarr"],
|
||||||
"torrent_max_ratio": restore_max_ratio,
|
"torrent_max_ratio": restore_max_ratio,
|
||||||
|
@ -652,7 +658,7 @@ class Qbt:
|
||||||
for torrent in torrent_list:
|
for torrent in torrent_list:
|
||||||
t_name = torrent.name
|
t_name = torrent.name
|
||||||
t_hash = torrent.hash
|
t_hash = torrent.hash
|
||||||
if t_hash in tdel_dict and "noHL" in torrent.tags:
|
if t_hash in tdel_dict and self.config.nohardlinks_tag in torrent.tags:
|
||||||
t_count = self.torrentinfo[t_name]["count"]
|
t_count = self.torrentinfo[t_name]["count"]
|
||||||
t_msg = self.torrentinfo[t_name]["msg"]
|
t_msg = self.torrentinfo[t_name]["msg"]
|
||||||
t_status = self.torrentinfo[t_name]["status"]
|
t_status = self.torrentinfo[t_name]["status"]
|
||||||
|
@ -718,7 +724,8 @@ class Qbt:
|
||||||
logger.print_line("No torrents to tag with no hardlinks.", self.config.loglevel)
|
logger.print_line("No torrents to tag with no hardlinks.", self.config.loglevel)
|
||||||
if num_untag >= 1:
|
if num_untag >= 1:
|
||||||
logger.print_line(
|
logger.print_line(
|
||||||
f"{'Did not delete' if self.config.dry_run else 'Deleted'} noHL tags / share limits for {num_untag} "
|
f"{'Did not delete' if self.config.dry_run else 'Deleted'} "
|
||||||
|
f"{self.config.nohardlinks_tag} tags / share limits for {num_untag} "
|
||||||
f".torrent{'s.' if num_untag > 1 else '.'}",
|
f".torrent{'s.' if num_untag > 1 else '.'}",
|
||||||
self.config.loglevel,
|
self.config.loglevel,
|
||||||
)
|
)
|
||||||
|
@ -743,7 +750,7 @@ class Qbt:
|
||||||
num_tor_error = 0
|
num_tor_error = 0
|
||||||
num_untag = 0
|
num_untag = 0
|
||||||
tor_error_summary = ""
|
tor_error_summary = ""
|
||||||
tag_error = self.config.settings["tracker_error_tag"]
|
tag_error = self.config.tracker_error_tag
|
||||||
cfg_rem_unregistered = self.config.commands["rem_unregistered"]
|
cfg_rem_unregistered = self.config.commands["rem_unregistered"]
|
||||||
cfg_tag_error = self.config.commands["tag_tracker_error"]
|
cfg_tag_error = self.config.commands["tag_tracker_error"]
|
||||||
|
|
||||||
|
|
|
@ -434,9 +434,9 @@ def start():
|
||||||
if stats["rem_unreg"] > 0:
|
if stats["rem_unreg"] > 0:
|
||||||
stats_summary.append(f"Total Unregistered Torrents Removed: {stats['rem_unreg']}")
|
stats_summary.append(f"Total Unregistered Torrents Removed: {stats['rem_unreg']}")
|
||||||
if stats["tagged_tracker_error"] > 0:
|
if stats["tagged_tracker_error"] > 0:
|
||||||
stats_summary.append(f"Total {cfg.settings['tracker_error_tag']} Torrents Tagged: {stats['tagged_tracker_error']}")
|
stats_summary.append(f"Total {cfg.tracker_error_tag} Torrents Tagged: {stats['tagged_tracker_error']}")
|
||||||
if stats["untagged_tracker_error"] > 0:
|
if stats["untagged_tracker_error"] > 0:
|
||||||
stats_summary.append(f"Total {cfg.settings['tracker_error_tag']} Torrents untagged: {stats['untagged_tracker_error']}")
|
stats_summary.append(f"Total {cfg.tracker_error_tag} Torrents untagged: {stats['untagged_tracker_error']}")
|
||||||
if stats["added"] > 0:
|
if stats["added"] > 0:
|
||||||
stats_summary.append(f"Total Torrents Added: {stats['added']}")
|
stats_summary.append(f"Total Torrents Added: {stats['added']}")
|
||||||
if stats["resumed"] > 0:
|
if stats["resumed"] > 0:
|
||||||
|
@ -450,9 +450,9 @@ def start():
|
||||||
if stats["orphaned"] > 0:
|
if stats["orphaned"] > 0:
|
||||||
stats_summary.append(f"Total Orphaned Files: {stats['orphaned']}")
|
stats_summary.append(f"Total Orphaned Files: {stats['orphaned']}")
|
||||||
if stats["tagged_noHL"] > 0:
|
if stats["tagged_noHL"] > 0:
|
||||||
stats_summary.append(f"Total noHL Torrents Tagged: {stats['tagged_noHL']}")
|
stats_summary.append(f"Total {cfg.nohardlinks_tag} Torrents Tagged: {stats['tagged_noHL']}")
|
||||||
if stats["untagged_noHL"] > 0:
|
if stats["untagged_noHL"] > 0:
|
||||||
stats_summary.append(f"Total noHL Torrents untagged: {stats['untagged_noHL']}")
|
stats_summary.append(f"Total {cfg.nohardlinks_tag} Torrents untagged: {stats['untagged_noHL']}")
|
||||||
if stats["recycle_emptied"] > 0:
|
if stats["recycle_emptied"] > 0:
|
||||||
stats_summary.append(f"Total Files Deleted from Recycle Bin: {stats['recycle_emptied']}")
|
stats_summary.append(f"Total Files Deleted from Recycle Bin: {stats['recycle_emptied']}")
|
||||||
if stats["orphaned_emptied"] > 0:
|
if stats["orphaned_emptied"] > 0:
|
||||||
|
|
Loading…
Add table
Reference in a new issue