From 89735102cb4a794dda15753313f4a60e6302a9f0 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Tue, 10 Mar 2026 16:01:36 -0400 Subject: [PATCH] [O] Avoid hardcoding dirs --- launcher.py | 6 ++++-- utils.py | 5 +++++ workflow.py | 7 ++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/launcher.py b/launcher.py index 5587ec2..a2c0a4f 100644 --- a/launcher.py +++ b/launcher.py @@ -5,6 +5,8 @@ import os from pathlib import Path from datetime import datetime import time +import tomllib +from utils import DEFAULT_DL_DIR, DEFAULT_JELLYFIN_DIR def run_workflow(imdb_id: str, dl_dir: str, jellyfin_dir: str, logs_dir: Path, errors_dir: Path): timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") @@ -39,8 +41,8 @@ def run_workflow(imdb_id: str, dl_dir: str, jellyfin_dir: str, logs_dir: Path, e def main(): parser = argparse.ArgumentParser(description="Multithreading launcher for IMDB workflow.") parser.add_argument("imdb_ids", nargs="+", help="The IMDb IDs to process (e.g., tt38872297 tt0903747)") - parser.add_argument("--dl-dir", type=str, default="/data/QB", help="The qBittorrent download directory") - parser.add_argument("--jellyfin-dir", type=str, default="/data/Jellyfin", help="The base Jellyfin library directory") + parser.add_argument("--dl-dir", type=str, default=DEFAULT_DL_DIR, help="The qBittorrent download directory") + parser.add_argument("--jellyfin-dir", type=str, default=DEFAULT_JELLYFIN_DIR, help="The base Jellyfin library directory") parser.add_argument("--workers", type=int, default=4, help="Number of concurrent workers") parser.add_argument("--delay", type=float, default=5.0, help="Delay in seconds between starting each workflow") diff --git a/utils.py b/utils.py index 5521122..15a9e13 100644 --- a/utils.py +++ b/utils.py @@ -1,8 +1,13 @@ import json import hashlib +import tomllib from pathlib import Path from functools import wraps +config = tomllib.loads(Path("config.toml").read_text(encoding="utf-8")) +DEFAULT_DL_DIR = config["paths"]["qb_download_dir"] +DEFAULT_JELLYFIN_DIR = config["paths"]["jellyfin_dir"] + def _disk_cache_decorator(subdir_name: str, ext: str, read_func, write_func, should_cache = None): """ Generic internal caching decorator handling filename hashing and io abstraction. diff --git a/workflow.py b/workflow.py index 2a4f429..87c35f0 100644 --- a/workflow.py +++ b/workflow.py @@ -2,6 +2,7 @@ import json import time from pathlib import Path +from utils import DEFAULT_DL_DIR, DEFAULT_JELLYFIN_DIR from utils_mteam import ( mteam_imdb_info, search_mteam_torrents, @@ -82,7 +83,7 @@ def wait_for_download(qb, t_hash: str): print("Download complete!") -def process_imdb_workflow(imdb_id: str, dl_dir: str = "/data/QB", jellyfin_base_dir: str = "/data/Jellyfin"): +def process_imdb_workflow(imdb_id: str, dl_dir: str = DEFAULT_DL_DIR, jellyfin_base_dir: str = DEFAULT_JELLYFIN_DIR): """ Workflow to automatically find, download, and map torrents for an IMDb ID into a Jellyfin library. """ @@ -212,8 +213,8 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description="Workflow to automatically find, download, and map torrents for an IMDb ID into Jellyfin.") parser.add_argument("imdb_id", type=str, help="The IMDb ID to process (e.g., tt38872297)") - parser.add_argument("--dl-dir", type=str, default="/data/QB", help="The qBittorrent download directory") - parser.add_argument("--jellyfin-dir", type=str, default="/data/Jellyfin", help="The base Jellyfin library directory") + parser.add_argument("--dl-dir", type=str, default=DEFAULT_DL_DIR, help="The qBittorrent download directory") + parser.add_argument("--jellyfin-dir", type=str, default=DEFAULT_JELLYFIN_DIR, help="The base Jellyfin library directory") args = parser.parse_args()