ytdl-sub/ytdl_subscribe/validators/base/string_datetime.py
2022-04-12 05:35:56 +00:00

26 lines
708 B
Python

from yt_dlp.utils import datetime_from_str
from ytdl_subscribe.validators.base.validators import Validator
from ytdl_subscribe.validators.exceptions import ValidationException
class StringDatetimeValidator(Validator):
"""
Validates a ytdl datetime string value
"""
_expected_value_type = str
_expected_value_type_name = "datetime string"
def __init__(self, name, value):
super().__init__(name, value)
try:
_ = datetime_from_str(self._value)
except Exception as exc:
raise ValidationException(exc) from exc
@property
def datetime_str(self) -> str:
"""Returns the datetime as a string"""
return self._value