From 6e17758826042dfb4cde56d10d21d5cf614788ae Mon Sep 17 00:00:00 2001 From: Hellow Date: Tue, 4 Apr 2023 20:00:21 +0200 Subject: [PATCH] changed download results and integrated them in the cli --- src/music_kraken/__init__.py | 20 ++++++++++--------- .../pages/download_center/search.py | 12 +++++------ .../pages/support_classes/download_result.py | 8 ++++++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index 587d714..e952255 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -59,20 +59,15 @@ def cli(): return if parsed in DOWNLOAD_COMMANDS: - if not search.download_chosen(): - print("could not download the chosen option.. sorry.") - else: - print("success! have fun :)") - return - - + print(search.download_chosen()) + url = re.match(URL_REGGEX, query) if url is not None: if not search.search_url(url.string): print("The given url couldn't be downloaded") return - page = search._get_page_from_query(parsed) + page = search.get_page_from_query(parsed) if page is not None: search.choose_page(page) return @@ -83,6 +78,13 @@ def cli(): search = pages.Search() while True: - next_search(search, input(">> ")) + next_input = input(">> ") + if next_input in { + "exit", + "quit" + }: + print("byeeee UwU") + break + next_search(search, next_input) print(search) \ No newline at end of file diff --git a/src/music_kraken/pages/download_center/search.py b/src/music_kraken/pages/download_center/search.py index 7d57fbd..4cd7a85 100644 --- a/src/music_kraken/pages/download_center/search.py +++ b/src/music_kraken/pages/download_center/search.py @@ -7,6 +7,7 @@ from .multiple_options import MultiPageOptions from ..abstract import Page from ...objects import Options, DatabaseObject, Source from ...utils.shared import DOWNLOAD_LOGGER as LOGGER +from ..support_classes.download_result import DownloadResult class Search(Download): @@ -83,7 +84,7 @@ class Search(Download): mpo[page] = prev_mpo[page] - def _get_page_from_query(self, query: str) -> Optional[Type[Page]]: + def get_page_from_query(self, query: str) -> Optional[Type[Page]]: """ query can be for example: "a" or "EncyclopaediaMetallum" to choose a page @@ -131,10 +132,9 @@ class Search(Download): return True - def download_chosen(self) -> bool: + def download_chosen(self) -> DownloadResult: if self._current_option._derive_from is None: - LOGGER.warning(f"No option has been chosen yet.") - return False + return DownloadResult(error_message="No option has been chosen yet.") source: Source for source in self._current_option._derive_from.source_collection: @@ -143,7 +143,5 @@ class Search(Download): if page in self.audio_pages: return page.download(music_object=self._current_option._derive_from) - LOGGER.warning(f"Page is no audio page.") - - return False + return DownloadResult(error_message=f"Didn't find a source for {self._current_option._derive_from.option_string}.") diff --git a/src/music_kraken/pages/support_classes/download_result.py b/src/music_kraken/pages/support_classes/download_result.py index a11f114..78cf0e2 100644 --- a/src/music_kraken/pages/support_classes/download_result.py +++ b/src/music_kraken/pages/support_classes/download_result.py @@ -16,8 +16,12 @@ class DownloadResult: return self.error_message is not None def merge(self, other: "DownloadResult"): - self.total += other.total - self.fail += other.fail + if other.fatal_error: + self.total += 1 + self.fail += 1 + else: + self.total += other.total + self.fail += other.fail def __repr__(self): if self.fatal_error: