From ad9c5df7a0a91f05767ba5fdebede473eed36662 Mon Sep 17 00:00:00 2001 From: PhYrE Date: Wed, 24 Apr 2024 01:39:41 +0200 Subject: [PATCH] Remove more special characters irrespective of filesystem support Having colons, asterisks, question marks, pipes, and other control characters, while valid on UNIX/Linux/MacOS systems, is not good for portability. It doesn't take much away to remove this, and ensures consistent file names across multiple platforms. --- zotify/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zotify/utils.py b/zotify/utils.py index dce9fd2..ba20aec 100644 --- a/zotify/utils.py +++ b/zotify/utils.py @@ -261,9 +261,9 @@ def fix_filename(name): if platform.system() == WINDOWS_SYSTEM: return re.sub(r'[/\\:|<>"?*\0-\x1f]|^(AUX|COM[1-9]|CON|LPT[1-9]|NUL|PRN)(?![^.])|^\s|[\s.]$', "_", str(name), flags=re.IGNORECASE) elif platform.system() == LINUX_SYSTEM: - return re.sub(r'[/\0]', "_", str(name)) + return re.sub(r'[/\\:|<>"?*\0-\x1f]|^(AUX|COM[1-9]|CON|LPT[1-9]|NUL|PRN)(?![^.])|^\s|[\s.]$', "_", str(name), flags=re.IGNORECASE) else: # MacOS - return re.sub(r'[/:\0]', "_", str(name)) + return re.sub(r'[/\\:|<>"?*\0-\x1f]|^(AUX|COM[1-9]|CON|LPT[1-9]|NUL|PRN)(?![^.])|^\s|[\s.]$', "_", str(name), flags=re.IGNORECASE) def fmt_seconds(secs: float) -> str: