Skip to content

Bulk asynchronous downloader for multiple file hosts

fix: handle changes in supported sites (config values) (#646)

NTFSvolume42a4230aac6b
diff --git a/cyberdrop_dl/config_definitions/config_settings.py b/cyberdrop_dl/config_definitions/config_settings.py
index 27cf80b27..5de842a11 100644
--- a/cyberdrop_dl/config_definitions/config_settings.py
+++ b/cyberdrop_dl/config_definitions/config_settings.py
@@ -1,9 +1,8 @@
from datetime import timedelta
from logging import DEBUG
from pathlib import Path
-from typing import Literal
-from pydantic import BaseModel, ByteSize, Field, NonNegativeInt, PositiveInt, field_validator
+from pydantic import BaseModel, ByteSize, Field, NonNegativeInt, PositiveInt, field_serializer, field_validator
from cyberdrop_dl.utils.constants import APP_STORAGE, BROWSERS, DOWNLOAD_STORAGE
from cyberdrop_dl.utils.data_enums_classes.hash import Hashing
@@ -23,6 +22,8 @@ from .custom.types import (
)
from .custom.validators import parse_duration_as_timedelta, parse_falsy_as
+ALL_SUPPORTED_SITES = ["<<ALL_SUPPORTED_SITES>>"]
+
class DownloadOptions(BaseModel):
block_download_sub_folders: bool = False
@@ -140,14 +141,30 @@ class Sorting(BaseModel):
class BrowserCookies(BaseModel):
auto_import: bool = False
browsers: list[BROWSERS] = [BROWSERS.chrome]
- sites: list[Literal[*SUPPORTED_SITES_DOMAINS]] = SUPPORTED_SITES_DOMAINS # type: ignore
+ sites: list[NonEmptyStr] = SUPPORTED_SITES_DOMAINS
+
+ @field_validator("browsers", mode="before")
+ @classmethod
+ def parse_browsers(cls, values: list) -> list:
+ values = parse_falsy_as(values, [])
+ if isinstance(values, list):
+ return sorted(str(value).lower() for value in values)
+ return values
- @field_validator("browsers", "sites", mode="before")
+ @field_validator("sites", mode="before")
@classmethod
def handle_list(cls, values: list) -> list:
values = parse_falsy_as(values, [])
+ if values == ALL_SUPPORTED_SITES:
+ return SUPPORTED_SITES_DOMAINS
if isinstance(values, list):
- return [str(value).lower() for value in values]
+ return sorted(str(value).lower() for value in values)
+ return values
+
+ @field_serializer("sites", when_used="json-unless-none")
+ def use_placeholder(self, values: list) -> list:
+ if set(values) == set(SUPPORTED_SITES_DOMAINS):
+ return ALL_SUPPORTED_SITES
return values
diff --git a/docs/reference/configuration-options/settings/browser_cookies.md b/docs/reference/configuration-options/settings/browser_cookies.md
index 1f44a8221..59a9313b6 100644
--- a/docs/reference/configuration-options/settings/browser_cookies.md
+++ b/docs/reference/configuration-options/settings/browser_cookies.md
@@ -52,9 +52,9 @@ If the value entered is `null` or an empty list, no cookies will be extracted fr
| Type | Default |
| --------------- | --------------- |
-| `list[DOMAINS]` | `[<ALL_SITES>]` |
+| `list[DOMAINS]` | `[<<ALL_SUPPORTED_SITES>>]` |
-List of domains to extract cookies from. You can put any domain on the list, but only sites supported by Cyberdrop-DL will be taken into account
+List of domains to extract cookies from. You can put any domain on the list, even if they are not officially supported
## Manual Cookie Extraction