Skip to content

Commit

Permalink
Add match by date when no time specified in TvMaze
Browse files Browse the repository at this point in the history
Sometimes, the TvMaze database only specifies a date
and not a time for an episode or set of episodes.
This is most common in webChannel originated shows.
In such a case, the 'Find Episode by Timestamp'
syntax, fails to find an exact or close match.
For example:
   tvmaze.py -N "Criminal Minds" "2022-11-24 21:00:00"

For this episode, in the TvMaze database
        airtime =
        airdate = 2022-11-24

With this code update, we detect when no airtime is
specified in the database, and apply a match-by-date
behavior.

The match-by-date results are only used as a last
resort. First we select exact timestamp matches.
If there are none of those, we select close
timestamp matches. If there are none of those,
then we'll select date only matches.

For example:

tvmaze.py -N "Criminal Minds" "2022-11-24 21:00:00"
<?xml version='1.0' encoding='UTF-8'?>
<metadata>
  <item>
    <title>Criminal Minds</title>
    <subtitle>Just Getting Started</subtitle>
    ...
    <season>16</season>
    <episode>1</episode>
    <inetref>81</inetref>
    ...
  </item>
  <item>
    <title>Criminal Minds</title>
    <subtitle>Sicarius</subtitle>
    ...
    <season>16</season>
    <episode>2</episode>
    <inetref>81</inetref>
    ...
  </item>
</metadata>

Note that there were 2 episodes released on 2022-11-24,
so both episodes appear in the output results.

In addition, a display of 'runtime' has been added
for the -M invocation option. For example

tvmaze.py -M "Fire Country"
<?xml version='1.0' encoding='UTF-8'?>
<metadata>
  <item>
    <title>Fire Country</title>
    ...
    <inetref>60339</inetref>
    <collectionref>60339</collectionref>
    <language>en</language>
    <releasedate>2022-10-07</releasedate>
    <userrating>6.300000</userrating>
    <popularity>99.0</popularity>
    <year>2022</year>
    <runtime>60</runtime>
    ...
  </item>
</metadata>

Resolves MythTV#654
  • Loading branch information
SteveErl committed Jan 23, 2023
1 parent 2531c67 commit 640565b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mythtv/programs/scripts/metadata/Television/tvmaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def buildList(tvtitle, opts):
m.collectionref = check_item(m, ("collectionref", str(show_info.id)), ignore=False)
m.language = check_item(m, ("language", str(locales.Language.getstored(show_info.language))))
m.userrating = check_item(m, ("userrating", show_info.rating['average']))
m.runtime = check_item(m, ("runtime", show_info.runtime))
try:
m.popularity = check_item(m, ("popularity", float(show_info.weight)), ignore=False)
except (TypeError, ValueError):
Expand Down Expand Up @@ -247,6 +248,7 @@ def buildNumbers(args, opts):
episodes = []
time_match_list = []
early_match_list = []
date_match_list = []
minTimeDelta = timedelta(minutes=60)
for i, ep in enumerate(episodes):
if ep.timestamp:
Expand Down Expand Up @@ -287,10 +289,28 @@ def buildNumbers(args, opts):
minTimeDelta = epInTgtZone - dtInTgtZone
early_match_list = [i]

# In some cases, tvmaze only specifies the date and not the time.
# This is most common in webChannel originated shows. For example:
# tvmaze.py -N "Criminal Minds" "2022-11-24 21:00:00"
# ep.airtime = , ep.airdate = 2022-11-24,
# ep.timestamp = 2022-11-24T12:00:00+00:00
# In such a scenario, look for date matches, ignoring the time.
if not ep.airtime and ep.airdate:
epDateInTgtZone = datetime(ep.airdate.year, ep.airdate.month, ep.airdate.day)\
.astimezone(posixtzinfo(show_tz))
if epDateInTgtZone <= dtInTgtZone < epDateInTgtZone+timedelta(hours=24):
if opts.debug:
print('Adding episode \'%s\' to date match list' % ep)
date_match_list.append(i)

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

if not time_match_list:
# No close matches found, so use the list of episodes on the day
time_match_list = date_match_list

if time_match_list:
for ep_index in time_match_list:
season_nr = str(episodes[ep_index].season)
Expand Down

0 comments on commit 640565b

Please sign in to comment.