From 9f2a4ec6f7e015a29eb88cb5b6ff70a8bbf41995 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Tue, 10 Mar 2026 18:29:24 -0400 Subject: [PATCH] [O] Sanitize file name --- workflow.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/workflow.py b/workflow.py index 782f580..befe7d4 100644 --- a/workflow.py +++ b/workflow.py @@ -1,3 +1,4 @@ +import re import json import time from pathlib import Path @@ -33,6 +34,10 @@ def format_file_tree(file_tree: list) -> str: lines.append(f.get("name", "")) return "\n".join(lines) +def sanitize_filename(name: str) -> str: + """Replaces invalid characters in filenames with spaces.""" + return re.sub(r'[\\/*?:"<>|]', " ", name).strip() + def prepare_file_tree_paths(file_tree: list, new_name: str, dl_dir: str) -> Path: """ @@ -260,12 +265,14 @@ def process_imdb_workflow(imdb_id: str, dl_dir: str = DEFAULT_DL_DIR, jellyfin_b title = imdb_info['data'].get('title', 'Unknown_Title') year = imdb_info['data'].get('year', '') - title_dir = f"{title} ({year})" + title = sanitize_filename(title) + + title_dir = sanitize_filename(f"{title} ({year})") print(f"Found Title: {title_dir}") print(f"\n=== [0.2] Checking if already exists in file system ===") fs_match_dir = check_local_filesystem(dl_dir, imdb_id) - new_name = f"{year} {title} [{imdb_id}]".strip() + new_name = sanitize_filename(f"{year} {title} [{imdb_id}]") if fs_match_dir: print(f"Found existing file/directory in file system: {fs_match_dir.name}, skipping qBit check, search, and download.")