Specify if config options should be send to the server
This commit is contained in:
parent
dfbecc1517
commit
de74d9ecd7
3 changed files with 22 additions and 9 deletions
syng
|
@ -13,6 +13,7 @@ class ConfigOption(Generic[T]):
|
|||
type: Option[T]
|
||||
description: str
|
||||
default: T
|
||||
send_to_server: bool = False
|
||||
|
||||
|
||||
class BoolOption(Option[bool]):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]]:
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue