Skip to content

Commit

Permalink
Read Rebroadcast Delay from database in tvmaze.py
Browse files Browse the repository at this point in the history
The tvmaze.py metadata grabber script has been updated
to acquire an optional Rebroadcast Delay from the
MythTv database. The database is only read when we
know it's a 'Lookup by Timestamp' and no Rebroadcast
Delay has been specified on the command line.

This allows us to use the Rebroadcast Delay without
having to update the callers of the grabber to add
a new argument.

Refs: MythTV#717
  • Loading branch information
SteveErl committed Feb 28, 2023
1 parent 95face1 commit 0ddeefb
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions mythtv/programs/scripts/metadata/Television/tvmaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def buildNumbers(args, opts):
from MythTV.utility.dt import posixtzinfo
from MythTV.tvmaze import tvmaze_api as tvmaze
from MythTV import datetime
from MythTV import MythDB
from lxml import etree
from datetime import timedelta

Expand Down Expand Up @@ -214,7 +215,10 @@ def buildNumbers(args, opts):
# check whether the 'subtitle' is really a timestamp
try:
dtInLocalZone = datetime.strptime(tvsubtitle, "%Y-%m-%d %H:%M:%S") # defaults to local timezone
except ValueError:
dtInLocalZone = None

if dtInLocalZone:
# The user may optionally specify a 'Broadcast Delay'.
#
# https://en.wikipedia.org/wiki/Broadcast_delay
Expand All @@ -227,8 +231,10 @@ def buildNumbers(args, opts):
# to air in local primetime hours to improve accessibility
# and viewership.
#
# There are also some broadcasts which are shown without a
# Broadcast Delay, such as live sporting events. When we are
# The initial broadcast happens in the eastern region(s).
# Rebroadcasts with delays happen in regions further west.
# There are also some programs which are shown in all regions
# without any delay, such as live sporting events. When we are
# looking for a match by timestamp, we may need to try both
# with and without a rebroadcast delay. For example, for an
# 8pm show in New York:
Expand All @@ -243,15 +249,25 @@ def buildNumbers(args, opts):
# Pacific/Honolulu -10 240 15:00 19:00 7pm
#
# The Rebroadcast Delay (in minutes) may be specified
# with a 3rd argument.
if len(args) > 2:
rbDelayMinutes = int(args[2])
else:
# with a 3rd argument or in the MythTv database.
try:
if len(args) > 2:
rbDelayMinutes = int(args[2])
else:
db = MythDB()
rbd = db.settings['NULL']['RebroadcastDelay']
if rbd:
rbDelayMinutes = int(rbd)
if rbDelayMinutes == 0:
rbDelayMinutes = None
else:
rbDelayMinutes = None

except ValueError:
rbDelayMinutes = None

except ValueError:
dtInLocalZone = None
rbDelayMinutes = None
if opts.debug:
print('Rebroadcast Delay =', rbDelayMinutes)

matchesFound = 0
best_ep_quality = 0.5 # require at least this quality on string match
Expand Down

0 comments on commit 0ddeefb

Please sign in to comment.