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
|
||||
"""
|
||||
if path is None:
|
||||
return None
|
||||
return
|
||||
typus = v.REMAP_TYPE_FROM_PLEXTYPE[typus]
|
||||
if state.REMAP_PATH is True:
|
||||
path = path.replace(getattr(state, 'remapSMB%sOrg' % typus),
|
||||
|
|
|
@ -531,10 +531,8 @@ class TVShows(Items):
|
|||
plex_db = self.plex_db
|
||||
artwork = self.artwork
|
||||
api = API(item)
|
||||
|
||||
update_item = True
|
||||
itemid = api.plex_id()
|
||||
|
||||
if not itemid:
|
||||
LOG.error("Cannot parse XML data for TV show")
|
||||
return
|
||||
|
@ -547,7 +545,6 @@ class TVShows(Items):
|
|||
update_item = False
|
||||
kodicursor.execute("select coalesce(max(idShow),0) from tvshow")
|
||||
showid = kodicursor.fetchone()[0] + 1
|
||||
|
||||
else:
|
||||
# Verification the item is still in Kodi
|
||||
query = "SELECT * FROM tvshow WHERE idShow = ?"
|
||||
|
@ -562,7 +559,6 @@ class TVShows(Items):
|
|||
|
||||
# fileId information
|
||||
checksum = api.checksum()
|
||||
|
||||
# item details
|
||||
genres = api.genre_list()
|
||||
title, sorttitle = api.titles()
|
||||
|
@ -581,37 +577,34 @@ class TVShows(Items):
|
|||
studio = None
|
||||
|
||||
# GET THE FILE AND PATH #####
|
||||
do_indirect = not state.DIRECT_PATHS
|
||||
if state.DIRECT_PATHS:
|
||||
# Direct paths is set the Kodi way
|
||||
playurl = api.tv_show_path()
|
||||
playurl = api.validate_playurl(api.tv_show_path(),
|
||||
api.plex_type(),
|
||||
folder=True)
|
||||
if playurl is None:
|
||||
# Something went wrong, trying to use non-direct paths
|
||||
do_indirect = True
|
||||
return
|
||||
if "\\" in playurl:
|
||||
# Local path
|
||||
path = "%s\\" % playurl
|
||||
toplevelpath = "%s\\" % dirname(dirname(path))
|
||||
else:
|
||||
playurl = api.validate_playurl(playurl,
|
||||
api.plex_type(),
|
||||
folder=True)
|
||||
if playurl is None:
|
||||
return False
|
||||
if "\\" in playurl:
|
||||
# Local path
|
||||
path = "%s\\" % playurl
|
||||
toplevelpath = "%s\\" % dirname(dirname(path))
|
||||
else:
|
||||
# Network path
|
||||
path = "%s/" % playurl
|
||||
toplevelpath = "%s/" % dirname(dirname(path))
|
||||
if do_indirect:
|
||||
# Network path
|
||||
path = "%s/" % playurl
|
||||
toplevelpath = "%s/" % dirname(dirname(path))
|
||||
toppathid = self.kodi_db.add_video_path(
|
||||
toplevelpath,
|
||||
content='tvshows',
|
||||
scraper='metadata.local')
|
||||
else:
|
||||
# Set plugin path
|
||||
toplevelpath = "plugin://%s.tvshows/" % v.ADDON_ID
|
||||
path = "%s%s/" % (toplevelpath, itemid)
|
||||
toppathid = self.kodi_db.get_path(toplevelpath)
|
||||
|
||||
# Add top path
|
||||
toppathid = self.kodi_db.add_video_path(toplevelpath)
|
||||
# add/retrieve pathid and fileid
|
||||
# if the path or file already exists, the calls return current value
|
||||
pathid = self.kodi_db.add_video_path(path)
|
||||
pathid = self.kodi_db.add_video_path(path,
|
||||
date_added=api.date_created(),
|
||||
id_parent_path=toppathid)
|
||||
# UPDATE THE TVSHOW #####
|
||||
if update_item:
|
||||
LOG.info("UPDATE tvshow itemid: %s - Title: %s", itemid, title)
|
||||
|
@ -671,16 +664,6 @@ class TVShows(Items):
|
|||
# OR ADD THE TVSHOW #####
|
||||
else:
|
||||
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
|
||||
query = "INSERT INTO tvshowlinkpath(idShow, idPath) values (?, ?)"
|
||||
kodicursor.execute(query, (showid, pathid))
|
||||
|
@ -733,14 +716,6 @@ class TVShows(Items):
|
|||
kodicursor.execute(query, (showid, title, plot, rating,
|
||||
premieredate, genre, title, tvdb,
|
||||
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_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.
|
||||
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:
|
||||
self.cursor.execute("select coalesce(max(idPath),0) from path")
|
||||
path_id = self.cursor.fetchone()[0] + 1
|
||||
|
@ -80,7 +80,7 @@ class KodiDBMethods(object):
|
|||
1,
|
||||
0))
|
||||
# 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:
|
||||
self.cursor.execute("select coalesce(max(idPath),0) from path")
|
||||
path_id = self.cursor.fetchone()[0] + 1
|
||||
|
@ -111,7 +111,7 @@ class KodiDBMethods(object):
|
|||
else:
|
||||
# Network path
|
||||
parentpath = "%s/" % dirname(dirname(path))
|
||||
pathid = self.getPath(parentpath)
|
||||
pathid = self.get_path(parentpath)
|
||||
if pathid is None:
|
||||
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
|
||||
pathid = self.cursor.fetchone()[0] + 1
|
||||
|
@ -126,8 +126,16 @@ class KodiDBMethods(object):
|
|||
self.cursor.execute(query, (parent_path_id, pathid))
|
||||
return pathid
|
||||
|
||||
def add_video_path(self, path):
|
||||
# SQL won't return existing paths otherwise
|
||||
def add_video_path(self, path, date_added=None, id_parent_path=None,
|
||||
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:
|
||||
path = ''
|
||||
query = 'SELECT idPath FROM path WHERE strPath = ?'
|
||||
|
@ -137,12 +145,14 @@ class KodiDBMethods(object):
|
|||
except TypeError:
|
||||
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
|
||||
pathid = self.cursor.fetchone()[0] + 1
|
||||
datetime = unix_date_to_kodi(unix_timestamp())
|
||||
query = '''
|
||||
INSERT INTO path(idPath, strPath, dateAdded)
|
||||
VALUES (?, ?, ?)
|
||||
INSERT INTO path(idPath, strPath, dateAdded, idParentPath,
|
||||
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
|
||||
|
||||
def add_music_path(self, path, strHash=None):
|
||||
|
@ -163,20 +173,16 @@ class KodiDBMethods(object):
|
|||
self.cursor.execute(query, (pathid, path, strHash))
|
||||
return pathid
|
||||
|
||||
def getPath(self, path):
|
||||
|
||||
query = ' '.join((
|
||||
|
||||
"SELECT idPath",
|
||||
"FROM path",
|
||||
"WHERE strPath = ?"
|
||||
))
|
||||
self.cursor.execute(query, (path,))
|
||||
def get_path(self, path):
|
||||
"""
|
||||
Returns the idPath from the path table for path [unicode] or None
|
||||
"""
|
||||
self.cursor.execute('SELECT idPath FROM path WHERE strPath = ?',
|
||||
(path,))
|
||||
try:
|
||||
pathid = self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
pathid = None
|
||||
|
||||
return pathid
|
||||
|
||||
def addFile(self, filename, pathid):
|
||||
|
@ -224,7 +230,7 @@ class KodiDBMethods(object):
|
|||
|
||||
def removeFile(self, path, filename):
|
||||
|
||||
pathid = self.getPath(path)
|
||||
pathid = self.get_path(path)
|
||||
|
||||
if pathid is not None:
|
||||
query = ' '.join((
|
||||
|
|
Loading…
Reference in a new issue