From de74d9ecd79347c2a53e8a0b247d89f4c0899dbf Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Sun, 2 Feb 2025 23:45:47 +0100 Subject: [PATCH] Specify if config options should be send to the server --- syng/config.py | 1 + syng/sources/source.py | 10 ++++++++++ syng/sources/youtube.py | 20 +++++++++++--------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/syng/config.py b/syng/config.py index fb519d1..f271ad3 100644 --- a/syng/config.py +++ b/syng/config.py @@ -13,6 +13,7 @@ class ConfigOption(Generic[T]): type: Option[T] description: str default: T + send_to_server: bool = False class BoolOption(Option[bool]): diff --git a/syng/sources/source.py b/syng/sources/source.py index a5aa9a1..0aac58b 100644 --- a/syng/sources/source.py +++ b/syng/sources/source.py @@ -123,6 +123,7 @@ class Source(ABC): source for documentation. :type config: dict[str, Any] """ + self.config: dict[str, Any] = config self.downloaded_files: defaultdict[str, DLFilesEntry] = defaultdict(DLFilesEntry) self._masterlock: asyncio.Lock = asyncio.Lock() self._index: list[str] = config["index"] if "index" in config else [] @@ -401,6 +402,15 @@ class Source(ABC): logger.warning(f"{self.source_name}: done") chunked = zip_longest(*[iter(self._index)] * 1000, fillvalue="") packages = [{"index": list(filter(lambda x: x != "", chunk))} for chunk in chunked] + first_package = { + key: value + for key, value in self.config.items() + if self.config_schema[key].send_to_server + } + if not packages: + packages = [first_package] + else: + packages[0] |= first_package if len(packages) == 1: return first_package return packages diff --git a/syng/sources/youtube.py b/syng/sources/youtube.py index b912d2d..7063497 100644 --- a/syng/sources/youtube.py +++ b/syng/sources/youtube.py @@ -175,7 +175,9 @@ class YoutubeSource(Source): source_name = "youtube" config_schema = Source.config_schema | { "enabled": ConfigOption(BoolOption(), "Enable this source", True), - "channels": ConfigOption(ListStrOption(), "A list channels\nto search in", []), + "channels": ConfigOption( + ListStrOption(), "A list channels\nto search in", [], send_to_server=True + ), "tmp_dir": ConfigOption( FolderOption(), "Folder for\ntemporary download", user_cache_dir("syng") ), @@ -222,14 +224,14 @@ class YoutubeSource(Source): } ) - async def get_config(self) -> dict[str, Any] | list[dict[str, Any]]: - """ - Return the list of channels in a dictionary with key ``channels``. - - :return: see above - :rtype: dict[str, Any]] - """ - return {"channels": self.channels} + # async def get_config(self) -> dict[str, Any] | list[dict[str, Any]]: + # """ + # Return the list of channels in a dictionary with key ``channels``. + # + # :return: see above + # :rtype: dict[str, Any]] + # """ + # return {"channels": self.channels} async def ensure_playable(self, entry: Entry) -> tuple[str, Optional[str]]: """