progress on threading

This commit is contained in:
Hellow2 2023-05-25 13:46:47 +02:00
parent 1362f708e6
commit 6caa6a28a6
6 changed files with 15 additions and 11 deletions

View File

@ -10,7 +10,7 @@ SOURCE_PAGE_MAP: Dict[SourcePages, Page] = dict()
ALL_PAGES: Tuple[Page, ...] = (
EncyclopaediaMetallum(),
Musify()
Musify())
)
AUDIO_PAGES: Tuple[Page, ...] = (
@ -27,7 +27,7 @@ for i, page in enumerate(ALL_PAGES):
NAME_PAGE_MAP[type(page).__name__.lower()] = page
NAME_PAGE_MAP[SHORTHANDS[i].lower()] = page
PAGE_NAME_MAP[page] = SHORTHANDS[i]
PAGE_NAME_MAP[type(page)] = SHORTHANDS[i]
SOURCE_PAGE_MAP[page.SOURCE_TYPE] = page

View File

@ -203,7 +203,7 @@ class Search(Download):
page = self._get_page_from_source(source=source)
if page in self.audio_pages:
return page.download(music_object=self._current_option._derive_from, genre=genre, download_all=download_all, **kwargs)
return page.download(music_object=self._current_option._derive_from, genre=genre, download_all=download_all)
return DownloadResult(error_message=f"Didn't find a source for {self._current_option._derive_from.option_string}.")

View File

@ -3,6 +3,7 @@ import random
from copy import copy
from typing import Optional, Union, Type, Dict, Set, List
import threading
from queue import Queue
import requests
from bs4 import BeautifulSoup
@ -112,7 +113,10 @@ class Page(threading.Thread):
SOURCE_TYPE: SourcePages
LOGGER = logging.getLogger("this shouldn't be used")
def __init__(self):
def __init__(self, search_queue: Queue, search_result_queue: Queue):
self.search_queue = search_queue
self.search_result_queue = search_result_queue
threading.Thread.__init__(self)
def run(self) -> None:

View File

@ -110,13 +110,13 @@ class EncyclopaediaMetallum(Page):
SOURCE_TYPE = SourcePages.ENCYCLOPAEDIA_METALLUM
LOGGER = ENCYCLOPAEDIA_METALLUM_LOGGER
def __init__(self):
def __init__(self, **kwargs):
self.connection: Connection = Connection(
host="https://www.metal-archives.com/",
logger=ENCYCLOPAEDIA_METALLUM_LOGGER
)
super().__init__()
super().__init__(**kwargs)
def song_search(self, song: Song) -> List[Song]:
endpoint = "https://www.metal-archives.com/search/ajax-advanced/searching/songs/?songTitle={song}&bandName={" \

View File

@ -115,13 +115,13 @@ class Musify(Page):
HOST = "https://musify.club"
def __init__(self):
def __init__(self, *args, **kwargs):
self.connection: Connection = Connection(
host="https://musify.club/",
logger=self.LOGGER
)
super().__init__()
super().__init__(*args, **kwargs)
def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]:
if source.url is None:

View File

@ -20,13 +20,13 @@ class Preset(Page):
SOURCE_TYPE = SourcePages.PRESET
LOGGER = logging.getLogger("preset")
def __init__(self):
def __init__(self, *args, **kwargs):
self.connection: Connection = Connection(
host="https://www.preset.cum/",
logger=self.LOGGER
)
super().__init__()
super().__init__(*args, **kwargs)
def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]:
return super().get_source_type(source)