2023-05-26 08:11:36 +00:00
|
|
|
from typing import Tuple, Type, Dict, List, Set
|
2023-03-28 10:50:23 +00:00
|
|
|
|
2023-05-23 11:59:24 +00:00
|
|
|
from ..utils.enums.source import SourcePages
|
2023-05-26 07:00:02 +00:00
|
|
|
from ..utils.support_classes import Query, EndThread
|
2023-05-23 11:59:24 +00:00
|
|
|
from ..pages import Page, EncyclopaediaMetallum, Musify
|
|
|
|
|
2023-05-26 08:11:36 +00:00
|
|
|
ALL_PAGES: Set[Type[Page]] = {
|
2023-05-26 07:00:02 +00:00
|
|
|
EncyclopaediaMetallum,
|
|
|
|
Musify
|
2023-05-26 08:11:36 +00:00
|
|
|
}
|
2023-03-28 12:04:15 +00:00
|
|
|
|
2023-05-26 08:11:36 +00:00
|
|
|
AUDIO_PAGES: Set[Type[Page]] = {
|
2023-05-26 07:00:02 +00:00
|
|
|
Musify,
|
2023-05-26 08:11:36 +00:00
|
|
|
}
|
2023-03-28 12:04:15 +00:00
|
|
|
|
2023-05-26 08:11:36 +00:00
|
|
|
SHADY_PAGES: Set[Type[Page]] = {
|
2023-05-26 07:00:02 +00:00
|
|
|
Musify,
|
2023-05-26 08:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2023-05-26 07:00:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
"""
|
2023-05-23 15:53:03 +00:00
|
|
|
# this needs to be case-insensitive
|
2023-03-29 13:22:18 +00:00
|
|
|
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):
|
2023-05-23 15:53:03 +00:00
|
|
|
NAME_PAGE_MAP[type(page).__name__.lower()] = page
|
2023-03-30 07:01:09 +00:00
|
|
|
NAME_PAGE_MAP[SHORTHANDS[i].lower()] = page
|
2023-03-29 13:22:18 +00:00
|
|
|
|
2023-05-25 11:46:47 +00:00
|
|
|
PAGE_NAME_MAP[type(page)] = SHORTHANDS[i]
|
2023-03-30 10:09:36 +00:00
|
|
|
|
|
|
|
SOURCE_PAGE_MAP[page.SOURCE_TYPE] = page
|
2023-05-26 07:00:02 +00:00
|
|
|
"""
|