Skip to content

A feature-rich command-line audio/video downloader

[utils] unified_strdate: Return None if the date format can't be recognized (fixes #7340)

Jaime Marquínez Ferrándiz6a750402787d
diff --git a/test/test_utils.py b/test/test_utils.py
index 3298315d24..01829f71e3 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -236,6 +236,7 @@ class TestUtil(unittest.TestCase):
unified_strdate('2/2/2015 6:47:40 PM', day_first=False),
'20150202')
self.assertEqual(unified_strdate('25-09-2014'), '20140925')
+ self.assertEqual(unified_strdate('UNKNOWN DATE FORMAT'), None)
def test_find_xpath_attr(self):
testxml = '''<root>
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 7b3f79141f..d39f313a41 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -911,7 +911,8 @@ def unified_strdate(date_str, day_first=True):
timetuple = email.utils.parsedate_tz(date_str)
if timetuple:
upload_date = datetime.datetime(*timetuple[:6]).strftime('%Y%m%d')
- return compat_str(upload_date)
+ if upload_date is not None:
+ return compat_str(upload_date)
def determine_ext(url, default_ext='unknown_video'):