implemented choose index

This commit is contained in:
Hellow2 2023-03-29 11:34:58 +02:00
parent 87f51d7a3a
commit e73bd6434d
3 changed files with 60 additions and 20 deletions

View File

@ -166,9 +166,16 @@ class Page:
new_music_object: DatabaseObject = type(music_object)()
had_sources = False
source: Source
for source in music_object.source_collection.get_sources_from_page(cls.SOURCE_TYPE):
new_music_object.merge(cls._fetch_object_from_source(source=source, obj_type=type(music_object), stop_at_level=stop_at_level))
had_sources = True
if not had_sources:
music_object.compile(merge_into=True)
return music_object
collections = {
Label: Collection(element_type=Label),

View File

@ -0,0 +1,36 @@
from typing import Tuple, Type, Set, Union, List
from . import page_attributes
from ..abstract import Page
from ...objects import Song, Album, Artist, Label
MusicObject = Union[Song, Album, Artist, Label]
class Download:
def __init__(
self,
pages: Tuple[Type[Page]] = page_attributes.ALL_PAGES,
exclude_pages: Set[Type[Page]] = set(),
exclude_shady: bool = False,
) -> None:
_page_list: List[Type[Page]] = []
_audio_page_list: List[Type[Page]] = []
for page in pages:
if exclude_shady and page in page_attributes.SHADY_PAGES:
continue
if page in exclude_pages:
continue
_page_list.append(page)
if page in page_attributes.AUDIO_PAGES:
_audio_page_list.append(page)
self.pages: Tuple[Type[Page]] = tuple(_page_list)
self.audio_pages: Tuple[Type[Page]] = tuple(_audio_page_list)
def fetch_details(self, music_object: MusicObject) -> MusicObject:
for page in self.pages:
page.fetch_details(music_object=music_object)
return music_object

View File

@ -2,6 +2,7 @@ from collections import defaultdict
from typing import Tuple, List, Set, Dict, Type, Union
from . import page_attributes
from .download import Download
from ..abstract import Page
from ...objects import Options, DatabaseObject
@ -45,7 +46,7 @@ class MultiPageOptions:
return "\n".join(lines)
def choose_from_all_pages(self, index: int) -> DatabaseObject:
def choose_from_all_pages(self, index: int) -> Tuple[DatabaseObject, Type[Page]]:
j = 0
for page, options in self._current_option_dict.items():
option_len = len(options)
@ -53,7 +54,7 @@ class MultiPageOptions:
option_len = self.max_displayed_options
if index < j + option_len:
return options[j + option_len - 1]
return options[j + option_len - 1], Page
j += option_len - 1
@ -80,7 +81,7 @@ class MultiPageOptions:
return self.string_from_all_pages()
class Search:
class Search(Download):
def __init__(
self,
query: str,
@ -91,22 +92,11 @@ class Search:
option_digits: int = 3,
dry: bool = False,
) -> None:
_page_list: List[Type[Page]] = []
_audio_page_list: List[Type[Page]] = []
for page in pages:
if exclude_shady and page in page_attributes.SHADY_PAGES:
continue
if page in exclude_pages:
continue
_page_list.append(page)
if page in page_attributes.AUDIO_PAGES:
_audio_page_list.append(page)
self.pages: Tuple[Type[Page]] = tuple(_page_list)
self.audio_pages: Tuple[Type[Page]] = tuple(_audio_page_list)
super().__init__(
pages=pages,
exclude_pages=exclude_pages,
exclude_shady=exclude_shady
)
self.max_displayed_options = max_displayed_options
self.option_digits: int = option_digits
@ -163,7 +153,14 @@ class Search:
def choose_index(self, index: int) -> MultiPageOptions:
pass
db_object, page = self._current_option.choose_from_all_pages(index=index)
music_object = self.fetch_details(db_object)
mpo = self.next_options
mpo[page] = music_object.options
return mpo
def choose(self, choosen: Union[Type[Page], int]) -> MultiPageOptions:
if type(choosen) == int: