From c501461b1ef57f137fa56087ef09b486807f873d Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Mon, 3 Apr 2023 11:17:55 +0200 Subject: [PATCH] escaping strings --- src/music_kraken/pages/abstract.py | 3 ++- src/music_kraken/utils/string_processing.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index 15055a4..ebb2f17 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -22,6 +22,7 @@ from ..objects import ( ) from ..tagging import write_metadata_to_target from ..utils.shared import DOWNLOAD_PATH, DOWNLOAD_FILE, DEFAULT_VALUES +from ..utils.string_processing import fit_to_file_system LOGGER = logging.getLogger("this shouldn't be used") @@ -36,7 +37,7 @@ class DefaultTarget: def __setattr__(self, __name: str, __value: str) -> None: if __name in DEFAULT_VALUES: if self.__getattribute__(__name) == DEFAULT_VALUES[__name]: - super().__setattr__(__name, __value) + super().__setattr__(__name, fit_to_file_system(__value)) return super().__setattr__(__name, __value) diff --git a/src/music_kraken/utils/string_processing.py b/src/music_kraken/utils/string_processing.py index 46edb8c..0268d3e 100644 --- a/src/music_kraken/utils/string_processing.py +++ b/src/music_kraken/utils/string_processing.py @@ -6,4 +6,17 @@ def unify(string: str) -> str: """ return string.lower() + +def fit_to_file_system(string: str) -> str: + string = string.strip() + + while string[0] == ".": + if len(string) == 0: + return string + + string = string[1:] + + string = string.replace("/", "|").replace("\\", "|") + + return string \ No newline at end of file