Add method apply_config to sources
This commit is contained in:
parent
de74d9ecd7
commit
0df93ac758
5 changed files with 20 additions and 23 deletions
|
@ -35,10 +35,7 @@ class FileBasedSource(Source):
|
||||||
"build_index": ConfigOption(BoolOption(), "Build index on startup", True),
|
"build_index": ConfigOption(BoolOption(), "Build index on startup", True),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, config: dict[str, Any]):
|
def apply_config(self, config: dict[str, Any]) -> None:
|
||||||
"""Initialize the file module."""
|
|
||||||
super().__init__(config)
|
|
||||||
|
|
||||||
self.extensions: list[str] = config["extensions"] if "extensions" in config else ["mp3+cdg"]
|
self.extensions: list[str] = config["extensions"] if "extensions" in config else ["mp3+cdg"]
|
||||||
self.extra_mpv_options = {"scale": "oversample"}
|
self.extra_mpv_options = {"scale": "oversample"}
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,8 @@ class FilesSource(FileBasedSource):
|
||||||
# "index_file": ("file", "Index file", os.path.join(user_cache_dir("syng"), "files-index")),
|
# "index_file": ("file", "Index file", os.path.join(user_cache_dir("syng"), "files-index")),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, config: dict[str, Any]):
|
def apply_config(self, config: dict[str, Any]) -> None:
|
||||||
"""Initialize the file module."""
|
super().apply_config(config)
|
||||||
super().__init__(config)
|
|
||||||
|
|
||||||
self.dir = config["dir"] if "dir" in config else "."
|
self.dir = config["dir"] if "dir" in config else "."
|
||||||
|
|
||||||
async def get_file_list(self) -> list[str]:
|
async def get_file_list(self) -> list[str]:
|
||||||
|
|
|
@ -57,10 +57,8 @@ class S3Source(FileBasedSource):
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, config: dict[str, Any]):
|
def apply_config(self, config: dict[str, Any]) -> None:
|
||||||
"""Create the source."""
|
super().apply_config(config)
|
||||||
super().__init__(config)
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
MINIO_AVAILABE
|
MINIO_AVAILABE
|
||||||
and "endpoint" in config
|
and "endpoint" in config
|
||||||
|
|
|
@ -22,7 +22,6 @@ from typing import Type
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from ..log import logger
|
from ..log import logger
|
||||||
from ..entry import Entry
|
from ..entry import Entry
|
||||||
from ..result import Result
|
from ..result import Result
|
||||||
|
@ -130,6 +129,7 @@ class Source(ABC):
|
||||||
self.extra_mpv_options: dict[str, str] = {}
|
self.extra_mpv_options: dict[str, str] = {}
|
||||||
self._skip_next = False
|
self._skip_next = False
|
||||||
self.build_index = config.get("build_index", False)
|
self.build_index = config.get("build_index", False)
|
||||||
|
self.apply_config(config)
|
||||||
|
|
||||||
async def get_entry(
|
async def get_entry(
|
||||||
self,
|
self,
|
||||||
|
@ -437,5 +437,18 @@ class Source(ABC):
|
||||||
self._index = []
|
self._index = []
|
||||||
self._index += config["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]] = {}
|
available_sources: dict[str, Type[Source]] = {}
|
||||||
|
|
|
@ -193,16 +193,7 @@ class YoutubeSource(Source):
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes
|
def apply_config(self, config: dict[str, Any]) -> None:
|
||||||
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)
|
|
||||||
|
|
||||||
self.channels: list[str] = config["channels"] if "channels" in config else []
|
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"
|
self.tmp_dir: str = config["tmp_dir"] if "tmp_dir" in config else "/tmp/syng"
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue