From 385edc7087d3c6e75bc019488d14fc739eb3264a Mon Sep 17 00:00:00 2001 From: Hellow Date: Tue, 18 Apr 2023 22:39:19 +0200 Subject: [PATCH] translit --- requirements.txt | 3 ++- src/music_kraken/utils/string_processing.py | 25 ++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index be0f7b7..a67d5a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,5 @@ setuptools~=60.2.0 tqdm~=4.65.0 peewee~=3.15.4 ffmpeg-python~=0.2.0 -platformdirs~=3.2.0 \ No newline at end of file +platformdirs~=3.2.0 +transliterate~=1.10.2 \ No newline at end of file diff --git a/src/music_kraken/utils/string_processing.py b/src/music_kraken/utils/string_processing.py index 0268d3e..8f1bb1f 100644 --- a/src/music_kraken/utils/string_processing.py +++ b/src/music_kraken/utils/string_processing.py @@ -1,22 +1,31 @@ +from transliterate.exceptions import LanguageDetectionError +from transliterate import translit + + def unify(string: str) -> str: """ - returns an unified str, to make comparosons easy. - an unified string has following attributes: + returns a unified str, to make comparisons easy. + a unified string has the following attributes: - is lowercase """ - + + try: + string = translit(string, reversed=True) + except LanguageDetectionError: + pass + 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