mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-09-13 08:34:51 +08:00
refactor recheck
This commit is contained in:
parent
f0b3ecd4e9
commit
3c1410f8af
3 changed files with 120 additions and 105 deletions
115
modules/core/recheck.py
Normal file
115
modules/core/recheck.py
Normal file
|
@ -0,0 +1,115 @@
|
|||
from datetime import timedelta
|
||||
|
||||
from modules import util
|
||||
|
||||
logger = util.logger
|
||||
|
||||
|
||||
class ReCheck:
|
||||
def __init__(self, qbit_manager):
|
||||
self.qbt = qbit_manager
|
||||
self.config = qbit_manager.config
|
||||
self.client = qbit_manager.client
|
||||
self.stats_resumed = 0
|
||||
self.stats_rechecked = 0
|
||||
|
||||
self.recheck()
|
||||
|
||||
def recheck(self):
|
||||
"""Function used to recheck paused torrents sorted by size and resume torrents that are completed"""
|
||||
if self.config.commands["recheck"]:
|
||||
logger.separator("Rechecking Paused Torrents", space=False, border=False)
|
||||
# sort by size and paused
|
||||
torrent_list = self.qbt.get_torrents({"status_filter": "paused", "sort": "size"})
|
||||
if torrent_list:
|
||||
for torrent in torrent_list:
|
||||
tracker = self.qbt.get_tags(torrent.trackers)
|
||||
# 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}",
|
||||
self.config.loglevel,
|
||||
)
|
||||
attr = {
|
||||
"function": "recheck",
|
||||
"title": "Resuming Torrent",
|
||||
"body": body,
|
||||
"torrent_name": torrent.name,
|
||||
"torrent_category": torrent.category,
|
||||
"torrent_tracker": tracker["url"],
|
||||
"notifiarr_indexer": tracker["notifiarr"],
|
||||
}
|
||||
self.config.send_notifications(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"-- Ratio vs Max Ratio: {torrent.ratio:.2f} < {torrent.max_ratio:.2f}", 4)
|
||||
)
|
||||
logger.debug(
|
||||
logger.insert_space(
|
||||
f"-- Seeding Time vs Max Seed Time: {timedelta(seconds=torrent.seeding_time)} < "
|
||||
f"{timedelta(minutes=torrent.max_seeding_time)}",
|
||||
4,
|
||||
)
|
||||
)
|
||||
if (
|
||||
(torrent.max_ratio >= 0 and torrent.ratio < torrent.max_ratio and torrent.max_seeding_time < 0)
|
||||
or (
|
||||
torrent.max_seeding_time >= 0
|
||||
and (torrent.seeding_time < (torrent.max_seeding_time * 60))
|
||||
and torrent.max_ratio < 0
|
||||
)
|
||||
or (
|
||||
torrent.max_ratio >= 0
|
||||
and torrent.max_seeding_time >= 0
|
||||
and torrent.ratio < torrent.max_ratio
|
||||
and (torrent.seeding_time < (torrent.max_seeding_time * 60))
|
||||
)
|
||||
):
|
||||
self.stats_resumed += 1
|
||||
body = logger.print_line(
|
||||
f"{'Not Resuming' if self.config.dry_run else 'Resuming'} [{tracker['tag']}] - "
|
||||
f"{torrent.name}",
|
||||
self.config.loglevel,
|
||||
)
|
||||
attr = {
|
||||
"function": "recheck",
|
||||
"title": "Resuming Torrent",
|
||||
"body": body,
|
||||
"torrent_name": torrent.name,
|
||||
"torrent_category": torrent.category,
|
||||
"torrent_tracker": tracker["url"],
|
||||
"notifiarr_indexer": tracker["notifiarr"],
|
||||
}
|
||||
self.config.send_notifications(attr)
|
||||
if not self.config.dry_run:
|
||||
torrent.resume()
|
||||
# Recheck
|
||||
elif (
|
||||
torrent.progress == 0
|
||||
and self.qbt.torrentinfo[torrent.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}",
|
||||
self.config.loglevel,
|
||||
)
|
||||
attr = {
|
||||
"function": "recheck",
|
||||
"title": "Rechecking Torrent",
|
||||
"body": body,
|
||||
"torrent_name": torrent.name,
|
||||
"torrent_category": torrent.category,
|
||||
"torrent_tracker": tracker["url"],
|
||||
"notifiarr_indexer": tracker["notifiarr"],
|
||||
}
|
||||
self.config.send_notifications(attr)
|
||||
if not self.config.dry_run:
|
||||
torrent.recheck()
|
|
@ -849,108 +849,6 @@ class Qbt:
|
|||
)
|
||||
return num_tags, num_untag, del_tor, del_tor_cont
|
||||
|
||||
def recheck(self):
|
||||
"""Function used to recheck paused torrents sorted by size and resume torrents that are completed"""
|
||||
resumed = 0
|
||||
rechecked = 0
|
||||
if self.config.commands["recheck"]:
|
||||
logger.separator("Rechecking Paused Torrents", space=False, border=False)
|
||||
# sort by size and paused
|
||||
torrent_list = self.get_torrents({"status_filter": "paused", "sort": "size"})
|
||||
if torrent_list:
|
||||
for torrent in torrent_list:
|
||||
tracker = self.get_tags(torrent.trackers)
|
||||
# Resume torrent if completed
|
||||
if torrent.progress == 1:
|
||||
if torrent.max_ratio < 0 and torrent.max_seeding_time < 0:
|
||||
resumed += 1
|
||||
body = logger.print_line(
|
||||
f"{'Not Resuming' if self.config.dry_run else 'Resuming'} [{tracker['tag']}] - {torrent.name}",
|
||||
self.config.loglevel,
|
||||
)
|
||||
attr = {
|
||||
"function": "recheck",
|
||||
"title": "Resuming Torrent",
|
||||
"body": body,
|
||||
"torrent_name": torrent.name,
|
||||
"torrent_category": torrent.category,
|
||||
"torrent_tracker": tracker["url"],
|
||||
"notifiarr_indexer": tracker["notifiarr"],
|
||||
}
|
||||
self.config.send_notifications(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"-- Ratio vs Max Ratio: {torrent.ratio:.2f} < {torrent.max_ratio:.2f}", 4)
|
||||
)
|
||||
logger.debug(
|
||||
logger.insert_space(
|
||||
f"-- Seeding Time vs Max Seed Time: {timedelta(seconds=torrent.seeding_time)} < "
|
||||
f"{timedelta(minutes=torrent.max_seeding_time)}",
|
||||
4,
|
||||
)
|
||||
)
|
||||
if (
|
||||
(torrent.max_ratio >= 0 and torrent.ratio < torrent.max_ratio and torrent.max_seeding_time < 0)
|
||||
or (
|
||||
torrent.max_seeding_time >= 0
|
||||
and (torrent.seeding_time < (torrent.max_seeding_time * 60))
|
||||
and torrent.max_ratio < 0
|
||||
)
|
||||
or (
|
||||
torrent.max_ratio >= 0
|
||||
and torrent.max_seeding_time >= 0
|
||||
and torrent.ratio < torrent.max_ratio
|
||||
and (torrent.seeding_time < (torrent.max_seeding_time * 60))
|
||||
)
|
||||
):
|
||||
resumed += 1
|
||||
body = logger.print_line(
|
||||
f"{'Not Resuming' if self.config.dry_run else 'Resuming'} [{tracker['tag']}] - "
|
||||
f"{torrent.name}",
|
||||
self.config.loglevel,
|
||||
)
|
||||
attr = {
|
||||
"function": "recheck",
|
||||
"title": "Resuming Torrent",
|
||||
"body": body,
|
||||
"torrent_name": torrent.name,
|
||||
"torrent_category": torrent.category,
|
||||
"torrent_tracker": tracker["url"],
|
||||
"notifiarr_indexer": tracker["notifiarr"],
|
||||
}
|
||||
self.config.send_notifications(attr)
|
||||
if not self.config.dry_run:
|
||||
torrent.resume()
|
||||
# Recheck
|
||||
elif (
|
||||
torrent.progress == 0
|
||||
and self.torrentinfo[torrent.name]["is_complete"]
|
||||
and not torrent.state_enum.is_checking
|
||||
):
|
||||
rechecked += 1
|
||||
body = logger.print_line(
|
||||
f"{'Not Rechecking' if self.config.dry_run else 'Rechecking'} [{tracker['tag']}] - {torrent.name}",
|
||||
self.config.loglevel,
|
||||
)
|
||||
attr = {
|
||||
"function": "recheck",
|
||||
"title": "Rechecking Torrent",
|
||||
"body": body,
|
||||
"torrent_name": torrent.name,
|
||||
"torrent_category": torrent.category,
|
||||
"torrent_tracker": tracker["url"],
|
||||
"notifiarr_indexer": tracker["notifiarr"],
|
||||
}
|
||||
self.config.send_notifications(attr)
|
||||
if not self.config.dry_run:
|
||||
torrent.recheck()
|
||||
return resumed, rechecked
|
||||
|
||||
def rem_orphaned(self):
|
||||
"""Remove orphaned files from remote directory"""
|
||||
orphaned = 0
|
||||
|
|
|
@ -291,6 +291,7 @@ from modules.core.category import Category # noqa
|
|||
from modules.core.tags import Tags # noqa
|
||||
from modules.core.remove_unregistered import RemoveUnregistered # noqa
|
||||
from modules.core.cross_seed import CrossSeed # noqa
|
||||
from modules.core.recheck import ReCheck # noqa
|
||||
|
||||
|
||||
def my_except_hook(exctype, value, tbi):
|
||||
|
@ -411,9 +412,10 @@ def start():
|
|||
stats["tagged"] += cross_seed.stats_tagged
|
||||
|
||||
# Recheck Torrents
|
||||
num_resumed, num_rechecked = cfg.qbt.recheck()
|
||||
stats["resumed"] += num_resumed
|
||||
stats["rechecked"] += num_rechecked
|
||||
if cfg.commands["recheck"]:
|
||||
recheck = ReCheck(qbit_manager)
|
||||
stats["resumed"] += recheck.stats_resumed
|
||||
stats["rechecked"] += recheck.stats_rechecked
|
||||
|
||||
# Tag NoHardLinks
|
||||
num_tagged, num_untagged, num_deleted, num_deleted_contents = cfg.qbt.tag_nohardlinks()
|
||||
|
|
Loading…
Add table
Reference in a new issue