Skip to content

Bulk asynchronous downloader for multiple file hosts

fix: move pydantic file (#658)

datawhores852394848850
diff --git a/cyberdrop_dl/config_definitions/custom/types.py b/cyberdrop_dl/config_definitions/custom/types.py
index 5674579fa..e91f70fd3 100644
--- a/cyberdrop_dl/config_definitions/custom/types.py
+++ b/cyberdrop_dl/config_definitions/custom/types.py
@@ -26,9 +26,11 @@ from .validators import parse_apprise_url, parse_falsy_as_none, parse_list
if TYPE_CHECKING:
from yarl import URL
+StrSerializer = PlainSerializer(str, return_type=str, when_used="json-unless-none")
+
ByteSizeSerilized = Annotated[ByteSize, PlainSerializer(convert_byte_size_to_str, return_type=str)]
-HttpURL = Annotated[HttpUrl, AfterValidator(convert_to_yarl)]
+HttpURL = Annotated[HttpUrl, AfterValidator(convert_to_yarl), StrSerializer]
ListNonNegativeInt = Annotated[list[NonNegativeInt], BeforeValidator(parse_list)]
NonEmptyStr = Annotated[str, StringConstraints(min_length=1, strip_whitespace=True)]
diff --git a/cyberdrop_dl/config_definitions/pydantic/custom_types.py b/cyberdrop_dl/config_definitions/pydantic/custom_types.py
deleted file mode 100644
index dd326dea9..000000000
--- a/cyberdrop_dl/config_definitions/pydantic/custom_types.py
+++ /dev/null
@@ -1,74 +0,0 @@
-from __future__ import annotations
-
-from typing import Annotated
-
-from pydantic import (
- AfterValidator,
- AnyUrl,
- BaseModel,
- ConfigDict,
- HttpUrl,
- PlainSerializer,
- Secret,
- SerializationInfo,
- StringConstraints,
- model_serializer,
- model_validator,
-)
-from yarl import URL
-
-
-def convert_to_yarl(value: AnyUrl) -> URL:
- return URL(str(value))
-
-
-StrSerializer = PlainSerializer(str, return_type=str, when_used="json-unless-none")
-
-HttpURL = Annotated[HttpUrl, AfterValidator(convert_to_yarl), StrSerializer]
-NonEmptyStr = Annotated[str, StringConstraints(min_length=1, strip_whitespace=True)]
-AnyURL = Annotated[AnyUrl, AfterValidator(convert_to_yarl), StrSerializer]
-SecretAnyURL = Secret[AnyURL]
-SecretHttpURL = Secret[HttpURL]
-
-
-class AliasModel(BaseModel):
- model_config = ConfigDict(populate_by_name=True)
-
-
-class FrozenModel(BaseModel):
- model_config = ConfigDict(frozen=True)
-
-
-class AppriseURLModel(FrozenModel):
- url: Secret[AnyUrl]
- tags: set[str]
-
- @model_serializer()
- def serialize(self, info: SerializationInfo):
- dump_secret = info.mode != "json"
- url = self.url.get_secret_value() if dump_secret else self.url
- tags = self.tags - set("no_logs")
- tags = sorted(tags)
- return f"{','.join(tags)}{'=' if tags else ''}{url}"
-
- @model_validator(mode="before")
- @staticmethod
- def parse_input(value: dict | URL | str):
- url = value
- tags = set()
- if isinstance(value, dict):
- tags = value.get("tags") or tags
- url = value.get("url", "")
-
- if isinstance(url, URL):
- url = str(url)
- parts = url.split("://", 1)[0].split("=", 1)
- if len(parts) == 2:
- tags = set(parts[0].split(","))
- url: str = url.split("=", 1)[-1]
-
- return {"url": url, "tags": tags}
-
-
-class HttpAppriseURL(AppriseURLModel):
- url: Secret[HttpURL]