implemented choose index
This commit is contained in:
parent
87f51d7a3a
commit
e73bd6434d
@ -166,9 +166,16 @@ class Page:
|
|||||||
|
|
||||||
new_music_object: DatabaseObject = type(music_object)()
|
new_music_object: DatabaseObject = type(music_object)()
|
||||||
|
|
||||||
|
had_sources = False
|
||||||
|
|
||||||
source: Source
|
source: Source
|
||||||
for source in music_object.source_collection.get_sources_from_page(cls.SOURCE_TYPE):
|
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))
|
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 = {
|
collections = {
|
||||||
Label: Collection(element_type=Label),
|
Label: Collection(element_type=Label),
|
||||||
|
36
src/music_kraken/pages/download_center/download.py
Normal file
36
src/music_kraken/pages/download_center/download.py
Normal 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
|
@ -2,6 +2,7 @@ from collections import defaultdict
|
|||||||
from typing import Tuple, List, Set, Dict, Type, Union
|
from typing import Tuple, List, Set, Dict, Type, Union
|
||||||
|
|
||||||
from . import page_attributes
|
from . import page_attributes
|
||||||
|
from .download import Download
|
||||||
from ..abstract import Page
|
from ..abstract import Page
|
||||||
from ...objects import Options, DatabaseObject
|
from ...objects import Options, DatabaseObject
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ class MultiPageOptions:
|
|||||||
|
|
||||||
return "\n".join(lines)
|
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
|
j = 0
|
||||||
for page, options in self._current_option_dict.items():
|
for page, options in self._current_option_dict.items():
|
||||||
option_len = len(options)
|
option_len = len(options)
|
||||||
@ -53,7 +54,7 @@ class MultiPageOptions:
|
|||||||
option_len = self.max_displayed_options
|
option_len = self.max_displayed_options
|
||||||
|
|
||||||
if index < j + option_len:
|
if index < j + option_len:
|
||||||
return options[j + option_len - 1]
|
return options[j + option_len - 1], Page
|
||||||
|
|
||||||
j += option_len - 1
|
j += option_len - 1
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ class MultiPageOptions:
|
|||||||
return self.string_from_all_pages()
|
return self.string_from_all_pages()
|
||||||
|
|
||||||
|
|
||||||
class Search:
|
class Search(Download):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
query: str,
|
query: str,
|
||||||
@ -91,22 +92,11 @@ class Search:
|
|||||||
option_digits: int = 3,
|
option_digits: int = 3,
|
||||||
dry: bool = False,
|
dry: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
_page_list: List[Type[Page]] = []
|
super().__init__(
|
||||||
_audio_page_list: List[Type[Page]] = []
|
pages=pages,
|
||||||
|
exclude_pages=exclude_pages,
|
||||||
for page in pages:
|
exclude_shady=exclude_shady
|
||||||
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)
|
|
||||||
|
|
||||||
self.max_displayed_options = max_displayed_options
|
self.max_displayed_options = max_displayed_options
|
||||||
self.option_digits: int = option_digits
|
self.option_digits: int = option_digits
|
||||||
@ -163,7 +153,14 @@ class Search:
|
|||||||
|
|
||||||
|
|
||||||
def choose_index(self, index: int) -> MultiPageOptions:
|
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:
|
def choose(self, choosen: Union[Type[Page], int]) -> MultiPageOptions:
|
||||||
if type(choosen) == int:
|
if type(choosen) == int:
|
||||||
|
Loading…
Reference in New Issue
Block a user