diff --git a/src/main.py b/src/main.py index 80a8e83..a5f25a0 100644 --- a/src/main.py +++ b/src/main.py @@ -1,7 +1,7 @@ from metadata.database import Database from metadata.download import MetadataDownloader import metadata.download -import metadata.metadata +import metadata.search import download_links import url_to_path import download @@ -17,6 +17,7 @@ DATABASE_FILE = "metadata.db" DATABASE_STRUCTURE_FILE = "database_structure.sql" DATABASE_STRUCTURE_FALLBACK = "https://raw.githubusercontent.com/HeIIow2/music-downloader/new_metadata/assets/database_structure.sql" +SEARCH_LOGGER = logging.getLogger("mb-cli") DATABASE_LOGGER = logging.getLogger("database") METADATA_DOWNLOAD_LOGGER = logging.getLogger("metadata-download") URL_DOWNLOAD_LOGGER = logging.getLogger("ling-download") @@ -27,9 +28,6 @@ NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea" MUSIC_DIR = os.path.expanduser('~/Music') TOR = False -logger = logging.getLogger() -logger.level = logging.DEBUG - temp_dir = os.path.join(tempfile.gettempdir(), TEMP_FOLDER) if not os.path.exists(temp_dir): os.mkdir(temp_dir) @@ -52,28 +50,26 @@ def get_existing_genre(): return valid_directories -def search_for_metadata(query: str): - search = metadata.metadata.Search(query=query) +def search_for_metadata(): + search = metadata.search.Search(logger=SEARCH_LOGGER) - print(search.options) while True: input_ = input( - "q to quit, ok to download, .. for previous options, . for current options, int for this element: ").lower() + "q to quit, .. for previous options, int for this element, str to search for query, ok to download\n") input_.strip() - if input_ == "q": - exit(0) - if input_ == "ok": - return search.current_chosen_option - if input_ == ".": - print(search.options) - continue - if input_ == "..": - print(search.get_previous_options()) + if input_.lower() == "ok": + break + if input_.lower() == "q": + break + if input_.lower() == "..": + search.get_previous_options() continue if input_.isdigit(): - print(search.choose(int(input_))) + search.choose(int(input_)) continue + search.search_from_query(input_) + return search.current_option def get_genre(): existing_genres = get_existing_genre() @@ -106,7 +102,7 @@ def cli(start_at: int = 0): logging.info(f"{genre} has been set as genre.") if start_at <= 0: - search = search_for_metadata(query=input("initial query: ")) + search = search_for_metadata() logging.info("Starting Downloading of metadata") metadata_downloader = MetadataDownloader(database, METADATA_DOWNLOAD_LOGGER) metadata_downloader.download(search) diff --git a/src/metadata/object_handeling.py b/src/metadata/object_handeling.py index 57a3b4d..7922603 100644 --- a/src/metadata/object_handeling.py +++ b/src/metadata/object_handeling.py @@ -19,6 +19,6 @@ def parse_music_brainz_date(mb_date: str) -> date: first_release_date = mb_date if first_release_date.count("-") == 2: year, month, day = [int(i) for i in first_release_date.split("-")] - elif first_release_date.count("-") == 0: + elif first_release_date.count("-") == 0 and first_release_date.isdigit(): year = int(first_release_date) return date(year, month, day) diff --git a/src/metadata/search.py b/src/metadata/search.py index 3030ec4..1ffbf47 100644 --- a/src/metadata/search.py +++ b/src/metadata/search.py @@ -26,6 +26,15 @@ class Option: self.additional_info = additional_info + def __getitem__(self, item): + map_ = { + "id": self.id, + "type": self.type, + "kind": self.type, + "name": self.name + } + return map_[item] + def __repr__(self) -> str: type_repr = { 'artist': 'artist\t\t',