From 89afd46b56ef547f55ba885e6b4bb3f246e5a0ce Mon Sep 17 00:00:00 2001 From: croneter Date: Mon, 25 Jan 2021 13:01:03 +0100 Subject: [PATCH] Fix OSError: Invalid argument when Plex returns an invalid timestamp --- resources/lib/timing.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/resources/lib/timing.py b/resources/lib/timing.py index 5ace8a90..5f0f1909 100644 --- a/resources/lib/timing.py +++ b/resources/lib/timing.py @@ -1,9 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import, division, unicode_literals +from logging import getLogger from datetime import datetime, timedelta from time import localtime, strftime +LOG = getLogger('PLEX.timing') + EPOCH = datetime.utcfromtimestamp(0) @@ -29,7 +32,13 @@ def unix_date_to_kodi(unix_kodi_time): Output: Y-m-d h:m:s = 2009-04-05 23:16:04 """ - return strftime('%Y-%m-%d %H:%M:%S', localtime(float(unix_kodi_time))) + try: + return strftime('%Y-%m-%d %H:%M:%S', localtime(float(unix_kodi_time))) + except Exception: + LOG.exception('Received an illegal timestamp from Plex: %s. ' + 'Using 1970-01-01 12:00:00', + unix_kodi_time) + return '1970-01-01 12:00:00' def plex_date_to_kodi(plex_timestamp):