mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2024-09-20 07:16:04 +08:00
adds recheck to use group notifications
This commit is contained in:
parent
29751d1809
commit
f56c1e3220
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue