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

79 lines
1.8 KiB
Python
Raw Normal View History

2022-11-03 01:56:19 +08:00
from pydantic import (
StrictBool,
StrictInt,
StrictStr,
constr,
validator,
)
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
2022-11-03 01:56:19 +08:00
class BaseUserSchema(RealBaseModel):
id: StrictInt
@property
2022-11-05 00:45:33 +08:00
def is_base_user(self) -> bool:
2022-11-03 01:56:19 +08:00
return True
2022-11-05 00:45:33 +08:00
class VideoCaptionSchema(RealBaseModel):
include_title: StrictBool
include_filename: StrictBool
include_link: StrictBool
2022-11-03 01:56:19 +08:00
class UserUploadSchema(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
class UserSchema(BaseUserSchema):
send_startup_message: StrictBool
2022-11-03 01:56:19 +08:00
upload: UserUploadSchema
@property
2022-11-05 00:45:33 +08:00
def is_base_user(self) -> bool:
2022-11-03 01:56:19 +08:00
return False
2022-11-06 04:20:27 +08:00
def _change_type(values: list[int]) -> list[BaseUserSchema]:
2022-11-03 01:56:19 +08:00
return [BaseUserSchema(id=id_) for id_ in values]
class ApiSchema(RealBaseModel):
upload_video_file: StrictBool
2022-11-03 01:56:19 +08:00
upload_video_max_file_size: StrictInt
upload_to_chat_ids: list[BaseUserSchema]
silent: StrictBool
2022-11-05 00:45:33 +08:00
video_caption: VideoCaptionSchema
2022-11-03 01:56:19 +08:00
2022-11-06 04:20:27 +08:00
_transform_chat_ids = validator('upload_to_chat_ids', pre=True)(_change_type)
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
2022-06-11 04:35:48 +08:00
lang_code: constr(regex=_LANG_CODE_REGEX, to_lower=True)
2022-11-05 00:45:33 +08:00
max_upload_tasks: StrictInt
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