Specify if config options should be send to the server

This commit is contained in:
Christoph Stahl 2025-02-02 23:45:47 +01:00
parent dfbecc1517
commit de74d9ecd7
3 changed files with 22 additions and 9 deletions

View file

@ -13,6 +13,7 @@ class ConfigOption(Generic[T]):
type: Option[T] type: Option[T]
description: str description: str
default: T default: T
send_to_server: bool = False
class BoolOption(Option[bool]): class BoolOption(Option[bool]):

View file

@ -123,6 +123,7 @@ class Source(ABC):
source for documentation. source for documentation.
:type config: dict[str, Any] :type config: dict[str, Any]
""" """
self.config: dict[str, Any] = config
self.downloaded_files: defaultdict[str, DLFilesEntry] = defaultdict(DLFilesEntry) self.downloaded_files: defaultdict[str, DLFilesEntry] = defaultdict(DLFilesEntry)
self._masterlock: asyncio.Lock = asyncio.Lock() self._masterlock: asyncio.Lock = asyncio.Lock()
self._index: list[str] = config["index"] if "index" in config else [] 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") logger.warning(f"{self.source_name}: done")
chunked = zip_longest(*[iter(self._index)] * 1000, fillvalue="") chunked = zip_longest(*[iter(self._index)] * 1000, fillvalue="")
packages = [{"index": list(filter(lambda x: x != "", chunk))} for chunk in chunked] 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: if len(packages) == 1:
return first_package return first_package
return packages return packages

View file

@ -175,7 +175,9 @@ class YoutubeSource(Source):
source_name = "youtube" source_name = "youtube"
config_schema = Source.config_schema | { config_schema = Source.config_schema | {
"enabled": ConfigOption(BoolOption(), "Enable this source", True), "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( "tmp_dir": ConfigOption(
FolderOption(), "Folder for\ntemporary download", user_cache_dir("syng") 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]]: # async def get_config(self) -> dict[str, Any] | list[dict[str, Any]]:
""" # """
Return the list of channels in a dictionary with key ``channels``. # Return the list of channels in a dictionary with key ``channels``.
#
:return: see above # :return: see above
:rtype: dict[str, Any]] # :rtype: dict[str, Any]]
""" # """
return {"channels": self.channels} # return {"channels": self.channels}
async def ensure_playable(self, entry: Entry) -> tuple[str, Optional[str]]: async def ensure_playable(self, entry: Entry) -> tuple[str, Optional[str]]:
""" """