Skip to content

Commit

Permalink
Updated blocklisting for stalled torrents, and added config for auto …
Browse files Browse the repository at this point in the history
…pause resume
  • Loading branch information
Feramance committed Jul 2, 2024
1 parent 7d9f817 commit cce9304
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
5 changes: 4 additions & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"

Expand Down
16 changes: 13 additions & 3 deletions qBitrr/arss.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from qBitrr.config import (
APPDATA_FOLDER,
AUTO_PAUSE_RESUME,
COMPLETED_DOWNLOAD_FOLDER,
CONFIG,
ENABLE_LOGS,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions qBitrr/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"]
)
Expand Down
1 change: 1 addition & 0 deletions qBitrr/env_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion qBitrr/gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion qBitrr/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit cce9304

Please sign in to comment.