From ad446a1099fb0a489d80d33ac2582d85f219ccda Mon Sep 17 00:00:00 2001 From: Muffin-chan <42274306+GabrieleAncillai@users.noreply.github.com> Date: Tue, 22 Nov 2022 03:24:25 -0500 Subject: [PATCH] Some cli improvements - Adds cross platform clear console functionality - Replaces "search_for_metadata" if tree with a match case - Implements alternative command interface for handling the program - Fixes bug of error being displayed when quitting the program --- .gitignore | 3 ++ src/music_kraken/__init__.py | 53 +++++++++++++++++++++-------- src/music_kraken/utils/__init__.py | 2 +- src/music_kraken/utils/functions.py | 4 +++ 4 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 src/music_kraken/utils/functions.py diff --git a/.gitignore b/.gitignore index bc6c53c..0ae234f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ __pycache__/ /build/* !/build/build.sh + +# Virtual Environment +venv diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index c0f0df0..b908225 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -1,3 +1,4 @@ +from .utils.functions import * from .utils.shared import * from .metadata import ( @@ -37,24 +38,42 @@ def get_existing_genre(): def search_for_metadata(): + clear_console() + search = metadata_search.Search() while True: input_ = input( - "q to quit, .. for previous options, int for this element, str to search for query, ok to download\n") - input_.strip() - if input_.lower() == "ok": - break - if input_.lower() == "q": - break - if input_.lower() == "..": - print() - print(search.get_previous_options()) - continue - if input_.isdigit(): - print() - print(search.choose(int(input_))) - continue +""" +- - - Type the command you want to execute - - - +.. - Previous Options +(query_string) - Search for songs, albums, bands... +(int) - Select an item from the search results +d - Start the download +h - Help +q - Quit / Exit + +command: """ + ) + + match (input_.strip().lower()): + case "d" | "ok" | "dl" | "download": + break + case "q" | "quit" | "exit": + clear_console() + exit() + case "h" | "help": + print() + # TODO: Help text (mainly explaining query strings and alternative command functionalities) + print("Insert here help text....") + case inp if inp.isdigit(): + print() + print(search.choose(int(input_))) + continue + case ".." : + print() + print(search.get_previous_options()) + print() print(search.search_from_query(input_)) @@ -81,6 +100,8 @@ def get_genre(): def cli(start_at: int = 0, only_lyrics: bool = False): + clear_console() + if start_at <= 2 and not only_lyrics: genre = get_genre() logging.info(f"{genre} has been set as genre.") @@ -107,3 +128,7 @@ def cli(start_at: int = 0, only_lyrics: bool = False): if start_at <= 4: logging.info("starting to fetch the lyrics") lyrics.fetch_lyrics() + + +def gtk_gui(): + pass diff --git a/src/music_kraken/utils/__init__.py b/src/music_kraken/utils/__init__.py index 275921a..1c1e438 100644 --- a/src/music_kraken/utils/__init__.py +++ b/src/music_kraken/utils/__init__.py @@ -1,2 +1,2 @@ # tells what exists -__all__ = ["shared", "object_handeling", "phonetic_compares"] +__all__ = ["shared", "object_handeling", "phonetic_compares", "functions"] diff --git a/src/music_kraken/utils/functions.py b/src/music_kraken/utils/functions.py new file mode 100644 index 0000000..d642f2a --- /dev/null +++ b/src/music_kraken/utils/functions.py @@ -0,0 +1,4 @@ +import os + +def clear_console(): + os.system('cls' if os.name in ('nt', 'dos') else 'clear') \ No newline at end of file