tried multithreading, not worth it at the current point
This commit is contained in:
parent
6caa6a28a6
commit
e996bd4e4f
@ -1,26 +1,32 @@
|
|||||||
from typing import Tuple, Type, Dict
|
from typing import Tuple, Type, Dict, List
|
||||||
|
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 ..pages import Page, EncyclopaediaMetallum, Musify
|
from ..pages import Page, EncyclopaediaMetallum, Musify
|
||||||
|
|
||||||
|
ALL_PAGES: Tuple[Type[Page], ...] = (
|
||||||
NAME_PAGE_MAP: Dict[str, Page] = dict()
|
EncyclopaediaMetallum,
|
||||||
PAGE_NAME_MAP: Dict[Page, str] = dict()
|
Musify
|
||||||
SOURCE_PAGE_MAP: Dict[SourcePages, Page] = dict()
|
|
||||||
|
|
||||||
ALL_PAGES: Tuple[Page, ...] = (
|
|
||||||
EncyclopaediaMetallum(),
|
|
||||||
Musify())
|
|
||||||
)
|
)
|
||||||
|
|
||||||
AUDIO_PAGES: Tuple[Page, ...] = (
|
AUDIO_PAGES: Tuple[Type[Page], ...] = (
|
||||||
Musify(),
|
Musify,
|
||||||
)
|
)
|
||||||
|
|
||||||
SHADY_PAGES: Tuple[Page, ...] = (
|
SHADY_PAGES: Tuple[Type[Page], ...] = (
|
||||||
Musify(),
|
Musify,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
exit_threads = EndThread()
|
||||||
|
search_queue: Queue[Query] = Queue()
|
||||||
|
|
||||||
|
_page_threads: Dict[Type[Page], List[Page]] = dict()
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
# this needs to be case-insensitive
|
# this needs to be case-insensitive
|
||||||
SHORTHANDS = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')
|
SHORTHANDS = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')
|
||||||
for i, page in enumerate(ALL_PAGES):
|
for i, page in enumerate(ALL_PAGES):
|
||||||
@ -30,4 +36,4 @@ for i, page in enumerate(ALL_PAGES):
|
|||||||
PAGE_NAME_MAP[type(page)] = SHORTHANDS[i]
|
PAGE_NAME_MAP[type(page)] = SHORTHANDS[i]
|
||||||
|
|
||||||
SOURCE_PAGE_MAP[page.SOURCE_TYPE] = page
|
SOURCE_PAGE_MAP[page.SOURCE_TYPE] = page
|
||||||
|
"""
|
@ -24,8 +24,8 @@ from ..utils.enums.source import SourcePages
|
|||||||
from ..utils.enums.album import AlbumType
|
from ..utils.enums.album import AlbumType
|
||||||
from ..audio import write_metadata_to_target, correct_codec
|
from ..audio import write_metadata_to_target, correct_codec
|
||||||
from ..utils import shared
|
from ..utils import shared
|
||||||
from ..utils.shared import DEFAULT_VALUES, DOWNLOAD_PATH, DOWNLOAD_FILE
|
from ..utils.shared import DEFAULT_VALUES, DOWNLOAD_PATH, DOWNLOAD_FILE, THREADED
|
||||||
from ..utils.support_classes import Query, DownloadResult, DefaultTarget
|
from ..utils.support_classes import Query, DownloadResult, DefaultTarget, EndThread, FinishedSearch
|
||||||
|
|
||||||
|
|
||||||
INDEPENDENT_DB_OBJECTS = Union[Label, Album, Artist, Song]
|
INDEPENDENT_DB_OBJECTS = Union[Label, Album, Artist, Song]
|
||||||
@ -104,7 +104,14 @@ def merge_together(old_object: DatabaseObject, new_object: DatabaseObject) -> Da
|
|||||||
return old_object
|
return old_object
|
||||||
|
|
||||||
|
|
||||||
class Page(threading.Thread):
|
class LoreIpsum:
|
||||||
|
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
|
||||||
@ -113,14 +120,24 @@ class Page(threading.Thread):
|
|||||||
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, 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.search_queue = search_queue
|
self.search_queue = search_queue
|
||||||
self.search_result_queue = search_result_queue
|
self.search_result_queue = search_result_queue
|
||||||
|
|
||||||
threading.Thread.__init__(self)
|
Parent.__init__(self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _empty_working_queues(self):
|
||||||
|
return self.search_queue.empty()
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
pass
|
while bool(self.end_event) and self._empty_working_queues:
|
||||||
|
if not self.search_queue.empty():
|
||||||
|
self.search(self.search_queue.get())
|
||||||
|
self.search_result_queue.put(FinishedSearch())
|
||||||
|
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
|
||||||
@ -146,7 +163,9 @@ class Page(threading.Thread):
|
|||||||
|
|
||||||
r = []
|
r = []
|
||||||
for default_query in query.default_search:
|
for default_query in query.default_search:
|
||||||
r.extend(self.general_search(default_query))
|
for single_option in self.general_search(default_query):
|
||||||
|
r.append(single_option)
|
||||||
|
self.search_result_queue.put(single_option)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
@ -103,3 +103,5 @@ SORT_BY_DATE = AUDIO_SECTION.SORT_BY_DATE.object_from_value
|
|||||||
SORT_BY_ALBUM_TYPE = AUDIO_SECTION.SORT_BY_ALBUM_TYPE.object_from_value
|
SORT_BY_ALBUM_TYPE = AUDIO_SECTION.SORT_BY_ALBUM_TYPE.object_from_value
|
||||||
|
|
||||||
ALBUM_TYPE_BLACKLIST: Set[AlbumType] = set(AUDIO_SECTION.ALBUM_TYPE_BLACKLIST.object_from_value)
|
ALBUM_TYPE_BLACKLIST: Set[AlbumType] = set(AUDIO_SECTION.ALBUM_TYPE_BLACKLIST.object_from_value)
|
||||||
|
|
||||||
|
THREADED = False
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
from .default_target import DefaultTarget
|
from .default_target import DefaultTarget
|
||||||
from .download_result import DownloadResult
|
from .download_result import DownloadResult
|
||||||
from .query import Query
|
from .query import Query
|
||||||
|
from .thread_classes import EndThread, FinishedSearch
|
||||||
|
12
src/music_kraken/utils/support_classes/thread_classes.py
Normal file
12
src/music_kraken/utils/support_classes/thread_classes.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
class EndThread:
|
||||||
|
_has_ended: bool = False
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
return self._has_ended
|
||||||
|
|
||||||
|
def exit(self):
|
||||||
|
self._has_ended
|
||||||
|
|
||||||
|
class FinishedSearch:
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user