changed download results

and integrated them in the cli
This commit is contained in:
Hellow 2023-04-04 20:00:21 +02:00
parent e8d17d5f37
commit 6e17758826
3 changed files with 22 additions and 18 deletions

View File

@ -59,20 +59,15 @@ def cli():
return return
if parsed in DOWNLOAD_COMMANDS: if parsed in DOWNLOAD_COMMANDS:
if not search.download_chosen(): print(search.download_chosen())
print("could not download the chosen option.. sorry.")
else:
print("success! have fun :)")
return
url = re.match(URL_REGGEX, query) url = re.match(URL_REGGEX, query)
if url is not None: if url is not None:
if not search.search_url(url.string): if not search.search_url(url.string):
print("The given url couldn't be downloaded") print("The given url couldn't be downloaded")
return return
page = search._get_page_from_query(parsed) page = search.get_page_from_query(parsed)
if page is not None: if page is not None:
search.choose_page(page) search.choose_page(page)
return return
@ -83,6 +78,13 @@ def cli():
search = pages.Search() search = pages.Search()
while True: 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) print(search)

View File

@ -7,6 +7,7 @@ from .multiple_options import MultiPageOptions
from ..abstract import Page from ..abstract import Page
from ...objects import Options, DatabaseObject, Source from ...objects import Options, DatabaseObject, Source
from ...utils.shared import DOWNLOAD_LOGGER as LOGGER from ...utils.shared import DOWNLOAD_LOGGER as LOGGER
from ..support_classes.download_result import DownloadResult
class Search(Download): class Search(Download):
@ -83,7 +84,7 @@ class Search(Download):
mpo[page] = prev_mpo[page] 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: query can be for example:
"a" or "EncyclopaediaMetallum" to choose a page "a" or "EncyclopaediaMetallum" to choose a page
@ -131,10 +132,9 @@ class Search(Download):
return True return True
def download_chosen(self) -> bool: def download_chosen(self) -> DownloadResult:
if self._current_option._derive_from is None: if self._current_option._derive_from is None:
LOGGER.warning(f"No option has been chosen yet.") return DownloadResult(error_message="No option has been chosen yet.")
return False
source: Source source: Source
for source in self._current_option._derive_from.source_collection: for source in self._current_option._derive_from.source_collection:
@ -143,7 +143,5 @@ class Search(Download):
if page in self.audio_pages: if page in self.audio_pages:
return page.download(music_object=self._current_option._derive_from) return page.download(music_object=self._current_option._derive_from)
LOGGER.warning(f"Page is no audio page.") return DownloadResult(error_message=f"Didn't find a source for {self._current_option._derive_from.option_string}.")
return False

View File

@ -16,8 +16,12 @@ class DownloadResult:
return self.error_message is not None return self.error_message is not None
def merge(self, other: "DownloadResult"): def merge(self, other: "DownloadResult"):
self.total += other.total if other.fatal_error:
self.fail += other.fail self.total += 1
self.fail += 1
else:
self.total += other.total
self.fail += other.fail
def __repr__(self): def __repr__(self):
if self.fatal_error: if self.fatal_error: