yt-dlp-bot/app_bot/bot/core/schema.py

86 lines
2.1 KiB
Python
Raw Normal View History

2024-03-14 05:51:30 +08:00
import abc
2022-11-03 01:56:19 +08:00
from pydantic import (
StrictBool,
StrictInt,
StrictStr,
2023-08-09 01:53:56 +08:00
StringConstraints,
field_validator,
2022-11-03 01:56:19 +08:00
)
2023-08-09 01:53:56 +08:00
from typing_extensions import Annotated
from yt_shared.enums import DownMediaType
2022-02-04 06:21:27 +08:00
from yt_shared.schemas.base import RealBaseModel
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-03-14 05:51:30 +08:00
class _BaseUserSchema(RealBaseModel, abc.ABC):
2022-11-03 01:56:19 +08:00
id: StrictInt
2024-03-14 05:51:30 +08:00
class AnonymousUserSchema(_BaseUserSchema):
pass
2022-11-03 01:56:19 +08:00
2022-11-05 00:45:33 +08:00
class VideoCaptionSchema(RealBaseModel):
include_title: StrictBool
include_filename: StrictBool
include_link: StrictBool
2023-03-11 06:13:16 +08:00
include_size: StrictBool
2022-11-05 00:45:33 +08:00
2023-04-17 04:32:47 +08:00
class UploadSchema(RealBaseModel):
upload_video_file: StrictBool
2022-11-03 01:56:19 +08:00
upload_video_max_file_size: StrictInt
forward_to_group: StrictBool
forward_group_id: StrictInt | None
silent: StrictBool
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):
2023-11-11 21:09:14 +08:00
is_admin: StrictBool
send_startup_message: StrictBool
download_media_type: DownMediaType
save_to_storage: StrictBool
2023-03-29 03:26:16 +08:00
use_url_regex_match: StrictBool
2023-04-17 04:32:47 +08:00
upload: UploadSchema
2022-11-03 01:56:19 +08:00
class ApiSchema(RealBaseModel):
upload_video_file: StrictBool
2022-11-03 01:56:19 +08:00
upload_video_max_file_size: StrictInt
2023-04-17 04:32:47 +08:00
upload_to_chat_ids: list[AnonymousUserSchema]
2022-11-03 01:56:19 +08:00
silent: StrictBool
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
2022-02-04 06:21:27 +08:00
class TelegramSchema(RealBaseModel):
2022-06-11 04:35:48 +08:00
api_id: StrictInt
api_hash: StrictStr
2022-02-04 06:21:27 +08:00
token: StrictStr
2023-08-09 01:53:56 +08:00
lang_code: Annotated[
str, StringConstraints(pattern=_LANG_CODE_REGEX, to_lower=True)
]
2022-11-05 00:45:33 +08:00
max_upload_tasks: StrictInt
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
class YtdlpSchema(RealBaseModel):
version_check_enabled: StrictBool
version_check_interval: StrictInt
notify_users_on_new_version: StrictBool
2022-02-04 06:21:27 +08:00
class ConfigSchema(RealBaseModel):
telegram: TelegramSchema
ytdlp: YtdlpSchema