From 3d38b2d6d014b8b0d90e72213420441634744efb Mon Sep 17 00:00:00 2001 From: pukkandan Date: Wed, 11 May 2022 05:52:31 +0530 Subject: [PATCH] Fix `--date today` Closes #3704 --- README.md | 3 ++- yt_dlp/options.py | 5 ++--- yt_dlp/utils.py | 30 ++++++++++++++---------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f8813cbb6d..a9a9a4c639 100644 --- a/README.md +++ b/README.md @@ -427,7 +427,8 @@ You can also fork the project on github and run your fork's [build workflow](.gi (e.g. 50k or 44.6m) --date DATE Download only videos uploaded on this date. The date can be "YYYYMMDD" or in the format - "(now|today)[+-][0-9](day|week|month|year)(s)?" + [now|today|yesterday][-N[day|week|month|year]]. + Eg: --date today-2weeks --datebefore DATE Download only videos uploaded on or before this date. The date formats accepted is the same as --date diff --git a/yt_dlp/options.py b/yt_dlp/options.py index 60f8665705..8a91952170 100644 --- a/yt_dlp/options.py +++ b/yt_dlp/options.py @@ -435,9 +435,8 @@ def create_parser(): '--date', metavar='DATE', dest='date', default=None, help=( - 'Download only videos uploaded on this date. ' - 'The date can be "YYYYMMDD" or in the format ' - '"(now|today)[+-][0-9](day|week|month|year)(s)?"')) + 'Download only videos uploaded on this date. The date can be "YYYYMMDD" or in the format ' + '[now|today|yesterday][-N[day|week|month|year]]. Eg: --date today-2weeks')) selection.add_option( '--datebefore', metavar='DATE', dest='datebefore', default=None, diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index e683eaaf1a..ba73c2191d 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -1756,14 +1756,14 @@ def subtitles_filename(filename, sub_lang, sub_format, expected_real_ext=None): def datetime_from_str(date_str, precision='auto', format='%Y%m%d'): - """ - Return a datetime object from a string in the format YYYYMMDD or - (now|today|yesterday|date)[+-][0-9](microsecond|second|minute|hour|day|week|month|year)(s)? + R""" + Return a datetime object from a string. + Supported format: + (now|today|yesterday|DATE)([+-]\d+(microsecond|second|minute|hour|day|week|month|year)s?)? - format: string date format used to return datetime object from - precision: round the time portion of a datetime object. - auto|microsecond|second|minute|hour|day. - auto: round to the unit provided in date_str (if applicable). + @param format strftime format of DATE + @param precision Round the datetime object: auto|microsecond|second|minute|hour|day + auto: round to the unit provided in date_str (if applicable). """ auto_precision = False if precision == 'auto': @@ -1775,7 +1775,7 @@ def datetime_from_str(date_str, precision='auto', format='%Y%m%d'): if date_str == 'yesterday': return today - datetime.timedelta(days=1) match = re.match( - r'(?P.+)(?P[+-])(?P