From aafbba3b1cc5a38de1a3b16eab8dcb05393faafe Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 23 May 2024 14:36:19 +0200 Subject: [PATCH] feat: implemented consistent settings --- music_kraken/download/page_attributes.py | 2 +- music_kraken/pages/__init__.py | 5 ++--- music_kraken/pages/_abstract.py | 22 +++++++--------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/music_kraken/download/page_attributes.py b/music_kraken/download/page_attributes.py index 8be35b8..c897cfe 100644 --- a/music_kraken/download/page_attributes.py +++ b/music_kraken/download/page_attributes.py @@ -48,7 +48,7 @@ class Pages: self.download_options: DownloadOptions = download_options or DownloadOptions() self.fetch_options: FetchOptions = fetch_options or FetchOptions() - scan_for_pages() + scan_for_pages(download_options=self.download_options, fetch_options=self.fetch_options, **kwargs) def search(self, query: Query) -> SearchResults: result = SearchResults() diff --git a/music_kraken/pages/__init__.py b/music_kraken/pages/__init__.py index 5f82511..1e015a6 100644 --- a/music_kraken/pages/__init__.py +++ b/music_kraken/pages/__init__.py @@ -36,7 +36,7 @@ def deregister_page(page_type: Type[Page]): p.__del__() del _registered_pages[page_type] -def scan_for_pages(): +def scan_for_pages(**kwargs): # assuming the wanted pages are the leaf classes of the interface leaf_classes = [] @@ -51,6 +51,5 @@ def scan_for_pages(): else: _class_list.extend(_class_subclasses) - print(leaf_classes) for leaf_class in leaf_classes: - register_page(leaf_class) + register_page(leaf_class, **kwargs) diff --git a/music_kraken/pages/_abstract.py b/music_kraken/pages/_abstract.py index e6e35f7..2b76c59 100644 --- a/music_kraken/pages/_abstract.py +++ b/music_kraken/pages/_abstract.py @@ -1,15 +1,19 @@ +from __future__ import annotations + import logging import random import re from copy import copy from pathlib import Path -from typing import Optional, Union, Type, Dict, Set, List, Tuple, TypedDict +from typing import Optional, Union, Type, Dict, Set, List, Tuple, TypedDict, TYPE_CHECKING from string import Formatter from dataclasses import dataclass, field import requests from bs4 import BeautifulSoup +if TYPE_CHECKING: + from ..download.page_attributes import DownloadOptions, FetchOptions from ..connection import Connection from ..objects import ( Song, @@ -34,18 +38,6 @@ from ..utils import trace, output, BColors INDEPENDENT_DB_OBJECTS = Union[Label, Album, Artist, Song] INDEPENDENT_DB_TYPES = Union[Type[Song], Type[Album], Type[Artist], Type[Label]] -@dataclass -class FetchOptions: - download_all: bool = False - album_type_blacklist: Set[AlbumType] = field(default_factory=lambda: set(AlbumType(a) for a in main_settings["album_type_blacklist"])) - -@dataclass -class DownloadOptions: - download_all: bool = False - album_type_blacklist: Set[AlbumType] = field(default_factory=lambda: set(AlbumType(a) for a in main_settings["album_type_blacklist"])) - - process_audio_if_found: bool = False - process_metadata_if_found: bool = True class Page: REGISTER = True @@ -56,14 +48,14 @@ class Page: cls.LOGGER = logging.getLogger(cls.__name__) return super().__new__(cls) - def __init__(self, download_options: DownloadOptions = None, fetch_options: FetchOptions = None): + def __init__(self, download_options: DownloadOptions = None, fetch_options: FetchOptions = None, **kwargs): self.SOURCE_TYPE.register_page(self) self.download_options: DownloadOptions = download_options or DownloadOptions() self.fetch_options: FetchOptions = fetch_options or FetchOptions() def __del__(self): - self.SOURCE_TYPE.deregister_page(self) + self.SOURCE_TYPE.deregister_page() def _search_regex(self, pattern, string, default=None, fatal=True, flags=0, group=None): """