changed download results
and integrated them in the cli
This commit is contained in:
parent
e8d17d5f37
commit
6e17758826
@ -59,12 +59,7 @@ 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:
|
||||
@ -72,7 +67,7 @@ def cli():
|
||||
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)
|
||||
|
@ -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}.")
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user