From c206d17762063f47062900aa6daf77dd9b367da5 Mon Sep 17 00:00:00 2001 From: Steve Erlenborn <1751095+SteveErl@users.noreply.github.com> Date: Thu, 10 Nov 2022 22:47:37 -0600 Subject: [PATCH] Fix setting of TvMaze show runtime The script tvmaze/show.py had a line which retrieved the episode duration from the metadata provider, but then assigned it to num_episodes, which makes no sense. There is no code looking for num_episodes, but there is code looking for runtime, so the line has been fixed to assign to runtime. Using the TVmaze service for metadata lookup, there are rare cases where the 'runtime' field is empty, but 'averageRuntime' is not. This happened when looking up metadata for a TV show called "Everything's Trash". Note that the database entry for this show was subsequently updated to include the missing 'runtime' field. But on the night it was recorded, and for several days later, that field was null. Here's an excerpt of the original metadata for "Everything's Trash": "id":60518, "url":"https://www.tvmaze.com/shows/60518/everythings-trash", "name":"Everything's Trash", "type":"Scripted", "language":"English", "genres":[], "status":"Running", "runtime":null, "averageRuntime":30, To handle this type of scenario, when the 'runtime' field is null, read the duration from the 'averageRuntime' field. If both are null, then avoid trying to cast that value to an integer in tvmaze.py. Refs: #654 --- mythtv/bindings/python/tvmaze/show.py | 5 ++++- mythtv/programs/scripts/metadata/Television/tvmaze.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mythtv/bindings/python/tvmaze/show.py b/mythtv/bindings/python/tvmaze/show.py index 194d362107e..9e07af70432 100644 --- a/mythtv/bindings/python/tvmaze/show.py +++ b/mythtv/bindings/python/tvmaze/show.py @@ -47,7 +47,10 @@ def __init__(self, data): self.language = show.get('language') self.genres = show.get('genres') self.status = show.get('status') - self.num_episodes = show.get('runtime') + self.runtime = show.get('runtime') + # Sometimes runtime is empty, but averageRuntime is not + if self.runtime is None: + self.runtime = show.get('averageRuntime') self.seasons = {} self._episode_list = [] self.specials = {} diff --git a/mythtv/programs/scripts/metadata/Television/tvmaze.py b/mythtv/programs/scripts/metadata/Television/tvmaze.py index 4a7e7c5f945..a4c9ea416c3 100755 --- a/mythtv/programs/scripts/metadata/Television/tvmaze.py +++ b/mythtv/programs/scripts/metadata/Television/tvmaze.py @@ -442,7 +442,8 @@ def buildSingleItem(inetref, season, episode_id): elif show_info.premiere_date: m.releasedate = check_item(m, ("releasedate", show_info.premiere_date)) m.year = check_item(m, ("year", show_info.premiere_date.year)) - m.runtime = check_item(m, ("runtime", int(ep_info.duration))) + if ep_info.duration: + m.runtime = check_item(m, ("runtime", int(ep_info.duration))) for actor in show_info.cast: try: