From 1d02fccce695a2e2690cef28642d0a2ebfeea54d Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 25 Feb 2020 20:19:59 -0500 Subject: [PATCH] Prevent harmless errors about bad dates from the server --- jellyfin_kodi/helper/utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jellyfin_kodi/helper/utils.py b/jellyfin_kodi/helper/utils.py index 48c88724..f6b6f8af 100644 --- a/jellyfin_kodi/helper/utils.py +++ b/jellyfin_kodi/helper/utils.py @@ -478,12 +478,15 @@ def convert_to_local(date): ''' try: date = parser.parse(date) if isinstance(date, string_types) else date - date = date.replace(tzinfo=tz.tzutc()) - date = date.astimezone(tz.tzlocal()) - - return date.strftime('%Y-%m-%dT%H:%M:%S') + parsed_date = date.replace(tzinfo=tz.tzutc()) + local_date = parsed_date.astimezone(tz.tzlocal()) + # Bad metadata defaults to date 1-1-1. Catch it and don't throw errors + if local_date.year == 1: + return str(date) + else: + return local_date.strftime('%Y-%m-%dT%H:%M:%S') except Exception as error: - LOG.exception(error) + LOG.exception('Item date: {} --- {}'.format(str(date), error)) return str(date)