[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
This commit is contained in:
parent
1a118e225a
commit
3c87dc9f8e
2 changed files with 18 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ from typing import Tuple
|
||||||
|
|
||||||
from ytdl_sub.config.plugin import Plugin
|
from ytdl_sub.config.plugin import Plugin
|
||||||
from ytdl_sub.config.preset_options import OptionsDictValidator
|
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
|
from ytdl_sub.validators.string_datetime import StringDatetimeValidator
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -57,11 +58,15 @@ class DateRangePlugin(Plugin[DateRangeOptions]):
|
||||||
breaking_match_filters: List[str] = []
|
breaking_match_filters: List[str] = []
|
||||||
|
|
||||||
if self.plugin_options.before:
|
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}")
|
match_filters.append(f"upload_date < {before_str}")
|
||||||
|
|
||||||
if self.plugin_options.after:
|
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}")
|
breaking_match_filters.append(f"upload_date >= {after_str}")
|
||||||
|
|
||||||
return match_filters, breaking_match_filters
|
return match_filters, breaking_match_filters
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from yt_dlp import DateRange
|
from yt_dlp import DateRange
|
||||||
|
from yt_dlp.utils import datetime_from_str
|
||||||
|
|
||||||
from ytdl_sub.config.preset_options import Overrides
|
from ytdl_sub.config.preset_options import Overrides
|
||||||
from ytdl_sub.validators.string_datetime import StringDatetimeValidator
|
from ytdl_sub.validators.string_datetime import StringDatetimeValidator
|
||||||
|
|
@ -29,3 +30,13 @@ def to_date_range(
|
||||||
return DateRange(start=start, end=end)
|
return DateRange(start=start, end=end)
|
||||||
|
|
||||||
return None
|
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")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue