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
|
from typing import Tuple, Type, Dict, List, Set
|
||||||
import threading
|
|
||||||
from queue import Queue
|
|
||||||
|
|
||||||
from ..utils.enums.source import SourcePages
|
from ..utils.enums.source import SourcePages
|
||||||
from ..utils.support_classes import Query, EndThread
|
from ..utils.support_classes import Query, EndThread
|
||||||
from ..pages import Page, EncyclopaediaMetallum, Musify
|
from ..pages import Page, EncyclopaediaMetallum, Musify
|
||||||
|
|
||||||
ALL_PAGES: Tuple[Type[Page], ...] = (
|
ALL_PAGES: Set[Type[Page]] = {
|
||||||
EncyclopaediaMetallum,
|
EncyclopaediaMetallum,
|
||||||
Musify
|
Musify
|
||||||
)
|
}
|
||||||
|
|
||||||
AUDIO_PAGES: Tuple[Type[Page], ...] = (
|
AUDIO_PAGES: Set[Type[Page]] = {
|
||||||
Musify,
|
Musify,
|
||||||
)
|
}
|
||||||
|
|
||||||
SHADY_PAGES: Tuple[Type[Page], ...] = (
|
SHADY_PAGES: Set[Type[Page]] = {
|
||||||
Musify,
|
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
|
return old_object
|
||||||
|
|
||||||
|
|
||||||
class LoreIpsum:
|
class Page():
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
Parent = threading.Thread if THREADED else LoreIpsum
|
|
||||||
|
|
||||||
|
|
||||||
class Page(Parent):
|
|
||||||
"""
|
"""
|
||||||
This is an abstract class, laying out the
|
This is an abstract class, laying out the
|
||||||
functionality for every other class fetching something
|
functionality for every other class fetching something
|
||||||
@ -120,14 +113,21 @@ class Page(Parent):
|
|||||||
SOURCE_TYPE: SourcePages
|
SOURCE_TYPE: SourcePages
|
||||||
LOGGER = logging.getLogger("this shouldn't be used")
|
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):
|
def __init__(self, end_event: EndThread, search_queue: Queue, search_result_queue: Queue):
|
||||||
self.end_event = end_event
|
self.end_event = end_event
|
||||||
|
|
||||||
self.search_queue = search_queue
|
self.search_queue = search_queue
|
||||||
self.search_result_queue = search_result_queue
|
self.search_result_queue = search_result_queue
|
||||||
|
|
||||||
Parent.__init__(self)
|
super().__init__()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _empty_working_queues(self):
|
def _empty_working_queues(self):
|
||||||
return self.search_queue.empty()
|
return self.search_queue.empty()
|
||||||
@ -138,6 +138,7 @@ class Page(Parent):
|
|||||||
self.search(self.search_queue.get())
|
self.search(self.search_queue.get())
|
||||||
self.search_result_queue.put(FinishedSearch())
|
self.search_result_queue.put(FinishedSearch())
|
||||||
continue
|
continue
|
||||||
|
"""
|
||||||
|
|
||||||
def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]:
|
def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]:
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user