rclaudio: catch exception when parsing bad date, set date to the epoch

This commit is contained in:
Jean-Francois Dockes 2021-02-25 19:27:24 +01:00
parent f2407c3394
commit 31f6793495

View File

@ -255,6 +255,7 @@ class AudioTagExtractor(RclBaseHandler):
# was wrong, because dmtime is the unix integer time. We have # was wrong, because dmtime is the unix integer time. We have
# removed the alias, and set dmtime from the parsed date value. # removed the alias, and set dmtime from the parsed date value.
def parsedate(self, dt): def parsedate(self, dt):
try:
dt = dt.decode('utf-8', errors='ignore') dt = dt.decode('utf-8', errors='ignore')
if len(dt) > 10: if len(dt) > 10:
dt = dt[0:10] dt = dt[0:10]
@ -267,6 +268,8 @@ class AudioTagExtractor(RclBaseHandler):
pdt = datetime.datetime.strptime(dt, "%Y-%m-%d") pdt = datetime.datetime.strptime(dt, "%Y-%m-%d")
val = time.mktime(pdt.timetuple()) val = time.mktime(pdt.timetuple())
return "%d" % val return "%d" % val
except:
return 0
def html_text(self, filename): def html_text(self, filename):