mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 00:06:07 -07:00
Add rating key to The Movie Database and TVmaze lookups
This commit is contained in:
parent
80ee8f9617
commit
41101921ed
2 changed files with 59 additions and 25 deletions
|
@ -544,25 +544,21 @@ def dbcheck():
|
||||||
# tvmaze_lookup table :: This table keeps record of the TVmaze lookups
|
# tvmaze_lookup table :: This table keeps record of the TVmaze lookups
|
||||||
c_db.execute(
|
c_db.execute(
|
||||||
'CREATE TABLE IF NOT EXISTS tvmaze_lookup (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
'CREATE TABLE IF NOT EXISTS tvmaze_lookup (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||||
'thetvdb_id INTEGER, imdb_id TEXT, tvmaze_id INTEGER, tvmaze_url TEXT, tvmaze_json TEXT)'
|
'rating_key INTEGER, thetvdb_id INTEGER, imdb_id TEXT, '
|
||||||
|
'tvmaze_id INTEGER, tvmaze_url TEXT, tvmaze_json TEXT)'
|
||||||
)
|
)
|
||||||
c_db.execute(
|
c_db.execute(
|
||||||
'CREATE UNIQUE INDEX IF NOT EXISTS idx_tvmaze_lookup_thetvdb_id ON tvmaze_lookup (thetvdb_id)'
|
'CREATE UNIQUE INDEX IF NOT EXISTS idx_tvmaze_lookup ON tvmaze_lookup (rating_key)'
|
||||||
)
|
|
||||||
c_db.execute(
|
|
||||||
'CREATE UNIQUE INDEX IF NOT EXISTS idx_tvmaze_lookup_imdb_id ON tvmaze_lookup (imdb_id)'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# themoviedb_lookup table :: This table keeps record of the TheMovieDB lookups
|
# themoviedb_lookup table :: This table keeps record of the TheMovieDB lookups
|
||||||
c_db.execute(
|
c_db.execute(
|
||||||
'CREATE TABLE IF NOT EXISTS themoviedb_lookup (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
'CREATE TABLE IF NOT EXISTS themoviedb_lookup (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||||
'thetvdb_id INTEGER, imdb_id TEXT, themoviedb_id INTEGER, themoviedb_url TEXT, themoviedb_json TEXT)'
|
'rating_key INTEGER, thetvdb_id INTEGER, imdb_id TEXT, '
|
||||||
|
'themoviedb_id INTEGER, themoviedb_url TEXT, themoviedb_json TEXT)'
|
||||||
)
|
)
|
||||||
c_db.execute(
|
c_db.execute(
|
||||||
'CREATE UNIQUE INDEX IF NOT EXISTS idx_themoviedb_lookup_thetvdb_id ON themoviedb_lookup (thetvdb_id)'
|
'CREATE UNIQUE INDEX IF NOT EXISTS idx_themoviedb_lookup ON themoviedb_lookup (rating_key)'
|
||||||
)
|
|
||||||
c_db.execute(
|
|
||||||
'CREATE UNIQUE INDEX IF NOT EXISTS idx_themoviedb_lookup_imdb_id ON themoviedb_lookup (imdb_id)'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Upgrade sessions table from earlier versions
|
# Upgrade sessions table from earlier versions
|
||||||
|
@ -1104,6 +1100,36 @@ def dbcheck():
|
||||||
'ALTER TABLE notifiers ADD COLUMN custom_conditions_logic TEXT'
|
'ALTER TABLE notifiers ADD COLUMN custom_conditions_logic TEXT'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Upgrade tvmaze_lookup table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT rating_key FROM tvmaze_lookup')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table tvmaze_lookup.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE tvmaze_lookup ADD COLUMN rating_key INTEGER'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'DROP INDEX idx_tvmaze_lookup_thetvdb_id'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'DROP INDEX idx_tvmaze_lookup_imdb_id'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Upgrade themoviedb_lookup table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT rating_key FROM themoviedb_lookup')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table themoviedb_lookup.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE themoviedb_lookup ADD COLUMN rating_key INTEGER'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'DROP INDEX idx_themoviedb_lookup_thetvdb_id'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'DROP INDEX idx_themoviedb_lookup_imdb_id'
|
||||||
|
)
|
||||||
|
|
||||||
# Add "Local" user to database as default unauthenticated user.
|
# Add "Local" user to database as default unauthenticated user.
|
||||||
result = c_db.execute('SELECT id FROM users WHERE username = "Local"')
|
result = c_db.execute('SELECT id FROM users WHERE username = "Local"')
|
||||||
if not result.fetchone():
|
if not result.fetchone():
|
||||||
|
|
|
@ -530,20 +530,24 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, *
|
||||||
|
|
||||||
# Get TheMovieDB info
|
# Get TheMovieDB info
|
||||||
if metadata.get('themoviedb_id'):
|
if metadata.get('themoviedb_id'):
|
||||||
themoveidb_json = get_themoviedb_info(metadata['media_type'], metadata['themoviedb_id'])
|
themoveidb_json = get_themoviedb_info(rating_key=rating_key,
|
||||||
|
media_type=metadata['media_type'],
|
||||||
|
themoviedb_id=metadata['themoviedb_id'])
|
||||||
|
|
||||||
if themoveidb_json.get('imdb_id'):
|
if themoveidb_json.get('imdb_id'):
|
||||||
metadata['imdb_id'] = themoveidb_json['imdb_id']
|
metadata['imdb_id'] = themoveidb_json['imdb_id']
|
||||||
metadata['imdb_url'] = 'https://www.imdb.com/title/' + themoveidb_json['imdb_id']
|
metadata['imdb_url'] = 'https://www.imdb.com/title/' + themoveidb_json['imdb_id']
|
||||||
|
|
||||||
elif metadata.get('thetvdb_id') or metadata.get('imdb_id'):
|
elif metadata.get('thetvdb_id') or metadata.get('imdb_id'):
|
||||||
themoviedb_info = lookup_themoviedb_by_id(thetvdb_id=metadata.get('thetvdb_id'),
|
themoviedb_info = lookup_themoviedb_by_id(rating_key=rating_key,
|
||||||
|
thetvdb_id=metadata.get('thetvdb_id'),
|
||||||
imdb_id=metadata.get('imdb_id'))
|
imdb_id=metadata.get('imdb_id'))
|
||||||
metadata.update(themoviedb_info)
|
metadata.update(themoviedb_info)
|
||||||
|
|
||||||
# Get TVmaze info (for tv shows only)
|
# Get TVmaze info (for tv shows only)
|
||||||
if metadata['media_type'] in ('show', 'season', 'episode') and (metadata.get('thetvdb_id') or metadata.get('imdb_id')):
|
if metadata['media_type'] in ('show', 'season', 'episode') and (metadata.get('thetvdb_id') or metadata.get('imdb_id')):
|
||||||
tvmaze_info = lookup_tvmaze_by_id(thetvdb_id=metadata.get('thetvdb_id'),
|
tvmaze_info = lookup_tvmaze_by_id(rating_key=rating_key,
|
||||||
|
thetvdb_id=metadata.get('thetvdb_id'),
|
||||||
imdb_id=metadata.get('imdb_id'))
|
imdb_id=metadata.get('imdb_id'))
|
||||||
metadata.update(tvmaze_info)
|
metadata.update(tvmaze_info)
|
||||||
|
|
||||||
|
@ -1011,15 +1015,15 @@ def get_poster_info(poster_thumb, poster_key, poster_title):
|
||||||
return poster_info
|
return poster_info
|
||||||
|
|
||||||
|
|
||||||
def lookup_tvmaze_by_id(thetvdb_id=None, imdb_id=None):
|
def lookup_tvmaze_by_id(rating_key=None, thetvdb_id=None, imdb_id=None):
|
||||||
tvmaze_info = {}
|
tvmaze_info = {}
|
||||||
|
|
||||||
db = database.MonitorDatabase()
|
db = database.MonitorDatabase()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query = 'SELECT imdb_id, tvmaze_id, tvmaze_url FROM tvmaze_lookup ' \
|
query = 'SELECT imdb_id, tvmaze_id, tvmaze_url FROM tvmaze_lookup ' \
|
||||||
'WHERE {} = ?'.format('thetvdb_id' if thetvdb_id else 'imdb_id')
|
'WHERE rating_key = ?'
|
||||||
tvmaze_info = db.select_single(query, args=[thetvdb_id or imdb_id])
|
tvmaze_info = db.select_single(query, args=[rating_key])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(u"PlexPy NotificationHandler :: Unable to execute database query for lookup_tvmaze_by_tvdb_id: %s." % e)
|
logger.warn(u"PlexPy NotificationHandler :: Unable to execute database query for lookup_tvmaze_by_tvdb_id: %s." % e)
|
||||||
|
|
||||||
|
@ -1040,7 +1044,8 @@ def lookup_tvmaze_by_id(thetvdb_id=None, imdb_id=None):
|
||||||
tvmaze_url = tvmaze_json.get('url', '')
|
tvmaze_url = tvmaze_json.get('url', '')
|
||||||
|
|
||||||
keys = {'tvmaze_id': tvmaze_id}
|
keys = {'tvmaze_id': tvmaze_id}
|
||||||
tvmaze_info = {'thetvdb_id': thetvdb_id,
|
tvmaze_info = {'rating_key': rating_key,
|
||||||
|
'thetvdb_id': thetvdb_id,
|
||||||
'imdb_id': imdb_id,
|
'imdb_id': imdb_id,
|
||||||
'tvmaze_url': tvmaze_url,
|
'tvmaze_url': tvmaze_url,
|
||||||
'tvmaze_json': json.dumps(tvmaze_json)}
|
'tvmaze_json': json.dumps(tvmaze_json)}
|
||||||
|
@ -1058,15 +1063,15 @@ def lookup_tvmaze_by_id(thetvdb_id=None, imdb_id=None):
|
||||||
return tvmaze_info
|
return tvmaze_info
|
||||||
|
|
||||||
|
|
||||||
def lookup_themoviedb_by_id(thetvdb_id=None, imdb_id=None):
|
def lookup_themoviedb_by_id(rating_key=None, thetvdb_id=None, imdb_id=None):
|
||||||
themoviedb_info = {}
|
themoviedb_info = {}
|
||||||
|
|
||||||
db = database.MonitorDatabase()
|
db = database.MonitorDatabase()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query = 'SELECT thetvdb_id, imdb_id, themoviedb_id, themoviedb_url FROM themoviedb_lookup ' \
|
query = 'SELECT thetvdb_id, imdb_id, themoviedb_id, themoviedb_url FROM themoviedb_lookup ' \
|
||||||
'WHERE {} = ?'.format('thetvdb_id' if thetvdb_id else 'imdb_id')
|
'WHERE rating_key = ?'
|
||||||
themoviedb_info = db.select_single(query, args=[thetvdb_id or imdb_id])
|
themoviedb_info = db.select_single(query, args=[rating_key])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(u"PlexPy NotificationHandler :: Unable to execute database query for lookup_themoviedb_by_imdb_id: %s." % e)
|
logger.warn(u"PlexPy NotificationHandler :: Unable to execute database query for lookup_themoviedb_by_imdb_id: %s." % e)
|
||||||
|
|
||||||
|
@ -1093,10 +1098,13 @@ def lookup_themoviedb_by_id(thetvdb_id=None, imdb_id=None):
|
||||||
if themoviedb_id:
|
if themoviedb_id:
|
||||||
media_type = 'tv' if thetvdb_id else 'movie'
|
media_type = 'tv' if thetvdb_id else 'movie'
|
||||||
themoviedb_url = 'https://www.themoviedb.org/{}/{}'.format(media_type, themoviedb_id)
|
themoviedb_url = 'https://www.themoviedb.org/{}/{}'.format(media_type, themoviedb_id)
|
||||||
themoviedb_json = get_themoviedb_info(media_type, themoviedb_id)
|
themoviedb_json = get_themoviedb_info(rating_key=rating_key,
|
||||||
|
media_type=media_type,
|
||||||
|
themoviedb_id=themoviedb_id)
|
||||||
|
|
||||||
keys = {'themoviedb_id': themoviedb_id}
|
keys = {'themoviedb_id': themoviedb_id}
|
||||||
themoviedb_info = {'thetvdb_id': thetvdb_id,
|
themoviedb_info = {'rating_key': rating_key,
|
||||||
|
'thetvdb_id': thetvdb_id,
|
||||||
'imdb_id': imdb_id or themoviedb_json.get('imdb_id'),
|
'imdb_id': imdb_id or themoviedb_json.get('imdb_id'),
|
||||||
'themoviedb_url': themoviedb_url,
|
'themoviedb_url': themoviedb_url,
|
||||||
'themoviedb_json': json.dumps(themoviedb_json)
|
'themoviedb_json': json.dumps(themoviedb_json)
|
||||||
|
@ -1116,7 +1124,7 @@ def lookup_themoviedb_by_id(thetvdb_id=None, imdb_id=None):
|
||||||
return themoviedb_info
|
return themoviedb_info
|
||||||
|
|
||||||
|
|
||||||
def get_themoviedb_info(media_type, themoviedb_id):
|
def get_themoviedb_info(rating_key=None, media_type=None, themoviedb_id=None):
|
||||||
if media_type == 'show':
|
if media_type == 'show':
|
||||||
media_type = 'tv'
|
media_type = 'tv'
|
||||||
|
|
||||||
|
@ -1126,8 +1134,8 @@ def get_themoviedb_info(media_type, themoviedb_id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query = 'SELECT themoviedb_json FROM themoviedb_lookup ' \
|
query = 'SELECT themoviedb_json FROM themoviedb_lookup ' \
|
||||||
'WHERE themoviedb_id = ?'
|
'WHERE rating_key = ?'
|
||||||
result = db.select_single(query, args=[themoviedb_id])
|
result = db.select_single(query, args=[rating_key])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(u"PlexPy NotificationHandler :: Unable to execute database query for get_themoviedb_info: %s." % e)
|
logger.warn(u"PlexPy NotificationHandler :: Unable to execute database query for get_themoviedb_info: %s." % e)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue