ytdl-sub/src/ytdl_sub/validators/string_datetime.py
Jesse Bannon e92b1cd12a
[BACKEND][HUGE] Function Support in variable syntax (#838)
A complete gutting of the internals of ytdl-sub to support functions in our variable syntax, in addition to being able to access a yt-dlp entry's .info.json fields using functions. Functionally, ytdl-sub should still look and behave the same from a user-perspective.

With so many lines of code changed (+8927, -2708), no doubt there will be new issues. Please make a GH issue or reach out on Discord if your config/subscriptions break in any way/shape/form.

Details on how to use function support will come soon in the form of proper documentation in our readthedocs.
2023-12-18 16:08:15 -08:00

27 lines
964 B
Python

from yt_dlp.utils import datetime_from_str
from ytdl_sub.validators.string_formatter_validators import OverridesStringFormatterValidator
class StringDatetimeValidator(OverridesStringFormatterValidator):
"""
String that contains a yt-dlp datetime. From their docs:
.. code-block:: Markdown
A string in the format YYYYMMDD or
(now|today|yesterday|date)[+-][0-9](microsecond|second|minute|hour|day|week|month|year)(s)
Valid examples are ``now-2weeks`` or ``20200101``. Can use override variables in this.
Note that yt-dlp will round times to the closest day, meaning that `day` is the lowest
granularity possible.
"""
_expected_value_type_name = "datetime string"
def post_process(self, resolved: str) -> str:
try:
_ = datetime_from_str(resolved)
except Exception as exc:
raise self._validation_exception(f"Invalid datetime string: {str(exc)}")
return resolved