diff --git a/pytest/modules/Speech_Recognition/test_hyphenation.py b/pytest/modules/Speech_Recognition/test_hyphenation.py index cfd5dd8..eab445d 100644 --- a/pytest/modules/Speech_Recognition/test_hyphenation.py +++ b/pytest/modules/Speech_Recognition/test_hyphenation.py @@ -1,17 +1,34 @@ """Tests for hyphenation.py""" import unittest -from src.modules.Speech_Recognition.hyphenation import hyphenation +from unittest.mock import patch +from src.modules.Speech_Recognition.hyphenation import hyphenation, language_check from hyphen import Hyphenator +class TestHypenation(unittest.TestCase): -def test_hypenation(): - """Test case for hyphenation function.""" + def test_hypenation(self): + """Test case for hyphenation function.""" - assert hyphenation("begegnen", Hyphenator("de_DE")) == ["be", "geg", "nen"] - assert hyphenation(".b,e~g'eg*nen, ", Hyphenator("de_DE")) == [".b,e", "~g'eg", "*nen, "] - assert hyphenation("Abend, ", Hyphenator("de_AT")) == None - assert hyphenation("Abend.", Hyphenator("de_AT")) == None + assert hyphenation("begegnen", Hyphenator("de_DE")) == ["be", "geg", "nen"] + assert hyphenation(".b,e~g'eg*nen, ", Hyphenator("de_DE")) == [".b,e", "~g'eg", "*nen, "] + assert hyphenation("Abend, ", Hyphenator("de_AT")) == None + assert hyphenation("Abend.", Hyphenator("de_AT")) == None + + @patch('hyphen.dictools.list_installed') + def test_language_check_has_installed_language(self, mock_list_installed): + + mock_list_installed.return_value = ['de', 'de_DE', 'en', 'en_US', 'en_GB'] + assert language_check("en") == "en_US" + assert language_check("de") == "de_DE" + + @patch('hyphen.dictools.list_installed') + def test_language_check_not_installed_language(self, mock_list_installed): + + mock_list_installed.return_value = [] + assert language_check("fr") == "fr_FR" + assert language_check("de") == "de" + assert language_check("none") == None if __name__ == "__main__": unittest.main() \ No newline at end of file diff --git a/pytest/modules/UltraStar/test_ultrastar_writer.py b/pytest/modules/UltraStar/test_ultrastar_writer.py index ae16a7f..fe5f061 100644 --- a/pytest/modules/UltraStar/test_ultrastar_writer.py +++ b/pytest/modules/UltraStar/test_ultrastar_writer.py @@ -82,7 +82,7 @@ class TestCreateUltrastarTxt(unittest.TestCase): @staticmethod def default_values(default_ultrastar_class): expected_calls = [ - f"#{UltrastarTxtTag.VERSION}:{default_ultrastar_class.version}\n", + #f"#{UltrastarTxtTag.VERSION}:{default_ultrastar_class.version}\n", # todo: Version definition is in progress f"#{UltrastarTxtTag.ARTIST}:{default_ultrastar_class.artist}\n", f"#{UltrastarTxtTag.TITLE}:{default_ultrastar_class.title}\n", f"#{UltrastarTxtTag.MP3}:{default_ultrastar_class.mp3}\n", @@ -103,7 +103,7 @@ class TestCreateUltrastarTxt(unittest.TestCase): @staticmethod def full_values(default_ultrastar_class): expected_calls = [ - f"#{UltrastarTxtTag.VERSION}:{default_ultrastar_class.version}\n", + #f"#{UltrastarTxtTag.VERSION}:{default_ultrastar_class.version}\n", # todo: Version definition is in progress f"#{UltrastarTxtTag.ARTIST}:{default_ultrastar_class.artist}\n", f"#{UltrastarTxtTag.TITLE}:{default_ultrastar_class.title}\n", f"#{UltrastarTxtTag.YEAR}:{default_ultrastar_class.year}\n", diff --git a/src/Settings.py b/src/Settings.py index 68c2199..70c771c 100644 --- a/src/Settings.py +++ b/src/Settings.py @@ -1,5 +1,5 @@ class Settings: - APP_VERSION = "0.0.1-2023-11-13" + APP_VERSION = "0.0.2" create_midi = True create_plot = False diff --git a/src/UltraSinger.py b/src/UltraSinger.py index dd52a60..5ad24f5 100644 --- a/src/UltraSinger.py +++ b/src/UltraSinger.py @@ -264,6 +264,18 @@ def print_support() -> None: f"{ULTRASINGER_HEAD} {gold_highlighted('This will help alot to keep this project alive and improved.')}" ) +def print_version() -> None: + """Print version text""" + print() + print( + f"{ULTRASINGER_HEAD} {gold_highlighted('*****************************')}" + ) + print( + f"{ULTRASINGER_HEAD} {gold_highlighted('UltraSinger Version:')} {light_blue_highlighted(settings.APP_VERSION)}" + ) + print( + f"{ULTRASINGER_HEAD} {gold_highlighted('*****************************')}" + ) def run() -> None: """The processing function of this program""" @@ -772,6 +784,7 @@ def denoise_vocal_audio(basename_without_ext: str, cache_path: str) -> None: def main(argv: list[str]) -> None: """Main function""" + print_version() init_settings(argv) run() # todo: cleanup diff --git a/src/modules/Speech_Recognition/hyphenation.py b/src/modules/Speech_Recognition/hyphenation.py index bd19774..4e13440 100644 --- a/src/modules/Speech_Recognition/hyphenation.py +++ b/src/modules/Speech_Recognition/hyphenation.py @@ -2,7 +2,7 @@ import string -from hyphen import Hyphenator +from hyphen import Hyphenator, dictools from modules.console_colors import ( ULTRASINGER_HEAD, @@ -78,10 +78,29 @@ def language_check(language="en") -> str | None: """Check if language is supported""" lang_region = None - for dict_lang in LANGUAGES: - if dict_lang.startswith(language): - lang_region = dict_lang - break + installed = dictools.list_installed() + installed_region_keys = [i for i in installed if i.startswith(language) and "_" in i] + try: + # Try to find installed language with region prediction + lang_region = next(i for i in installed_region_keys if i == f"{language}_{language.upper()}") + except StopIteration: + if installed_region_keys: + # Take first installed region language + lang_region = installed_region_keys[0] + else: + # Take downloadable language key + downloadable_key = [i for i in LANGUAGES if i.startswith(language)] + downloadable_folder_key = [i for i in downloadable_key if i == language] + if downloadable_folder_key: + lang_region = downloadable_key[0] + else: + try: + # Try to find downloadable language with region prediction + lang_region = next(i for i in downloadable_key if i == f"{language}_{language.upper()}") + except StopIteration: + if downloadable_key: + # Take first installed region language + lang_region = downloadable_key[0] if lang_region is None: return None