diff --git a/syng/sources/filebased.py b/syng/sources/filebased.py index b51f561..ca031bf 100644 --- a/syng/sources/filebased.py +++ b/syng/sources/filebased.py @@ -35,10 +35,7 @@ class FileBasedSource(Source): "build_index": ConfigOption(BoolOption(), "Build index on startup", True), } - def __init__(self, config: dict[str, Any]): - """Initialize the file module.""" - super().__init__(config) - + def apply_config(self, config: dict[str, Any]) -> None: self.extensions: list[str] = config["extensions"] if "extensions" in config else ["mp3+cdg"] self.extra_mpv_options = {"scale": "oversample"} diff --git a/syng/sources/files.py b/syng/sources/files.py index c0cfe39..ee44049 100644 --- a/syng/sources/files.py +++ b/syng/sources/files.py @@ -25,10 +25,8 @@ class FilesSource(FileBasedSource): # "index_file": ("file", "Index file", os.path.join(user_cache_dir("syng"), "files-index")), } - def __init__(self, config: dict[str, Any]): - """Initialize the file module.""" - super().__init__(config) - + def apply_config(self, config: dict[str, Any]) -> None: + super().apply_config(config) self.dir = config["dir"] if "dir" in config else "." async def get_file_list(self) -> list[str]: diff --git a/syng/sources/s3.py b/syng/sources/s3.py index 9bb995f..cff8ac3 100644 --- a/syng/sources/s3.py +++ b/syng/sources/s3.py @@ -57,10 +57,8 @@ class S3Source(FileBasedSource): ), } - def __init__(self, config: dict[str, Any]): - """Create the source.""" - super().__init__(config) - + def apply_config(self, config: dict[str, Any]) -> None: + super().apply_config(config) if ( MINIO_AVAILABE and "endpoint" in config diff --git a/syng/sources/source.py b/syng/sources/source.py index 0aac58b..1457902 100644 --- a/syng/sources/source.py +++ b/syng/sources/source.py @@ -22,7 +22,6 @@ from typing import Type from abc import ABC, abstractmethod - from ..log import logger from ..entry import Entry from ..result import Result @@ -130,6 +129,7 @@ class Source(ABC): self.extra_mpv_options: dict[str, str] = {} self._skip_next = False self.build_index = config.get("build_index", False) + self.apply_config(config) async def get_entry( self, @@ -437,5 +437,18 @@ class Source(ABC): self._index = [] self._index += config["index"] + @abstractmethod + def apply_config(self, config: dict[str, Any]) -> None: + """ + Apply the a config to the source. + + This should be implemented by each source individually. + + :param config: The part of the config to apply. + :type config: dict[str, Any] + :rtype: None + """ + pass + available_sources: dict[str, Type[Source]] = {} diff --git a/syng/sources/youtube.py b/syng/sources/youtube.py index 7063497..c18fd34 100644 --- a/syng/sources/youtube.py +++ b/syng/sources/youtube.py @@ -193,16 +193,7 @@ class YoutubeSource(Source): ), } - # pylint: disable=too-many-instance-attributes - def __init__(self, config: dict[str, Any]): - """ - Create the YouTube source. - - :param config: The configuration for the source. - :type config: dict[str, Any] - """ - super().__init__(config) - + def apply_config(self, config: dict[str, Any]) -> None: self.channels: list[str] = config["channels"] if "channels" in config else [] self.tmp_dir: str = config["tmp_dir"] if "tmp_dir" in config else "/tmp/syng" try: