From cce9304104843bbf0cfa442a0ad5ecb4ab9004f6 Mon Sep 17 00:00:00 2001 From: Feramance Date: Tue, 2 Jul 2024 09:02:16 +0200 Subject: [PATCH] Updated blocklisting for stalled torrents, and added config for auto pause resume --- config.example.toml | 5 ++++- qBitrr/arss.py | 16 +++++++++++++--- qBitrr/config.py | 9 +++++++-- qBitrr/env_config.py | 1 + qBitrr/gen_config.py | 8 +++++++- qBitrr/logger.py | 6 +++++- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/config.example.toml b/config.example.toml index 8a49714a..efb87ac0 100644 --- a/config.example.toml +++ b/config.example.toml @@ -12,7 +12,7 @@ Logging = true # Folder where your completed downloads are put into. Can be found in qBitTorrent -> Options -> Downloads -> Default Save Path (Please note, replace all '\' with '/') CompletedDownloadFolder = "CHANGE_ME" -#The desired amount of free space in the downloads directory [K=kilobytes, M=megabytes, G=gigabytes, T=terabytes] (set to -1 to disable) +#The desired amount of free space in the downloads directory [K=kilobytes, M=megabytes, G=gigabytes, T=terabytes] (set to -1 to disable, this bypasses AutoPauseResume) FreeSpace = "-1" # Time to sleep for if there is no internet (in seconds: 600 = 10 Minutes) @@ -24,6 +24,9 @@ LoopSleepTimer = 5 # Time to sleep between posting search commands (in seconds: 600 = 10 Minutes) SearchLoopDelay = -1 +# Enable automation of pausing and resuming torrents as needed +AutoPauseResume = true + # Add torrents to this category to mark them as failed FailedCategory = "failed" diff --git a/qBitrr/arss.py b/qBitrr/arss.py index 9b26ff37..9a512905 100755 --- a/qBitrr/arss.py +++ b/qBitrr/arss.py @@ -28,6 +28,7 @@ from qBitrr.config import ( APPDATA_FOLDER, + AUTO_PAUSE_RESUME, COMPLETED_DOWNLOAD_FOLDER, CONFIG, ENABLE_LOGS, @@ -759,7 +760,7 @@ def _process_ombi_requests(self) -> dict[str, set[str, int]]: def _process_paused(self) -> None: # Bulks pause all torrents flagged for pausing. - if self.pause: + if self.pause and AUTO_PAUSE_RESUME: self.needs_cleanup = True self.logger.debug("Pausing %s torrents", len(self.pause)) for i in self.pause: @@ -861,6 +862,16 @@ def _process_failed_individual( self.delete_from_queue(id_=entry, blacklist=True) else: self.delete_from_queue(id_=entry, blacklist=False) + else: + if hash_ not in skip_blacklist: + self.logger.debug( + "Blocklisting: %s (%s)", + hash_, + self.manager.qbit_manager.name_cache.get(hash_, "Blocklisted"), + ) + self.delete_from_queue(id_=entry, remove_from_client=False, blacklist=True) + else: + self.delete_from_queue(id_=entry, remove_from_client=False, blacklist=False) if hash_ in self.recently_queue: del self.recently_queue[hash_] object_id = self.requeue_cache.get(entry) @@ -1102,7 +1113,7 @@ def _process_file_priority(self) -> None: del self.change_priority[hash_] def _process_resume(self) -> None: - if self.resume: + if self.resume and AUTO_PAUSE_RESUME: self.needs_cleanup = True self.manager.qbit.torrents_resume(torrent_hashes=self.resume) for k in self.resume: @@ -3414,7 +3425,6 @@ def _process_single_torrent_fully_completed_torrent( torrent.name, torrent.hash, ) - # self.pause.add(torrent.hash) content_path = pathlib.Path(torrent.content_path) if content_path.is_dir() and content_path.name == torrent.name: torrent_folder = content_path diff --git a/qBitrr/config.py b/qBitrr/config.py index 5684de76..4df3d87d 100644 --- a/qBitrr/config.py +++ b/qBitrr/config.py @@ -117,9 +117,11 @@ def process_flags() -> argparse.Namespace | bool: "Settings.RecheckCategory", fallback="recheck" ) CONSOLE_LOGGING_LEVEL_STRING = ENVIRO_CONFIG.settings.console_level or CONFIG.get_or_raise( - "Settings.ConsoleLevel" + "Settings.ConsoleLevel", fallback="INFO" +) +ENABLE_LOGS = ENVIRO_CONFIG.settings.logging or CONFIG.get_or_raise( + "Settings.Logging", fallback=True ) -ENABLE_LOGS = ENVIRO_CONFIG.settings.logging or CONFIG.get_or_raise("Settings.Logging") COMPLETED_DOWNLOAD_FOLDER = ( ENVIRO_CONFIG.settings.completed_download_folder or CONFIG.get_or_raise("Settings.CompletedDownloadFolder") @@ -134,6 +136,9 @@ def process_flags() -> argparse.Namespace | bool: SEARCH_LOOP_DELAY = ENVIRO_CONFIG.settings.search_loop_delay or CONFIG.get( "Settings.SearchLoopDelay", fallback=-1 ) +AUTO_PAUSE_RESUME = ENVIRO_CONFIG.settings.auto_pause_resume or CONFIG.get_or_raise( + "Settings.AutoPauseResume", fallback=True +) PING_URLS = ENVIRO_CONFIG.settings.ping_urls or CONFIG.get( "Settings.PingURLS", fallback=["one.one.one.one", "dns.google.com"] ) diff --git a/qBitrr/env_config.py b/qBitrr/env_config.py index 9b35e0cd..98c52805 100644 --- a/qBitrr/env_config.py +++ b/qBitrr/env_config.py @@ -35,6 +35,7 @@ class Settings: no_internet_sleep_timer = environ.var(None, converter=Converter.int) loop_sleep_timer = environ.var(None, converter=Converter.int) search_loop_delay = environ.var(None, converter=Converter.int) + auto_pause_resume = environ.var(None, converter=Converter.bool) failed_category = environ.var(None) recheck_category = environ.var(None) ignore_torrents_younger_than = environ.var(None, converter=Converter.int) diff --git a/qBitrr/gen_config.py b/qBitrr/gen_config.py index d393259c..e903cdb1 100755 --- a/qBitrr/gen_config.py +++ b/qBitrr/gen_config.py @@ -52,7 +52,7 @@ def _add_settings_section(config: TOMLDocument): ) _gen_default_line( settings, - "The desired amount of free space in the downloads directory [K=kilobytes, M=megabytes, G=gigabytes, T=terabytes] (set to -1 to disable)", + "The desired amount of free space in the downloads directory [K=kilobytes, M=megabytes, G=gigabytes, T=terabytes] (set to -1 to disable, this bypasses AutoPauseResume)", "FreeSpace", ENVIRO_CONFIG.settings.free_space or "-1", ) @@ -74,6 +74,12 @@ def _add_settings_section(config: TOMLDocument): "SearchLoopDelay", ENVIRO_CONFIG.settings.search_loop_delay or -1, ) + _gen_default_line( + settings, + "Enable automation of pausing and resuming torrents as needed", + "AutoPauseResume", + ENVIRO_CONFIG.settings.auto_pause_resume or True, + ) _gen_default_line( settings, "Add torrents to this category to mark them as failed", diff --git a/qBitrr/logger.py b/qBitrr/logger.py index c94f232c..4bcdcc24 100644 --- a/qBitrr/logger.py +++ b/qBitrr/logger.py @@ -7,10 +7,12 @@ import coloredlogs from qBitrr.config import ( + AUTO_PAUSE_RESUME, COMPLETED_DOWNLOAD_FOLDER, CONFIG, CONSOLE_LOGGING_LEVEL_STRING, COPIED_TO_NEW_DIR, + ENABLE_LOGS, FAILED_CATEGORY, FREE_SPACE, HOME_PATH, @@ -123,12 +125,14 @@ def run_logs(logger: Logger) -> None: def log_Debugs(logger): logger.debug("Log Level: %s", CONSOLE_LOGGING_LEVEL_STRING) logger.debug("Ping URLs: %s", PING_URLS) + logger.debug("Script Config: Logging=%s", ENABLE_LOGS) logger.debug("Script Config: FailedCategory=%s", FAILED_CATEGORY) logger.debug("Script Config: RecheckCategory=%s", RECHECK_CATEGORY) logger.debug("Script Config: CompletedDownloadFolder=%s", COMPLETED_DOWNLOAD_FOLDER) logger.debug("Script Config: FreeSpace=%s", FREE_SPACE) logger.debug("Script Config: LoopSleepTimer=%s", LOOP_SLEEP_TIMER) - logger.debug("Script Config: LoopSleepTimer=%s", SEARCH_LOOP_DELAY) + logger.debug("Script Config: SearchLoopDelay=%s", SEARCH_LOOP_DELAY) + logger.debug("Script Config: AutoPauseResume=%s", AUTO_PAUSE_RESUME) logger.debug( "Script Config: NoInternetSleepTimer=%s", NO_INTERNET_SLEEP_TIMER,