2024-04-26 04:09:50 +08:00
|
|
|
from abc import ABC
|
|
|
|
|
|
|
|
from pydantic import Field, PositiveInt, StringConstraints, field_validator
|
2023-08-09 01:53:56 +08:00
|
|
|
from typing_extensions import Annotated
|
2024-05-31 03:39:51 +08:00
|
|
|
from yt_shared.enums import DownMediaType, YtdlpReleaseChannelType
|
2024-04-26 04:09:50 +08:00
|
|
|
from yt_shared.schemas.base import StrictBaseConfigModel
|
2022-02-04 06:21:27 +08:00
|
|
|
|
2022-06-11 04:35:48 +08:00
|
|
|
_LANG_CODE_LEN = 2
|
2022-10-14 03:55:18 +08:00
|
|
|
_LANG_CODE_REGEX = rf'^[a-z]{{{_LANG_CODE_LEN}}}$'
|
2022-06-11 04:35:48 +08:00
|
|
|
|
2022-02-04 06:21:27 +08:00
|
|
|
|
2024-04-26 04:09:50 +08:00
|
|
|
class _BaseUserSchema(StrictBaseConfigModel, ABC):
|
|
|
|
id: int
|
2022-11-03 01:56:19 +08:00
|
|
|
|
2024-03-14 05:51:30 +08:00
|
|
|
|
|
|
|
class AnonymousUserSchema(_BaseUserSchema):
|
|
|
|
pass
|
2022-11-03 01:56:19 +08:00
|
|
|
|
|
|
|
|
2024-04-26 04:09:50 +08:00
|
|
|
class VideoCaptionSchema(StrictBaseConfigModel):
|
|
|
|
include_title: bool
|
|
|
|
include_filename: bool
|
|
|
|
include_link: bool
|
|
|
|
include_size: bool
|
2022-11-05 00:45:33 +08:00
|
|
|
|
|
|
|
|
2024-04-26 04:09:50 +08:00
|
|
|
class UploadSchema(StrictBaseConfigModel):
|
|
|
|
upload_video_file: bool
|
|
|
|
upload_video_max_file_size: PositiveInt
|
|
|
|
forward_to_group: bool
|
|
|
|
forward_group_id: int | None
|
|
|
|
silent: bool
|
2022-11-05 00:45:33 +08:00
|
|
|
video_caption: VideoCaptionSchema
|
2022-11-03 01:56:19 +08:00
|
|
|
|
|
|
|
|
2024-03-14 05:51:30 +08:00
|
|
|
class UserSchema(_BaseUserSchema):
|
2024-04-26 04:09:50 +08:00
|
|
|
is_admin: bool
|
|
|
|
send_startup_message: bool
|
|
|
|
download_media_type: Annotated[DownMediaType, Field(strict=False)]
|
|
|
|
save_to_storage: bool
|
|
|
|
use_url_regex_match: bool
|
2023-04-17 04:32:47 +08:00
|
|
|
upload: UploadSchema
|
2022-11-03 01:56:19 +08:00
|
|
|
|
|
|
|
|
2024-04-26 04:09:50 +08:00
|
|
|
class ApiSchema(StrictBaseConfigModel):
|
|
|
|
upload_video_file: bool
|
|
|
|
upload_video_max_file_size: PositiveInt
|
2023-04-17 04:32:47 +08:00
|
|
|
upload_to_chat_ids: list[AnonymousUserSchema]
|
2024-04-26 04:09:50 +08:00
|
|
|
silent: bool
|
2022-11-05 00:45:33 +08:00
|
|
|
video_caption: VideoCaptionSchema
|
2022-11-03 01:56:19 +08:00
|
|
|
|
2023-08-09 01:53:56 +08:00
|
|
|
@field_validator('upload_to_chat_ids', mode='before')
|
|
|
|
@classmethod
|
|
|
|
def transform_chat_ids(cls, values: list[int]) -> list[AnonymousUserSchema]:
|
|
|
|
return [AnonymousUserSchema(id=id_) for id_ in values]
|
2022-11-03 01:56:19 +08:00
|
|
|
|
|
|
|
|
2024-04-26 04:09:50 +08:00
|
|
|
class TelegramSchema(StrictBaseConfigModel):
|
|
|
|
api_id: int
|
|
|
|
api_hash: str
|
|
|
|
token: str
|
2023-08-09 01:53:56 +08:00
|
|
|
lang_code: Annotated[
|
|
|
|
str, StringConstraints(pattern=_LANG_CODE_REGEX, to_lower=True)
|
|
|
|
]
|
2024-04-26 04:09:50 +08:00
|
|
|
max_upload_tasks: PositiveInt
|
2023-03-29 03:26:16 +08:00
|
|
|
url_validation_regexes: list[str]
|
2022-11-03 01:56:19 +08:00
|
|
|
allowed_users: list[UserSchema]
|
|
|
|
api: ApiSchema
|
2022-02-04 06:21:27 +08:00
|
|
|
|
|
|
|
|
2024-04-26 04:09:50 +08:00
|
|
|
class YtdlpSchema(StrictBaseConfigModel):
|
|
|
|
version_check_enabled: bool
|
|
|
|
version_check_interval: PositiveInt
|
|
|
|
notify_users_on_new_version: bool
|
2024-05-31 03:39:51 +08:00
|
|
|
release_channel: Annotated[YtdlpReleaseChannelType, Field(strict=False)]
|
2022-11-08 03:25:11 +08:00
|
|
|
|
|
|
|
|
2024-04-26 04:09:50 +08:00
|
|
|
class ConfigSchema(StrictBaseConfigModel):
|
2022-02-04 06:21:27 +08:00
|
|
|
telegram: TelegramSchema
|
2022-11-08 03:25:11 +08:00
|
|
|
ytdlp: YtdlpSchema
|