Skip to content

Commit

Permalink
Add robustness when the timestamp is missing for an episode. MythTV#654
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveErl committed Nov 4, 2022
1 parent 497dede commit 9da4396
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions mythtv/programs/scripts/metadata/Television/tvmaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,31 +243,42 @@ 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 9da4396

Please sign in to comment.