much progress in cleaning up
This commit is contained in:
parent
e996bd4e4f
commit
2fabd09a71
@ -1,29 +1,49 @@
|
||||
from typing import Tuple, Type, Dict, List
|
||||
import threading
|
||||
from queue import Queue
|
||||
from typing import Tuple, Type, Dict, List, Set
|
||||
|
||||
from ..utils.enums.source import SourcePages
|
||||
from ..utils.support_classes import Query, EndThread
|
||||
from ..pages import Page, EncyclopaediaMetallum, Musify
|
||||
|
||||
ALL_PAGES: Tuple[Type[Page], ...] = (
|
||||
ALL_PAGES: Set[Type[Page]] = {
|
||||
EncyclopaediaMetallum,
|
||||
Musify
|
||||
)
|
||||
}
|
||||
|
||||
AUDIO_PAGES: Tuple[Type[Page], ...] = (
|
||||
AUDIO_PAGES: Set[Type[Page]] = {
|
||||
Musify,
|
||||
)
|
||||
}
|
||||
|
||||
SHADY_PAGES: Tuple[Type[Page], ...] = (
|
||||
SHADY_PAGES: Set[Type[Page]] = {
|
||||
Musify,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
exit_threads = EndThread()
|
||||
search_queue: Queue[Query] = Queue()
|
||||
|
||||
_page_threads: Dict[Type[Page], List[Page]] = dict()
|
||||
class Pages:
|
||||
def __init__(self, exclude_pages: Set[Type[Page]] = None, exclude_shady: bool = False) -> None:
|
||||
# initialize all page instances
|
||||
self._page_instances: Dict[Type[Page], Page] = dict()
|
||||
|
||||
exclude_pages = exclude_pages if exclude_pages is not None else set()
|
||||
|
||||
if exclude_shady:
|
||||
exclude_pages = exclude_pages.union(SHADY_PAGES)
|
||||
|
||||
if not exclude_pages.issubset(ALL_PAGES):
|
||||
raise ValueError(f"The excluded pages have to be a subset of all pages: {exclude_pages} | {ALL_PAGES}")
|
||||
|
||||
def _set_to_tuple(page_set: Set[Type[Page]]) -> Tuple[Type[Page], ...]:
|
||||
return tuple(sorted(page_set, key=lambda page: page.__name__))
|
||||
|
||||
self.pages: Tuple[Type[Page], ...] = _set_to_tuple(ALL_PAGES.difference(exclude_pages))
|
||||
self.audio_pages: Tuple[Type[Page], ...] = _set_to_tuple(set(self.pages).intersection(AUDIO_PAGES))
|
||||
|
||||
for page_type in ALL_PAGES:
|
||||
self._page_instances[page_type] = page_type()
|
||||
|
||||
def search(self, query: Query):
|
||||
for page_type in self.pages:
|
||||
self._page_instances[page_type].search(query=query)
|
||||
|
||||
|
||||
"""
|
||||
|
25
src/music_kraken/download/results.py
Normal file
25
src/music_kraken/download/results.py
Normal file
@ -0,0 +1,25 @@
|
||||
from typing import Tuple, Type, Dict, List
|
||||
|
||||
from ..objects import DatabaseObject
|
||||
from ..utils.enums.source import SourcePages
|
||||
from ..pages import Page, EncyclopaediaMetallum, Musify
|
||||
|
||||
class SearchResults:
|
||||
def __init__(
|
||||
self,
|
||||
pages: Tuple[Type[Page], ...]
|
||||
|
||||
) -> None:
|
||||
self.pages = pages
|
||||
# this would initialize a list for every page, which I don't think I want
|
||||
# self.results = Dict[Type[Page], List[DatabaseObject]] = {page: [] for page in self.pages}
|
||||
self.results = Dict[Type[Page], List[DatabaseObject]] = {}
|
||||
|
||||
def add(self, page: Type[Page], search_result: List[DatabaseObject]):
|
||||
self.results[page] = search_result
|
||||
|
||||
def __str__(self) -> str:
|
||||
for page in self.pages:
|
||||
if page not in self.results:
|
||||
continue
|
||||
|
@ -104,14 +104,7 @@ def merge_together(old_object: DatabaseObject, new_object: DatabaseObject) -> Da
|
||||
return old_object
|
||||
|
||||
|
||||
class LoreIpsum:
|
||||
pass
|
||||
|
||||
|
||||
Parent = threading.Thread if THREADED else LoreIpsum
|
||||
|
||||
|
||||
class Page(Parent):
|
||||
class Page():
|
||||
"""
|
||||
This is an abstract class, laying out the
|
||||
functionality for every other class fetching something
|
||||
@ -120,13 +113,20 @@ class Page(Parent):
|
||||
SOURCE_TYPE: SourcePages
|
||||
LOGGER = logging.getLogger("this shouldn't be used")
|
||||
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
"""
|
||||
CODE I NEED WHEN I START WITH MULTITHREADING
|
||||
|
||||
def __init__(self, end_event: EndThread, search_queue: Queue, search_result_queue: Queue):
|
||||
self.end_event = end_event
|
||||
|
||||
self.search_queue = search_queue
|
||||
self.search_result_queue = search_result_queue
|
||||
|
||||
Parent.__init__(self)
|
||||
super().__init__()
|
||||
|
||||
@property
|
||||
def _empty_working_queues(self):
|
||||
@ -138,6 +138,7 @@ class Page(Parent):
|
||||
self.search(self.search_queue.get())
|
||||
self.search_result_queue.put(FinishedSearch())
|
||||
continue
|
||||
"""
|
||||
|
||||
def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]:
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user