From 4d64bc52517256e1fbdb365b24e5f728ff392493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20K=C3=B6nig?= Date: Mon, 21 May 2018 01:20:05 +0200 Subject: [PATCH] handle wrong formatted date argument The provided date argument (--date, --datebefore or --dateafter) is parsed by datetimp.strptime(). This function throws as ValueError exception at failure. This patch implements exception handling by catching the ValueError exception, printing an error message and exiting with a non-zero exit code. --- youtube_dl/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index f9ca63c58..a87509e39 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1270,7 +1270,10 @@ def date_from_str(date_str): unit += 's' delta = datetime.timedelta(**{unit: time}) return today + delta - return datetime.datetime.strptime(date_str, '%Y%m%d').date() + try: + return datetime.datetime.strptime(date_str, '%Y%m%d').date() + except ValueError: + sys.exit('ERROR: cannot parse datestring ' + date_str) def hyphenate_date(date_str):