Optimize DB path updates for TV shows
This commit is contained in:
parent
d74c26fd4c
commit
44073a3201
3 changed files with 47 additions and 66 deletions
|
@ -1442,7 +1442,7 @@ class API(object):
|
||||||
omit_check : Will entirely omit validity check if True
|
omit_check : Will entirely omit validity check if True
|
||||||
"""
|
"""
|
||||||
if path is None:
|
if path is None:
|
||||||
return None
|
return
|
||||||
typus = v.REMAP_TYPE_FROM_PLEXTYPE[typus]
|
typus = v.REMAP_TYPE_FROM_PLEXTYPE[typus]
|
||||||
if state.REMAP_PATH is True:
|
if state.REMAP_PATH is True:
|
||||||
path = path.replace(getattr(state, 'remapSMB%sOrg' % typus),
|
path = path.replace(getattr(state, 'remapSMB%sOrg' % typus),
|
||||||
|
|
|
@ -531,10 +531,8 @@ class TVShows(Items):
|
||||||
plex_db = self.plex_db
|
plex_db = self.plex_db
|
||||||
artwork = self.artwork
|
artwork = self.artwork
|
||||||
api = API(item)
|
api = API(item)
|
||||||
|
|
||||||
update_item = True
|
update_item = True
|
||||||
itemid = api.plex_id()
|
itemid = api.plex_id()
|
||||||
|
|
||||||
if not itemid:
|
if not itemid:
|
||||||
LOG.error("Cannot parse XML data for TV show")
|
LOG.error("Cannot parse XML data for TV show")
|
||||||
return
|
return
|
||||||
|
@ -547,7 +545,6 @@ class TVShows(Items):
|
||||||
update_item = False
|
update_item = False
|
||||||
kodicursor.execute("select coalesce(max(idShow),0) from tvshow")
|
kodicursor.execute("select coalesce(max(idShow),0) from tvshow")
|
||||||
showid = kodicursor.fetchone()[0] + 1
|
showid = kodicursor.fetchone()[0] + 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Verification the item is still in Kodi
|
# Verification the item is still in Kodi
|
||||||
query = "SELECT * FROM tvshow WHERE idShow = ?"
|
query = "SELECT * FROM tvshow WHERE idShow = ?"
|
||||||
|
@ -562,7 +559,6 @@ class TVShows(Items):
|
||||||
|
|
||||||
# fileId information
|
# fileId information
|
||||||
checksum = api.checksum()
|
checksum = api.checksum()
|
||||||
|
|
||||||
# item details
|
# item details
|
||||||
genres = api.genre_list()
|
genres = api.genre_list()
|
||||||
title, sorttitle = api.titles()
|
title, sorttitle = api.titles()
|
||||||
|
@ -581,19 +577,13 @@ class TVShows(Items):
|
||||||
studio = None
|
studio = None
|
||||||
|
|
||||||
# GET THE FILE AND PATH #####
|
# GET THE FILE AND PATH #####
|
||||||
do_indirect = not state.DIRECT_PATHS
|
|
||||||
if state.DIRECT_PATHS:
|
if state.DIRECT_PATHS:
|
||||||
# Direct paths is set the Kodi way
|
# Direct paths is set the Kodi way
|
||||||
playurl = api.tv_show_path()
|
playurl = api.validate_playurl(api.tv_show_path(),
|
||||||
if playurl is None:
|
|
||||||
# Something went wrong, trying to use non-direct paths
|
|
||||||
do_indirect = True
|
|
||||||
else:
|
|
||||||
playurl = api.validate_playurl(playurl,
|
|
||||||
api.plex_type(),
|
api.plex_type(),
|
||||||
folder=True)
|
folder=True)
|
||||||
if playurl is None:
|
if playurl is None:
|
||||||
return False
|
return
|
||||||
if "\\" in playurl:
|
if "\\" in playurl:
|
||||||
# Local path
|
# Local path
|
||||||
path = "%s\\" % playurl
|
path = "%s\\" % playurl
|
||||||
|
@ -602,16 +592,19 @@ class TVShows(Items):
|
||||||
# Network path
|
# Network path
|
||||||
path = "%s/" % playurl
|
path = "%s/" % playurl
|
||||||
toplevelpath = "%s/" % dirname(dirname(path))
|
toplevelpath = "%s/" % dirname(dirname(path))
|
||||||
if do_indirect:
|
toppathid = self.kodi_db.add_video_path(
|
||||||
|
toplevelpath,
|
||||||
|
content='tvshows',
|
||||||
|
scraper='metadata.local')
|
||||||
|
else:
|
||||||
# Set plugin path
|
# Set plugin path
|
||||||
toplevelpath = "plugin://%s.tvshows/" % v.ADDON_ID
|
toplevelpath = "plugin://%s.tvshows/" % v.ADDON_ID
|
||||||
path = "%s%s/" % (toplevelpath, itemid)
|
path = "%s%s/" % (toplevelpath, itemid)
|
||||||
|
toppathid = self.kodi_db.get_path(toplevelpath)
|
||||||
|
|
||||||
# Add top path
|
pathid = self.kodi_db.add_video_path(path,
|
||||||
toppathid = self.kodi_db.add_video_path(toplevelpath)
|
date_added=api.date_created(),
|
||||||
# add/retrieve pathid and fileid
|
id_parent_path=toppathid)
|
||||||
# if the path or file already exists, the calls return current value
|
|
||||||
pathid = self.kodi_db.add_video_path(path)
|
|
||||||
# UPDATE THE TVSHOW #####
|
# UPDATE THE TVSHOW #####
|
||||||
if update_item:
|
if update_item:
|
||||||
LOG.info("UPDATE tvshow itemid: %s - Title: %s", itemid, title)
|
LOG.info("UPDATE tvshow itemid: %s - Title: %s", itemid, title)
|
||||||
|
@ -671,16 +664,6 @@ class TVShows(Items):
|
||||||
# OR ADD THE TVSHOW #####
|
# OR ADD THE TVSHOW #####
|
||||||
else:
|
else:
|
||||||
LOG.info("ADD tvshow itemid: %s - Title: %s", itemid, title)
|
LOG.info("ADD tvshow itemid: %s - Title: %s", itemid, title)
|
||||||
query = '''
|
|
||||||
UPDATE path
|
|
||||||
SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?
|
|
||||||
WHERE idPath = ?
|
|
||||||
'''
|
|
||||||
kodicursor.execute(query, (toplevelpath,
|
|
||||||
"tvshows",
|
|
||||||
"metadata.local",
|
|
||||||
1,
|
|
||||||
toppathid))
|
|
||||||
# Link the path
|
# Link the path
|
||||||
query = "INSERT INTO tvshowlinkpath(idShow, idPath) values (?, ?)"
|
query = "INSERT INTO tvshowlinkpath(idShow, idPath) values (?, ?)"
|
||||||
kodicursor.execute(query, (showid, pathid))
|
kodicursor.execute(query, (showid, pathid))
|
||||||
|
@ -733,14 +716,6 @@ class TVShows(Items):
|
||||||
kodicursor.execute(query, (showid, title, plot, rating,
|
kodicursor.execute(query, (showid, title, plot, rating,
|
||||||
premieredate, genre, title, tvdb,
|
premieredate, genre, title, tvdb,
|
||||||
mpaa, studio, sorttitle))
|
mpaa, studio, sorttitle))
|
||||||
# Update the path
|
|
||||||
query = '''
|
|
||||||
UPDATE path
|
|
||||||
SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?,
|
|
||||||
idParentPath = ?
|
|
||||||
WHERE idPath = ?
|
|
||||||
'''
|
|
||||||
kodicursor.execute(query, (path, None, None, 1, toppathid, pathid))
|
|
||||||
|
|
||||||
self.kodi_db.modify_people(showid, v.KODI_TYPE_SHOW, api.people_list())
|
self.kodi_db.modify_people(showid, v.KODI_TYPE_SHOW, api.people_list())
|
||||||
self.kodi_db.modify_genres(showid, v.KODI_TYPE_SHOW, genres)
|
self.kodi_db.modify_genres(showid, v.KODI_TYPE_SHOW, genres)
|
||||||
|
|
|
@ -60,7 +60,7 @@ class KodiDBMethods(object):
|
||||||
For some reason, Kodi ignores this if done via itemtypes while e.g.
|
For some reason, Kodi ignores this if done via itemtypes while e.g.
|
||||||
adding or updating items. (addPath method does NOT work)
|
adding or updating items. (addPath method does NOT work)
|
||||||
"""
|
"""
|
||||||
path_id = self.getPath('plugin://%s.movies/' % v.ADDON_ID)
|
path_id = self.get_path('plugin://%s.movies/' % v.ADDON_ID)
|
||||||
if path_id is None:
|
if path_id is None:
|
||||||
self.cursor.execute("select coalesce(max(idPath),0) from path")
|
self.cursor.execute("select coalesce(max(idPath),0) from path")
|
||||||
path_id = self.cursor.fetchone()[0] + 1
|
path_id = self.cursor.fetchone()[0] + 1
|
||||||
|
@ -80,7 +80,7 @@ class KodiDBMethods(object):
|
||||||
1,
|
1,
|
||||||
0))
|
0))
|
||||||
# And TV shows
|
# And TV shows
|
||||||
path_id = self.getPath('plugin://%s.tvshows/' % v.ADDON_ID)
|
path_id = self.get_path('plugin://%s.tvshows/' % v.ADDON_ID)
|
||||||
if path_id is None:
|
if path_id is None:
|
||||||
self.cursor.execute("select coalesce(max(idPath),0) from path")
|
self.cursor.execute("select coalesce(max(idPath),0) from path")
|
||||||
path_id = self.cursor.fetchone()[0] + 1
|
path_id = self.cursor.fetchone()[0] + 1
|
||||||
|
@ -111,7 +111,7 @@ class KodiDBMethods(object):
|
||||||
else:
|
else:
|
||||||
# Network path
|
# Network path
|
||||||
parentpath = "%s/" % dirname(dirname(path))
|
parentpath = "%s/" % dirname(dirname(path))
|
||||||
pathid = self.getPath(parentpath)
|
pathid = self.get_path(parentpath)
|
||||||
if pathid is None:
|
if pathid is None:
|
||||||
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
|
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
|
||||||
pathid = self.cursor.fetchone()[0] + 1
|
pathid = self.cursor.fetchone()[0] + 1
|
||||||
|
@ -126,8 +126,16 @@ class KodiDBMethods(object):
|
||||||
self.cursor.execute(query, (parent_path_id, pathid))
|
self.cursor.execute(query, (parent_path_id, pathid))
|
||||||
return pathid
|
return pathid
|
||||||
|
|
||||||
def add_video_path(self, path):
|
def add_video_path(self, path, date_added=None, id_parent_path=None,
|
||||||
# SQL won't return existing paths otherwise
|
content=None, scraper=None):
|
||||||
|
"""
|
||||||
|
Returns the idPath from the path table. Creates a new entry if path
|
||||||
|
[unicode] does not yet exist (using date_added [kodi date type],
|
||||||
|
id_parent_path [int], content ['tvshows', 'movies', None], scraper
|
||||||
|
[usually 'metadata.local'])
|
||||||
|
|
||||||
|
WILL activate noUpdate for the path!
|
||||||
|
"""
|
||||||
if path is None:
|
if path is None:
|
||||||
path = ''
|
path = ''
|
||||||
query = 'SELECT idPath FROM path WHERE strPath = ?'
|
query = 'SELECT idPath FROM path WHERE strPath = ?'
|
||||||
|
@ -137,12 +145,14 @@ class KodiDBMethods(object):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
|
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
|
||||||
pathid = self.cursor.fetchone()[0] + 1
|
pathid = self.cursor.fetchone()[0] + 1
|
||||||
datetime = unix_date_to_kodi(unix_timestamp())
|
|
||||||
query = '''
|
query = '''
|
||||||
INSERT INTO path(idPath, strPath, dateAdded)
|
INSERT INTO path(idPath, strPath, dateAdded, idParentPath,
|
||||||
VALUES (?, ?, ?)
|
strContent, strScraper, noUpdate)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
self.cursor.execute(query, (pathid, path, datetime))
|
self.cursor.execute(query,
|
||||||
|
(pathid, path, date_added, id_parent_path,
|
||||||
|
content, scraper, 1))
|
||||||
return pathid
|
return pathid
|
||||||
|
|
||||||
def add_music_path(self, path, strHash=None):
|
def add_music_path(self, path, strHash=None):
|
||||||
|
@ -163,20 +173,16 @@ class KodiDBMethods(object):
|
||||||
self.cursor.execute(query, (pathid, path, strHash))
|
self.cursor.execute(query, (pathid, path, strHash))
|
||||||
return pathid
|
return pathid
|
||||||
|
|
||||||
def getPath(self, path):
|
def get_path(self, path):
|
||||||
|
"""
|
||||||
query = ' '.join((
|
Returns the idPath from the path table for path [unicode] or None
|
||||||
|
"""
|
||||||
"SELECT idPath",
|
self.cursor.execute('SELECT idPath FROM path WHERE strPath = ?',
|
||||||
"FROM path",
|
(path,))
|
||||||
"WHERE strPath = ?"
|
|
||||||
))
|
|
||||||
self.cursor.execute(query, (path,))
|
|
||||||
try:
|
try:
|
||||||
pathid = self.cursor.fetchone()[0]
|
pathid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pathid = None
|
pathid = None
|
||||||
|
|
||||||
return pathid
|
return pathid
|
||||||
|
|
||||||
def addFile(self, filename, pathid):
|
def addFile(self, filename, pathid):
|
||||||
|
@ -224,7 +230,7 @@ class KodiDBMethods(object):
|
||||||
|
|
||||||
def removeFile(self, path, filename):
|
def removeFile(self, path, filename):
|
||||||
|
|
||||||
pathid = self.getPath(path)
|
pathid = self.get_path(path)
|
||||||
|
|
||||||
if pathid is not None:
|
if pathid is not None:
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
Loading…
Reference in a new issue