From f56c1e3220d85313fec34fff1db7b204661d7196 Mon Sep 17 00:00:00 2001 From: bobokun Date: Sun, 4 Jun 2023 15:13:31 -0400 Subject: [PATCH] adds recheck to use group notifications --- VERSION | 2 +- modules/core/recheck.py | 44 +++++++++++++++++++++++++++-------------- modules/webhooks.py | 7 +++++++ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/VERSION b/VERSION index 19cf398..72f4c65 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.0-develop11 +4.0.0-develop12 diff --git a/modules/core/recheck.py b/modules/core/recheck.py index acefeb1..2ac7032 100644 --- a/modules/core/recheck.py +++ b/modules/core/recheck.py @@ -13,7 +13,14 @@ class ReCheck: self.stats_resumed = 0 self.stats_rechecked = 0 + self.torrents_updated_recheck = [] # List of torrents updated + self.notify_attr_recheck = [] # List of single torrent attributes to send to notifiarr + self.torrents_updated_resume = [] # List of torrents updated + self.notify_attr_resume = [] # List of single torrent attributes to send to notifiarr + self.recheck() + self.config.webhooks_factory.notify(self.torrents_updated_resume, self.notify_attr_resume, group_by="tag") + self.config.webhooks_factory.notify(self.torrents_updated_recheck, self.notify_attr_recheck, group_by="tag") def recheck(self): """Function used to recheck paused torrents sorted by size and resume torrents that are completed""" @@ -24,30 +31,34 @@ class ReCheck: if torrent_list: for torrent in torrent_list: tracker = self.qbt.get_tags(torrent.trackers) + t_name = torrent.name + t_category = torrent.category # Resume torrent if completed if torrent.progress == 1: if torrent.max_ratio < 0 and torrent.max_seeding_time < 0: self.stats_resumed += 1 body = logger.print_line( - f"{'Not Resuming' if self.config.dry_run else 'Resuming'} [{tracker['tag']}] - {torrent.name}", + f"{'Not Resuming' if self.config.dry_run else 'Resuming'} [{tracker['tag']}] - {t_name}", self.config.loglevel, ) attr = { "function": "recheck", "title": "Resuming Torrent", "body": body, - "torrents": [torrent.name], - "torrent_category": torrent.category, + "torrents": [t_name], + "torrent_tag": tracker["tag"], + "torrent_category": t_category, "torrent_tracker": tracker["url"], "notifiarr_indexer": tracker["notifiarr"], } - self.config.send_notifications(attr) + self.torrents_updated_resume.append(t_name) + self.notify_attr_resume.append(attr) if not self.config.dry_run: torrent.resume() else: # Check to see if torrent meets AutoTorrentManagement criteria logger.debug("DEBUG: Torrent to see if torrent meets AutoTorrentManagement Criteria") - logger.debug(logger.insert_space(f"- Torrent Name: {torrent.name}", 2)) + logger.debug(logger.insert_space(f"- Torrent Name: {t_name}", 2)) logger.debug( logger.insert_space(f"-- Ratio vs Max Ratio: {torrent.ratio:.2f} < {torrent.max_ratio:.2f}", 4) ) @@ -74,42 +85,45 @@ class ReCheck: ): self.stats_resumed += 1 body = logger.print_line( - f"{'Not Resuming' if self.config.dry_run else 'Resuming'} [{tracker['tag']}] - " - f"{torrent.name}", + f"{'Not Resuming' if self.config.dry_run else 'Resuming'} [{tracker['tag']}] - " f"{t_name}", self.config.loglevel, ) attr = { "function": "recheck", "title": "Resuming Torrent", "body": body, - "torrents": [torrent.name], - "torrent_category": torrent.category, + "torrents": [t_name], + "torrent_tag": tracker["tag"], + "torrent_category": t_category, "torrent_tracker": tracker["url"], "notifiarr_indexer": tracker["notifiarr"], } - self.config.send_notifications(attr) + self.torrents_updated_resume.append(t_name) + self.notify_attr_resume.append(attr) if not self.config.dry_run: torrent.resume() # Recheck elif ( torrent.progress == 0 - and self.qbt.torrentinfo[torrent.name]["is_complete"] + and self.qbt.torrentinfo[t_name]["is_complete"] and not torrent.state_enum.is_checking ): self.stats_rechecked += 1 body = logger.print_line( - f"{'Not Rechecking' if self.config.dry_run else 'Rechecking'} [{tracker['tag']}] - {torrent.name}", + f"{'Not Rechecking' if self.config.dry_run else 'Rechecking'} [{tracker['tag']}] - {t_name}", self.config.loglevel, ) attr = { "function": "recheck", "title": "Rechecking Torrent", "body": body, - "torrents": [torrent.name], - "torrent_category": torrent.category, + "torrents": [t_name], + "torrent_tag": tracker["tag"], + "torrent_category": t_category, "torrent_tracker": tracker["url"], "notifiarr_indexer": tracker["notifiarr"], } - self.config.send_notifications(attr) + self.torrents_updated_recheck.append(t_name) + self.notify_attr_recheck.append(attr) if not self.config.dry_run: torrent.recheck() diff --git a/modules/webhooks.py b/modules/webhooks.py index 2e43f4a..984dd26 100755 --- a/modules/webhooks.py +++ b/modules/webhooks.py @@ -178,6 +178,8 @@ class Webhooks: group_attr = group_notifications_by_key(payload, "torrent_category") elif group_by == "tag": group_attr = group_notifications_by_key(payload, "torrent_tag") + elif group_by == "tracker": + group_attr = group_notifications_by_key(payload, "torrent_tracker") # group notifications by grouping attribute for group in group_attr: @@ -203,6 +205,11 @@ class Webhooks: attr["torrent_category"] = group_attr[group].get("torrent_category") if only_one_torrent_updated else None attr["torrent_tracker"] = group_attr[group].get("torrent_tracker") attr["notifiarr_indexer"] = group_attr[group].get("notifiarr_indexer") + elif group_by == "tracker": + attr["torrent_tracker"] = group + attr["torrent_category"] = group_attr[group].get("torrent_category") if only_one_torrent_updated else None + attr["torrent_tag"] = group_attr[group].get("torrent_tag") if only_one_torrent_updated else None + attr["notifiarr_indexer"] = group_attr[group].get("notifiarr_indexer") for extra_attr in payload: if extra_attr not in attr: