platform agnostic special char stripping

This commit is contained in:
Zotify 2024-09-01 18:47:51 +12:00
parent 21ef30844b
commit 08d844fe3e

View file

@ -12,7 +12,7 @@ import music_tag
import requests
from zotify.const import ARTIST, GENRE, TRACKTITLE, ALBUM, YEAR, DISCNUMBER, TRACKNUMBER, ARTWORK, \
WINDOWS_SYSTEM, LINUX_SYSTEM, ALBUMARTIST
WINDOWS_SYSTEM, ALBUMARTIST
from zotify.zotify import Zotify
@ -258,12 +258,7 @@ def fix_filename(name):
>>> all('_' == fix_filename(chr(i)) for i in list(range(32)))
True
"""
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))
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: