From 69d868860c7de89d2cfe3af3b3b83b20c5d24e2a Mon Sep 17 00:00:00 2001 From: Pukabyte <120460627+Pukabyte@users.noreply.github.com> Date: Sat, 14 Dec 2024 16:05:15 +1300 Subject: [PATCH 1/2] Update import_torrent_folder.py - interactive style --- import_torrent_folder.py | 111 +++++++++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 15 deletions(-) diff --git a/import_torrent_folder.py b/import_torrent_folder.py index a882296..72352e2 100644 --- a/import_torrent_folder.py +++ b/import_torrent_folder.py @@ -1,19 +1,44 @@ import os import re +import time import argparse from shared.shared import blackhole, realdebrid parentDirectory = realdebrid['mountTorrentsPath'] -def get_completed_parent_directory(args): - if args.symlink_directory: - return args.symlink_directory - elif args.radarr: +def get_completed_parent_directory(use_radarr, use_radarr4k, use_radarranime, use_radarrmux, use_sonarr, use_sonarr4k, use_sonarranime, use_sonarrmux, custom_directory): + if custom_directory: + return custom_directory + elif use_radarr: return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']}/completed" - elif args.sonarr: + elif use_radarr4k: + return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']}4k/completed" + elif use_radarranime: + return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']}anime/completed" + elif use_radarrmux: + return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']}mux/completed" + elif use_sonarr: return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']}/completed" + elif use_sonarr4k: + return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']}4k/completed" + elif use_sonarranime: + return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']}anime/completed" + elif use_sonarrmux: + return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']}mux/completed" else: - return + return None + +def retry_find_directory(directory, max_retries=60, wait_time=1): + """Retry finding the directory every second for a total of 60 seconds, updating the status message.""" + print("Finding torrents", end="", flush=True) + for attempt in range(max_retries): + if os.path.isdir(directory): + print("\nDirectory found.") + return True + print(".", end="", flush=True) + time.sleep(wait_time) + print("\nFailed to find directory.") + return False def process_directory(directory, completedParentDirectory, custom_regex=None, dry_run=False): fullDirectory = os.path.join(parentDirectory, directory) @@ -27,6 +52,13 @@ def process_directory(directory, completedParentDirectory, custom_regex=None, dr multiSeasonMatch = re.search(multiSeasonRegexCombined, directory) + if not retry_find_directory(fullDirectory): + print(f"Failed to find directory: {fullDirectory} after 60 seconds.") + return + + # Print the message indicating the directory being processed + print(f"Symlinks sent to {completedParentDirectory.split('/')[-2]} for {directory}") + for root, dirs, files in os.walk(fullDirectory): relRoot = os.path.relpath(root, fullDirectory) for filename in files: @@ -47,14 +79,11 @@ def process_directory(directory, completedParentDirectory, custom_regex=None, dr if not dry_run: os.makedirs(os.path.join(completedSeasonFullDirectory, relRoot), exist_ok=True) os.symlink(os.path.join(root, filename), os.path.join(completedSeasonFullDirectory, relRoot, filename)) - print('Season Recursive:', f"{os.path.join(completedSeasonFullDirectory, relRoot, filename)} -> {os.path.join(root, filename)}") - continue if not dry_run: os.makedirs(os.path.join(completedFullDirectory, relRoot), exist_ok=True) os.symlink(os.path.join(root, filename), os.path.join(completedFullDirectory, relRoot, filename)) - print('Recursive:', f"{os.path.join(completedFullDirectory, relRoot, filename)} -> {os.path.join(root, filename)}") def process(directory, completedParentDirectory, custom_regex, dry_run=False, no_confirm=False): if directory: @@ -73,20 +102,72 @@ def process(directory, completedParentDirectory, custom_regex, dry_run=False, no else: print(f"Skipping processing of {directory}") -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser(description='Process directories for torrent imports.') parser.add_argument('--directory', type=str, help='Specific directory to process') parser.add_argument('--custom-regex', type=str, help='Custom multi-season regex') parser.add_argument('--dry-run', action='store_true', help='Print actions without executing') parser.add_argument('--no-confirm', action='store_true', help='Execute without confirmation') parser.add_argument('--radarr', action='store_true', help='Use the Radarr symlink directory') + parser.add_argument('--radarr4k', action='store_true', help='Use the Radarr4K symlink directory') + parser.add_argument('--radarranime', action='store_true', help='Use the RadarrAnime symlink directory') + parser.add_argument('--radarrmux', action='store_true', help='Use the Radarrmux symlink directory') parser.add_argument('--sonarr', action='store_true', help='Use the Sonarr symlink directory') + parser.add_argument('--sonarr4k', action='store_true', help='Use the Sonarr4K symlink directory') + parser.add_argument('--sonarranime', action='store_true', help='Use the SonarrAnime symlink directory') + parser.add_argument('--sonarrmux', action='store_true', help='Use the Sonarrmux symlink directory') parser.add_argument('--symlink-directory', type=str, help='Custom symlink directory') args = parser.parse_args() - completedParentDirectory = get_completed_parent_directory(args) - if not completedParentDirectory: - parser.error("One of --radarr, --sonarr, or --symlink-directory is required.") - - process(args.directory, completedParentDirectory, args.custom_regex, args.dry_run, args.no_confirm) + if args.directory or args.radarr or args.radarr4k or args.radarranime or args.radarrmux or args.sonarr or args.sonarr4k or args.sonarranime or args.sonarrmux or args.symlink_directory: + # Process once with the provided arguments and exit + completedParentDirectory = get_completed_parent_directory( + args.radarr, args.radarr4k, args.radarranime, args.radarrmux, + args.sonarr, args.sonarr4k, args.sonarranime, args.sonarrmux, + args.symlink_directory + ) + if not completedParentDirectory: + parser.error("One of --radarr, --radarr4k, --radarranime, --sonarr, --sonarr4k, --sonarranime, or --symlink-directory is required.") + + process(args.directory, completedParentDirectory, args.custom_regex, args.dry_run, args.no_confirm) + else: + # Enter interactive loop for continuous processing + while True: + directory = input("Enter the directory to process: ") + choice = input("Is this for Radarr, Radarr4K, RadarrAnime, Radarrmux, Sonarr, Sonarr4K, or SonarrAnime, Sonarrmux? (r/r4k/ra/rm/s/s4k/sa/sm): ").strip().lower() + + radarr, radarr4k, radarranime, radarrmux, sonarr, sonarr4k, sonarranime, sonarrmux = False, False, False, False, False, False, False, False + + if choice == 'r': + radarr = True + elif choice == 'r4k': + radarr4k = True + elif choice == 'ra': + radarranime = True + elif choice == 'rm': + radarrmux = True + elif choice == 's': + sonarr = True + elif choice == 's4k': + sonarr4k = True + elif choice == 'sa': + sonarranime = True + elif choice == 'sm': + sonarrmux == True + else: + print("Invalid choice. Please try again.") + continue + + completedParentDirectory = get_completed_parent_directory( + radarr, radarr4k, radarranime, radarrmux, + sonarr, sonarr4k, sonarranime, sonarrmux, + None + ) + if not completedParentDirectory: + print("Invalid directory configuration. Please try again.") + continue + + process(directory, completedParentDirectory, args.custom_regex, args.dry_run, args.no_confirm) +if __name__ == '__main__': + main() From 863a9288f40c57caf3c814da0af3b9a2ee3c84db Mon Sep 17 00:00:00 2001 From: Pukabyte <120460627+Pukabyte@users.noreply.github.com> Date: Mon, 24 Feb 2025 07:50:12 +1300 Subject: [PATCH 2/2] Update import_torrent_folder.py --- import_torrent_folder.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/import_torrent_folder.py b/import_torrent_folder.py index 72352e2..9f59e64 100644 --- a/import_torrent_folder.py +++ b/import_torrent_folder.py @@ -12,19 +12,19 @@ def get_completed_parent_directory(use_radarr, use_radarr4k, use_radarranime, us elif use_radarr: return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']}/completed" elif use_radarr4k: - return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']}4k/completed" + return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']} 4k/completed" elif use_radarranime: - return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']}anime/completed" + return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']} anime/completed" elif use_radarrmux: - return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']}mux/completed" + return f"{blackhole['baseWatchPath']}/{blackhole['radarrPath']} mux/completed" elif use_sonarr: return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']}/completed" elif use_sonarr4k: - return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']}4k/completed" + return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']} 4k/completed" elif use_sonarranime: - return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']}anime/completed" + return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']} anime/completed" elif use_sonarrmux: - return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']}mux/completed" + return f"{blackhole['baseWatchPath']}/{blackhole['sonarrPath']} mux/completed" else: return None