Link parent paths in Kodi video DB

- Should speed up On Deck video node
This commit is contained in:
tomkat83 2016-04-22 14:46:08 +02:00
parent 97c261bc4d
commit 07ed22e44a
2 changed files with 41 additions and 6 deletions

View file

@ -1040,6 +1040,8 @@ class TVShows(Items):
toplevelpath = "plugin://plugin.video.plexkodiconnect.tvshows/"
path = "%s%s/" % (toplevelpath, itemid)
# Add top path
toppathid = kodi_db.addPath(toplevelpath)
# UPDATE THE TVSHOW #####
if update_item:
self.logMsg("UPDATE tvshow itemid: %s - Title: %s" % (itemid, title), 1)
@ -1062,8 +1064,6 @@ class TVShows(Items):
else:
self.logMsg("ADD tvshow itemid: %s - Title: %s" % (itemid, title), 1)
# Add top path
toppathid = kodi_db.addPath(toplevelpath)
query = ' '.join((
"UPDATE path",
@ -1098,10 +1098,11 @@ class TVShows(Items):
query = ' '.join((
"UPDATE path",
"SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?",
"SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?, ",
"idParentPath = ?"
"WHERE idPath = ?"
))
kodicursor.execute(query, (path, None, None, 1, pathid))
kodicursor.execute(query, (path, None, None, 1, toppathid, pathid))
# Process cast
people = API.getPeopleList()
@ -1324,6 +1325,7 @@ class TVShows(Items):
# Network share
filename = playurl.rsplit("/", 1)[1]
path = playurl.replace(filename, "")
parentPathId = kodi_db.getParentPathId(path)
if doIndirect:
# Set plugin path and media flags using real filename
if playurl is not None:
@ -1341,6 +1343,8 @@ class TVShows(Items):
'mode': "play"
}
filename = "%s?%s" % (path, urllib.urlencode(params))
parentPathId = kodi_db.addPath(
'plugin://plugin.video.plexkodiconnect.tvshows/')
# UPDATE THE EPISODE #####
if update_item:
@ -1421,10 +1425,11 @@ class TVShows(Items):
query = ' '.join((
"UPDATE path",
"SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?",
"SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?, ",
"idParentPath = ?"
"WHERE idPath = ?"
))
kodicursor.execute(query, (path, None, None, 1, pathid))
kodicursor.execute(query, (path, None, None, 1, parentPathId, pathid))
# Update the file
query = ' '.join((

View file

@ -3,6 +3,7 @@
###############################################################################
import xbmc
from ntpath import dirname
import artwork
import clientinfo
@ -66,6 +67,35 @@ class Kodidb_Functions():
'metadata.local',
'plugin://plugin.video.plexkodiconnect.movies%%'))
def getParentPathId(self, path):
"""
Video DB: Adds all subdirectories to SQL path while setting a "trail"
of parentPathId
"""
if "\\" in path:
# Local path
parentpath = "%s\\" % dirname(dirname(path))
else:
# Network path
parentpath = "%s/" % dirname(dirname(path))
pathid = self.getPath(parentpath)
if pathid is None:
self.cursor.execute("select coalesce(max(idPath),0) from path")
pathid = self.cursor.fetchone()[0] + 1
query = ' '.join((
"INSERT INTO path(idPath, strPath)",
"VALUES (?, ?)"
))
self.cursor.execute(query, (pathid, parentpath))
parentPathid = self.getParentPathId(parentpath)
query = ' '.join((
"UPDATE path",
"SET idParentPath = ?",
"WHERE idPath = ?"
))
self.cursor.execute(query, (parentPathid, pathid))
return pathid
def addPath(self, path, strHash=None):
# SQL won't return existing paths otherwise
if path is None: