From 26c81779fa62c356da472eb35866c7618e467691 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 21 Nov 2025 19:14:54 +0000 Subject: [PATCH] fix(utilities): handle space-hyphen-space separators in sanitize_filename Pre-process space-hyphen-space patterns (e.g., "Title - Episode") before other character replacements to prevent creating problematic dot-hyphen-dot (.-.) patterns in filenames. This addresses PR #44 by fixing the root cause rather than post-processing the problematic pattern. The fix ensures that titles like "Show - S01E01" become "Show.S01E01" --- unshackle/core/utilities.py | 1 + 1 file changed, 1 insertion(+) diff --git a/unshackle/core/utilities.py b/unshackle/core/utilities.py index 4892c24..d0ace5f 100644 --- a/unshackle/core/utilities.py +++ b/unshackle/core/utilities.py @@ -127,6 +127,7 @@ def sanitize_filename(filename: str, spacer: str = ".") -> str: # remove or replace further characters as needed filename = "".join(c for c in filename if unicodedata.category(c) != "Mn") # hidden characters filename = filename.replace("/", " & ").replace(";", " & ") # e.g. multi-episode filenames + filename = re.sub(r" - ", spacer, filename) # title separators to spacer (avoids .-. pattern) filename = re.sub(r"[:; ]", spacer, filename) # structural chars to (spacer) filename = re.sub(r"[\\*!?¿,'\"" "()<>|$#~]", "", filename) # not filename safe chars filename = re.sub(rf"[{spacer}]{{2,}}", spacer, filename) # remove extra neighbouring (spacer)s