mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2024-09-20 15:26:02 +08:00
updates tags to use group notifications
This commit is contained in:
parent
b5384dc915
commit
e936e4526f
|
@ -45,7 +45,7 @@ class ShareLimits:
|
|||
"title": f"Updating Share Limits for {group_name}. Priority {group_config['priority']}",
|
||||
"body": f"Updated {len(self.torrents_updated)} torrents.",
|
||||
"grouping": group_name,
|
||||
"torrent_list": self.torrents_updated,
|
||||
"torrents": self.torrents_updated,
|
||||
"torrent_tag": self.group_tag,
|
||||
"torrent_max_ratio": group_config["max_ratio"],
|
||||
"torrent_max_seeding_time": group_config["max_seeding_time"],
|
||||
|
@ -88,9 +88,9 @@ class ShareLimits:
|
|||
"function": "cleanup_share_limits",
|
||||
"title": "Share limit removal",
|
||||
"grouping": group_name,
|
||||
"torrent_name": t_name,
|
||||
"torrents": [t_name],
|
||||
"torrent_category": torrent.category,
|
||||
"cleanup": "True",
|
||||
"cleanup": True,
|
||||
"torrent_tracker": tracker["url"],
|
||||
"notifiarr_indexer": tracker["notifiarr"],
|
||||
}
|
||||
|
@ -135,8 +135,11 @@ class ShareLimits:
|
|||
"title": "Share limit removal - Deleted .torrent but NOT content files.",
|
||||
"body": f"Deleted {self.stats_deleted} .torrents but NOT content files.",
|
||||
"grouping": group_name,
|
||||
"torrent_list": list(t_deleted),
|
||||
"torrents": list(t_deleted),
|
||||
"torrent_category": None,
|
||||
"cleanup": True,
|
||||
"torrent_tracker": None,
|
||||
"notifiarr_indexer": None,
|
||||
"torrents_deleted_and_contents": False,
|
||||
}
|
||||
self.config.send_notifications(attr)
|
||||
|
@ -146,8 +149,11 @@ class ShareLimits:
|
|||
"title": "Share limit removal - Deleted .torrent AND content files.",
|
||||
"body": f"Deleted {self.stats_deleted_contents} .torrents AND content files.",
|
||||
"grouping": group_name,
|
||||
"torrent_list": list(t_deleted_and_contents),
|
||||
"torrents": list(t_deleted_and_contents),
|
||||
"torrent_category": None,
|
||||
"cleanup": True,
|
||||
"torrent_tracker": None,
|
||||
"notifiarr_indexer": None,
|
||||
"torrents_deleted_and_contents": True,
|
||||
}
|
||||
self.config.send_notifications(attr)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from modules import util
|
||||
from modules.webhooks import GROUP_NOTIFICATION_LIMIT
|
||||
|
||||
logger = util.logger
|
||||
|
||||
|
@ -10,8 +11,10 @@ class Tags:
|
|||
self.client = qbit_manager.client
|
||||
self.stats = 0
|
||||
self.share_limits_suffix_tag = qbit_manager.config.share_limits_suffix_tag # suffix tag for share limits
|
||||
|
||||
self.torrents_updated = [] # List of torrents updated
|
||||
self.notify_attr = [] # List of single torrent attributes to send to notifiarr
|
||||
self.tags()
|
||||
self.notify()
|
||||
|
||||
def tags(self):
|
||||
"""Update tags for torrents"""
|
||||
|
@ -23,9 +26,10 @@ class Tags:
|
|||
if torrent.tags == "" or (len([trk for trk in check_tags if trk not in ignore_tags]) == 0):
|
||||
tracker = self.qbt.get_tags(torrent.trackers)
|
||||
if tracker["tag"]:
|
||||
t_name = torrent.name
|
||||
self.stats += len(tracker["tag"])
|
||||
body = []
|
||||
body += logger.print_line(logger.insert_space(f"Torrent Name: {torrent.name}", 3), self.config.loglevel)
|
||||
body += logger.print_line(logger.insert_space(f"Torrent Name: {t_name}", 3), self.config.loglevel)
|
||||
body += logger.print_line(
|
||||
logger.insert_space(f'New Tag{"s" if len(tracker["tag"]) > 1 else ""}: {", ".join(tracker["tag"])}', 8),
|
||||
self.config.loglevel,
|
||||
|
@ -38,16 +42,58 @@ class Tags:
|
|||
"function": "tag_update",
|
||||
"title": "Updating Tags",
|
||||
"body": "\n".join(body),
|
||||
"torrent_name": torrent.name,
|
||||
"torrents": [t_name],
|
||||
"torrent_category": category,
|
||||
"torrent_tag": ", ".join(tracker["tag"]),
|
||||
"torrent_tracker": tracker["url"],
|
||||
"notifiarr_indexer": tracker["notifiarr"],
|
||||
}
|
||||
self.config.send_notifications(attr)
|
||||
self.notify_attr.append(attr)
|
||||
self.torrents_updated.append(t_name)
|
||||
if self.stats >= 1:
|
||||
logger.print_line(
|
||||
f"{'Did not update' if self.config.dry_run else 'Updated'} {self.stats} new tags.", self.config.loglevel
|
||||
)
|
||||
else:
|
||||
logger.print_line("No new torrents to tag.", self.config.loglevel)
|
||||
|
||||
def notify(self):
|
||||
"""Send notifications"""
|
||||
|
||||
def group_notifications_by_tag(self):
|
||||
group_attr = {}
|
||||
"""Group notifications by tag"""
|
||||
for attr in self.notify_attr:
|
||||
tag = attr["torrent_tag"]
|
||||
if tag not in group_attr:
|
||||
group_attr[tag] = {
|
||||
"torrent_tag": tag,
|
||||
"torrents": [attr["torrents"][0]],
|
||||
"torrent_tracker": attr["torrent_tracker"],
|
||||
"notifiarr_indexer": attr["notifiarr_indexer"],
|
||||
}
|
||||
else:
|
||||
group_attr[tag]["torrents"].append(attr["torrents"][0])
|
||||
return group_attr
|
||||
|
||||
if len(self.torrents_updated) > GROUP_NOTIFICATION_LIMIT:
|
||||
logger.trace(
|
||||
f"Number of tags > {GROUP_NOTIFICATION_LIMIT}, grouping notifications by tag.",
|
||||
)
|
||||
group_attr = group_notifications_by_tag(self)
|
||||
for tag in group_attr:
|
||||
attr = {
|
||||
"function": "tag_update",
|
||||
"title": f"Updating Tags for {tag}",
|
||||
"body": f"Updated {len(group_attr[tag]['torrents'])} "
|
||||
f"{'torrents' if len(group_attr[tag]['torrents']) > 1 else 'torrent'} with tag '{tag}'",
|
||||
"torrents": group_attr[tag]["torrents"],
|
||||
"torrent_category": None,
|
||||
"torrent_tag": tag,
|
||||
"torrent_tracker": group_attr[tag]["torrent_tracker"],
|
||||
"notifiarr_indexer": group_attr[tag]["notifiarr_indexer"],
|
||||
}
|
||||
self.config.send_notifications(attr)
|
||||
else:
|
||||
for attr in self.notify_attr:
|
||||
self.config.send_notifications(attr)
|
||||
|
|
Loading…
Reference in a new issue