From 3c87dc9f8e0a74e9d6e0c59570d48cb73c3362c6 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Wed, 20 Sep 2023 08:30:29 -0700 Subject: [PATCH] [BUGFIX] Fix date_range plugin as a match-filter (#726) Bugfix to the prior release. Convert yt-dlp date formats (i.e. `today-2months`) into a date string with format `YYYYMMDD`. This will make it compatible with match-filter syntax --- src/ytdl_sub/plugins/date_range.py | 9 +++++++-- src/ytdl_sub/utils/datetime.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ytdl_sub/plugins/date_range.py b/src/ytdl_sub/plugins/date_range.py index ca86e27b..1d93a483 100644 --- a/src/ytdl_sub/plugins/date_range.py +++ b/src/ytdl_sub/plugins/date_range.py @@ -4,6 +4,7 @@ from typing import Tuple from ytdl_sub.config.plugin import Plugin from ytdl_sub.config.preset_options import OptionsDictValidator +from ytdl_sub.utils.datetime import to_date_str from ytdl_sub.validators.string_datetime import StringDatetimeValidator @@ -57,11 +58,15 @@ class DateRangePlugin(Plugin[DateRangeOptions]): breaking_match_filters: List[str] = [] if self.plugin_options.before: - before_str = self.overrides.apply_formatter(formatter=self.plugin_options.before) + before_str = to_date_str( + date_validator=self.plugin_options.before, overrides=self.overrides + ) match_filters.append(f"upload_date < {before_str}") if self.plugin_options.after: - after_str = self.overrides.apply_formatter(formatter=self.plugin_options.after) + after_str = to_date_str( + date_validator=self.plugin_options.after, overrides=self.overrides + ) breaking_match_filters.append(f"upload_date >= {after_str}") return match_filters, breaking_match_filters diff --git a/src/ytdl_sub/utils/datetime.py b/src/ytdl_sub/utils/datetime.py index d7b1e07a..07fcaacf 100644 --- a/src/ytdl_sub/utils/datetime.py +++ b/src/ytdl_sub/utils/datetime.py @@ -1,6 +1,7 @@ from typing import Optional from yt_dlp import DateRange +from yt_dlp.utils import datetime_from_str from ytdl_sub.config.preset_options import Overrides from ytdl_sub.validators.string_datetime import StringDatetimeValidator @@ -29,3 +30,13 @@ def to_date_range( return DateRange(start=start, end=end) return None + + +def to_date_str(date_validator: StringDatetimeValidator, overrides: Overrides) -> str: + """ + Returns + ------- + Date in the form of YYYYMMDD as a string + """ + date_str = overrides.apply_formatter(formatter=date_validator) + return datetime_from_str(date_str).date().strftime("%Y%m%d")