Skip to content

Commit

Permalink
Handle null timestamp or runtime TvMaze fields
Browse files Browse the repository at this point in the history
In rare cases, the TvMaze database provides null timestamp
or runtime data fields. To make the metadata retrieval script
more fault tolerant, null checks have been added for these values.

When the timestamp field is null, don't use it to generate a
datetime to use in a search for a matching episode.

When the runtime duration field is null, the delta size is
now set to zero minutes. The code which looks for an episode
match has been updated to separate "on time" recordings from
"a little late" recordings to accommodate the possible delta
size of zero.

Refs: MythTV#654
  • Loading branch information
SteveErl committed Nov 13, 2022
1 parent 35eccb4 commit 52b8977
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions mythtv/programs/scripts/metadata/Television/tvmaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,31 +244,43 @@ def buildNumbers(args, opts):
early_match_list = []
minTimeDelta = timedelta(minutes=60)
for i, ep in enumerate(episodes):
epInTgtZone = datetime.fromIso(ep.timestamp, tz = posixtzinfo(show_tz))
durationDelta = timedelta(minutes=ep.duration)

# Consider it a match if the recording starts late, but within the duration of the show.
if epInTgtZone <= dtInTgtZone < epInTgtZone+durationDelta:
# Recording start time is within the range of this episode
if opts.debug:
print('Recording in range of inetref %d, season %d, episode %d (%s ... %s)' \
% (inetref, ep.season, ep.number, epInTgtZone, epInTgtZone+durationDelta))
time_match_list.append(i)
minTimeDelta = timedelta(minutes=0)
# Consider it a match if the recording is a little bit early. This helps cases
# where you set up a rule to record, at say 9:00, and the broadcaster uses a
# slightly odd start time, like 9:05.
elif epInTgtZone-minTimeDelta <= dtInTgtZone < epInTgtZone:
# Recording started earlier than this episode, so see if it's the closest match
if epInTgtZone - dtInTgtZone == minTimeDelta:
if ep.timestamp:
epInTgtZone = datetime.fromIso(ep.timestamp, tz = posixtzinfo(show_tz))
if ep.duration:
durationDelta = timedelta(minutes=ep.duration)
else:
durationDelta = timedelta(minutes=0)

if epInTgtZone == dtInTgtZone:
if opts.debug:
print('adding episode to closest list', epInTgtZone - dtInTgtZone, '\n')
early_match_list.append(i)
elif epInTgtZone - dtInTgtZone < minTimeDelta:
print('Recording matches inetref %d, season %d, episode %d at %s' \
% (inetref, ep.season, ep.number, epInTgtZone))
time_match_list.append(i)
minTimeDelta = timedelta(minutes=0)

# Consider it a match if the recording starts late,
# but within the duration of the show.
elif epInTgtZone < dtInTgtZone < epInTgtZone+durationDelta:
# Recording start time is within the range of this episode
if opts.debug:
print('this episode is new closest', epInTgtZone - dtInTgtZone, '\n')
minTimeDelta = epInTgtZone - dtInTgtZone
early_match_list = [i]
print('Recording in range of inetref %d, season %d, episode %d (%s ... %s)' \
% (inetref, ep.season, ep.number, epInTgtZone, epInTgtZone+durationDelta))
time_match_list.append(i)
minTimeDelta = timedelta(minutes=0)
# Consider it a match if the recording is a little bit early. This helps cases
# where you set up a rule to record, at say 9:00, and the broadcaster uses a
# slightly odd start time, like 9:05.
elif epInTgtZone-minTimeDelta <= dtInTgtZone < epInTgtZone:
# Recording started earlier than this episode, so see if it's the closest match
if epInTgtZone - dtInTgtZone == minTimeDelta:
if opts.debug:
print('adding episode to closest list', epInTgtZone - dtInTgtZone, '\n')
early_match_list.append(i)
elif epInTgtZone - dtInTgtZone < minTimeDelta:
if opts.debug:
print('this episode is new closest', epInTgtZone - dtInTgtZone, '\n')
minTimeDelta = epInTgtZone - dtInTgtZone
early_match_list = [i]

if not time_match_list:
# No exact matches found, so use the list of the closest episode(s)
Expand Down

0 comments on commit 52b8977

Please sign in to comment.