Skip to content

Commit

Permalink
Update xmltv.py handle date format errors
Browse files Browse the repository at this point in the history
catch invalid date format errors to prevent crashing.
  • Loading branch information
ovargasp authored Dec 15, 2024
1 parent 4110a62 commit c5780e4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/common/xmltv.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,15 @@ def get_next_elem(self, _program):
p_date = self.get_p_date(elem)
if p_date:
_program['air_date'] = p_date
if len(p_date) == 4:
_program['formatted_date'] = p_date
else:
_program['formatted_date'] = datetime.datetime.strptime(
p_date, '%Y%m%d').strftime('%Y/%m/%d')
try:
if len(p_date) == 4:
_program['formatted_date'] = p_date
else:
_program['formatted_date'] = datetime.datetime.strptime(
p_date, '%Y%m%d').strftime('%Y/%m/%d')
except ValueError:
# Invalid date format, use today's date instead
_program['formatted_date'] = datetime.datetime.today().strftime('%Y/%m/%d')
return True
elif elem.tag == 'episode-num':
episode_num = self.get_p_episode_num(elem)
Expand Down

0 comments on commit c5780e4

Please sign in to comment.