From 640565b8da553b94595bc3445ba48533117e4643 Mon Sep 17 00:00:00 2001
From: Steve Erlenborn <1751095+SteveErl@users.noreply.github.com>
Date: Mon, 23 Jan 2023 17:04:02 -0600
Subject: [PATCH] Add match by date when no time specified in TvMaze
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"
-
Criminal Minds
Just Getting Started
...
16
1
81
...
-
Criminal Minds
Sicarius
...
16
2
81
...
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"
-
Fire Country
...
60339
60339
en
2022-10-07
6.300000
99.0
2022
60
...
Resolves #654
---
.../scripts/metadata/Television/tvmaze.py | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/mythtv/programs/scripts/metadata/Television/tvmaze.py b/mythtv/programs/scripts/metadata/Television/tvmaze.py
index 4e72206348d..0e0d40ff3e9 100755
--- a/mythtv/programs/scripts/metadata/Television/tvmaze.py
+++ b/mythtv/programs/scripts/metadata/Television/tvmaze.py
@@ -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):
@@ -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:
@@ -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)