Skip to content

Commit 5c9ee33

Browse files
authored
Merge pull request #367 from makeroo/master
Do not fail while parsing illegal dates. Return None instead.
2 parents cdda56b + 3bc890a commit 5c9ee33

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

plexapi/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from getpass import getpass
1010
from threading import Thread, Event
1111
from tqdm import tqdm
12-
from plexapi import compat
12+
from plexapi import compat, log
1313
from plexapi.exceptions import NotFound
1414

15+
1516
# Search Types - Plex uses these to filter specific media types when searching.
1617
# Library Types - Populated at runtime
1718
SEARCHTYPES = {'movie': 1, 'show': 2, 'season': 3, 'episode': 4, 'trailer': 5, 'comic': 6, 'person': 7,
@@ -176,7 +177,11 @@ def toDatetime(value, format=None):
176177
"""
177178
if value and value is not None:
178179
if format:
179-
value = datetime.strptime(value, format)
180+
try:
181+
value = datetime.strptime(value, format)
182+
except ValueError:
183+
log.info('Failed to parse %s to datetime, defaulting to None', value)
184+
return None
180185
else:
181186
# https://bugs.python.org/issue30684
182187
# And platform support for before epoch seems to be flaky.

0 commit comments

Comments
 (0)