mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 02:06:09 +00:00
self cursor
This commit is contained in:
parent
6922eea15f
commit
a6a3da60f2
1 changed files with 1153 additions and 1190 deletions
|
@ -33,20 +33,18 @@ class Kodidb_Functions():
|
||||||
|
|
||||||
def addPath(self, path):
|
def addPath(self, path):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
"SELECT idPath",
|
"SELECT idPath",
|
||||||
"FROM path",
|
"FROM path",
|
||||||
"WHERE strPath = ?"
|
"WHERE strPath = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (path,))
|
self.cursor.execute(query, (path,))
|
||||||
try:
|
try:
|
||||||
pathid = cursor.fetchone()[0]
|
pathid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
cursor.execute("select coalesce(max(idPath),0) from path")
|
self.cursor.execute("select coalesce(max(idPath),0) from path")
|
||||||
pathid = cursor.fetchone()[0] + 1
|
pathid = self.cursor.fetchone()[0] + 1
|
||||||
query = (
|
query = (
|
||||||
'''
|
'''
|
||||||
INSERT INTO path(
|
INSERT INTO path(
|
||||||
|
@ -55,23 +53,21 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (pathid, path))
|
self.cursor.execute(query, (pathid, path))
|
||||||
|
|
||||||
return pathid
|
return pathid
|
||||||
|
|
||||||
def getPath(self, path):
|
def getPath(self, path):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
"SELECT idPath",
|
"SELECT idPath",
|
||||||
"FROM path",
|
"FROM path",
|
||||||
"WHERE strPath = ?"
|
"WHERE strPath = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (path,))
|
self.cursor.execute(query, (path,))
|
||||||
try:
|
try:
|
||||||
pathid = cursor.fetchone()[0]
|
pathid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pathid = None
|
pathid = None
|
||||||
|
|
||||||
|
@ -79,8 +75,6 @@ class Kodidb_Functions():
|
||||||
|
|
||||||
def addFile(self, filename, pathid):
|
def addFile(self, filename, pathid):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
"SELECT idFile",
|
"SELECT idFile",
|
||||||
|
@ -88,12 +82,12 @@ class Kodidb_Functions():
|
||||||
"WHERE strFilename = ?",
|
"WHERE strFilename = ?",
|
||||||
"AND idPath = ?"
|
"AND idPath = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (filename, pathid,))
|
self.cursor.execute(query, (filename, pathid,))
|
||||||
try:
|
try:
|
||||||
fileid = cursor.fetchone()[0]
|
fileid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
cursor.execute("select coalesce(max(idFile),0) from files")
|
self.cursor.execute("select coalesce(max(idFile),0) from files")
|
||||||
fileid = cursor.fetchone()[0] + 1
|
fileid = self.cursor.fetchone()[0] + 1
|
||||||
query = (
|
query = (
|
||||||
'''
|
'''
|
||||||
INSERT INTO files(
|
INSERT INTO files(
|
||||||
|
@ -102,23 +96,21 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (fileid, filename))
|
self.cursor.execute(query, (fileid, filename))
|
||||||
|
|
||||||
return fileid
|
return fileid
|
||||||
|
|
||||||
def getFile(self, fileid):
|
def getFile(self, fileid):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
"SELECT strFilename",
|
"SELECT strFilename",
|
||||||
"FROM files",
|
"FROM files",
|
||||||
"WHERE idFile = ?"
|
"WHERE idFile = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (fileid,))
|
self.cursor.execute(query, (fileid,))
|
||||||
try:
|
try:
|
||||||
filename = cursor.fetchone()[0]
|
filename = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
filename = ""
|
filename = ""
|
||||||
|
|
||||||
|
@ -139,8 +131,6 @@ class Kodidb_Functions():
|
||||||
|
|
||||||
def addCountries(self, kodiid, countries, mediatype):
|
def addCountries(self, kodiid, countries, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
if self.kodiversion in (15, 16, 17):
|
if self.kodiversion in (15, 16, 17):
|
||||||
# Kodi Isengard, Jarvis, Krypton
|
# Kodi Isengard, Jarvis, Krypton
|
||||||
for country in countries:
|
for country in countries:
|
||||||
|
@ -151,18 +141,18 @@ class Kodidb_Functions():
|
||||||
"WHERE name = ?",
|
"WHERE name = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (country,))
|
self.cursor.execute(query, (country,))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
country_id = cursor.fetchone()[0]
|
country_id = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Country entry does not exists
|
# Country entry does not exists
|
||||||
cursor.execute("select coalesce(max(country_id),0) from country")
|
self.cursor.execute("select coalesce(max(country_id),0) from country")
|
||||||
country_id = cursor.fetchone()[0] + 1
|
country_id = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO country(country_id, name) values(?, ?)"
|
query = "INSERT INTO country(country_id, name) values(?, ?)"
|
||||||
cursor.execute(query, (country_id, country))
|
self.cursor.execute(query, (country_id, country))
|
||||||
self.logMsg("Add country to media, processing: %s" % country, 2)
|
self.logMsg("Add country to media, processing: %s" % country, 2)
|
||||||
|
|
||||||
finally: # Assign country to content
|
finally: # Assign country to content
|
||||||
|
@ -174,7 +164,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (country_id, kodiid, mediatype))
|
self.cursor.execute(query, (country_id, kodiid, mediatype))
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
for country in countries:
|
for country in countries:
|
||||||
|
@ -185,18 +175,18 @@ class Kodidb_Functions():
|
||||||
"WHERE strCountry = ?",
|
"WHERE strCountry = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (country,))
|
self.cursor.execute(query, (country,))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
idCountry = cursor.fetchone()[0]
|
idCountry = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Country entry does not exists
|
# Country entry does not exists
|
||||||
cursor.execute("select coalesce(max(idCountry),0) from country")
|
self.cursor.execute("select coalesce(max(idCountry),0) from country")
|
||||||
idCountry = cursor.fetchone()[0] + 1
|
idCountry = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO country(idCountry, strCountry) values(?, ?)"
|
query = "INSERT INTO country(idCountry, strCountry) values(?, ?)"
|
||||||
cursor.execute(query, (idCountry, country))
|
self.cursor.execute(query, (idCountry, country))
|
||||||
self.logMsg("Add country to media, processing: %s" % country, 2)
|
self.logMsg("Add country to media, processing: %s" % country, 2)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -210,14 +200,10 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (idCountry, kodiid))
|
self.cursor.execute(query, (idCountry, kodiid))
|
||||||
|
|
||||||
def addPeople(self, kodiid, people, mediatype):
|
def addPeople(self, kodiid, people, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
artwork = self.artwork
|
|
||||||
kodiversion = self.kodiversion
|
|
||||||
|
|
||||||
castorder = 1
|
castorder = 1
|
||||||
for person in people:
|
for person in people:
|
||||||
|
|
||||||
|
@ -226,7 +212,7 @@ class Kodidb_Functions():
|
||||||
thumb = person['imageurl']
|
thumb = person['imageurl']
|
||||||
|
|
||||||
# Kodi Isengard, Jarvis, Krypton
|
# Kodi Isengard, Jarvis, Krypton
|
||||||
if kodiversion in (15, 16, 17):
|
if self.kodiversion in (15, 16, 17):
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
"SELECT actor_id",
|
"SELECT actor_id",
|
||||||
|
@ -234,18 +220,18 @@ class Kodidb_Functions():
|
||||||
"WHERE name = ?",
|
"WHERE name = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (name,))
|
self.cursor.execute(query, (name,))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
actorid = cursor.fetchone()[0]
|
actorid = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Cast entry does not exists
|
# Cast entry does not exists
|
||||||
cursor.execute("select coalesce(max(actor_id),0) from actor")
|
self.cursor.execute("select coalesce(max(actor_id),0) from actor")
|
||||||
actorid = cursor.fetchone()[0] + 1
|
actorid = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO actor(actor_id, name) values(?, ?)"
|
query = "INSERT INTO actor(actor_id, name) values(?, ?)"
|
||||||
cursor.execute(query, (actorid, name))
|
self.cursor.execute(query, (actorid, name))
|
||||||
self.logMsg("Add people to media, processing: %s" % name, 2)
|
self.logMsg("Add people to media, processing: %s" % name, 2)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -260,7 +246,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (actorid, kodiid, mediatype, role, castorder))
|
self.cursor.execute(query, (actorid, kodiid, mediatype, role, castorder))
|
||||||
castorder += 1
|
castorder += 1
|
||||||
|
|
||||||
elif "Director" in type:
|
elif "Director" in type:
|
||||||
|
@ -272,7 +258,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (actorid, kodiid, mediatype))
|
self.cursor.execute(query, (actorid, kodiid, mediatype))
|
||||||
|
|
||||||
elif type in ("Writing", "Writer"):
|
elif type in ("Writing", "Writer"):
|
||||||
query = (
|
query = (
|
||||||
|
@ -283,7 +269,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (actorid, kodiid, mediatype))
|
self.cursor.execute(query, (actorid, kodiid, mediatype))
|
||||||
|
|
||||||
elif "Artist" in type:
|
elif "Artist" in type:
|
||||||
query = (
|
query = (
|
||||||
|
@ -294,7 +280,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (actorid, kodiid, mediatype))
|
self.cursor.execute(query, (actorid, kodiid, mediatype))
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
else:
|
else:
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -304,18 +290,18 @@ class Kodidb_Functions():
|
||||||
"WHERE strActor = ?",
|
"WHERE strActor = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (name,))
|
self.cursor.execute(query, (name,))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
actorid = cursor.fetchone()[0]
|
actorid = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Cast entry does not exists
|
# Cast entry does not exists
|
||||||
cursor.execute("select coalesce(max(idActor),0) from actors")
|
self.cursor.execute("select coalesce(max(idActor),0) from actors")
|
||||||
actorid = cursor.fetchone()[0] + 1
|
actorid = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO actors(idActor, strActor) values(?, ?)"
|
query = "INSERT INTO actors(idActor, strActor) values(?, ?)"
|
||||||
cursor.execute(query, (actorid, name))
|
self.cursor.execute(query, (actorid, name))
|
||||||
self.logMsg("Add people to media, processing: %s" % name, 2)
|
self.logMsg("Add people to media, processing: %s" % name, 2)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -352,7 +338,7 @@ class Kodidb_Functions():
|
||||||
)
|
)
|
||||||
else: return # Item is invalid
|
else: return # Item is invalid
|
||||||
|
|
||||||
cursor.execute(query, (actorid, kodiid, role, castorder))
|
self.cursor.execute(query, (actorid, kodiid, role, castorder))
|
||||||
castorder += 1
|
castorder += 1
|
||||||
|
|
||||||
elif "Director" in type:
|
elif "Director" in type:
|
||||||
|
@ -395,7 +381,7 @@ class Kodidb_Functions():
|
||||||
)
|
)
|
||||||
else: return # Item is invalid
|
else: return # Item is invalid
|
||||||
|
|
||||||
cursor.execute(query, (actorid, kodiid))
|
self.cursor.execute(query, (actorid, kodiid))
|
||||||
|
|
||||||
elif type in ("Writing", "Writer"):
|
elif type in ("Writing", "Writer"):
|
||||||
if "movie" in mediatype:
|
if "movie" in mediatype:
|
||||||
|
@ -418,7 +404,7 @@ class Kodidb_Functions():
|
||||||
)
|
)
|
||||||
else: return # Item is invalid
|
else: return # Item is invalid
|
||||||
|
|
||||||
cursor.execute(query, (actorid, kodiid))
|
self.cursor.execute(query, (actorid, kodiid))
|
||||||
|
|
||||||
elif "Artist" in type:
|
elif "Artist" in type:
|
||||||
query = (
|
query = (
|
||||||
|
@ -429,7 +415,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (actorid, kodiid))
|
self.cursor.execute(query, (actorid, kodiid))
|
||||||
|
|
||||||
# Add person image to art table
|
# Add person image to art table
|
||||||
if thumb:
|
if thumb:
|
||||||
|
@ -438,11 +424,10 @@ class Kodidb_Functions():
|
||||||
if "writing" in arttype:
|
if "writing" in arttype:
|
||||||
arttype = "writer"
|
arttype = "writer"
|
||||||
|
|
||||||
artwork.addOrUpdateArt(thumb, actorid, arttype, "thumb", cursor)
|
self.artwork.addOrUpdateArt(thumb, actorid, arttype, "thumb", cursor)
|
||||||
|
|
||||||
def addGenres(self, kodiid, genres, mediatype):
|
def addGenres(self, kodiid, genres, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
# Kodi Isengard, Jarvis, Krypton
|
# Kodi Isengard, Jarvis, Krypton
|
||||||
if self.kodiversion in (15, 16, 17):
|
if self.kodiversion in (15, 16, 17):
|
||||||
|
@ -453,7 +438,7 @@ class Kodidb_Functions():
|
||||||
"WHERE media_id = ?",
|
"WHERE media_id = ?",
|
||||||
"AND media_type = ?"
|
"AND media_type = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid, mediatype,))
|
self.cursor.execute(query, (kodiid, mediatype,))
|
||||||
|
|
||||||
# Add genres
|
# Add genres
|
||||||
for genre in genres:
|
for genre in genres:
|
||||||
|
@ -465,18 +450,18 @@ class Kodidb_Functions():
|
||||||
"WHERE name = ?",
|
"WHERE name = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (genre,))
|
self.cursor.execute(query, (genre,))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
genre_id = cursor.fetchone()[0]
|
genre_id = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Create genre in database
|
# Create genre in database
|
||||||
cursor.execute("select coalesce(max(genre_id),0) from genre")
|
self.cursor.execute("select coalesce(max(genre_id),0) from genre")
|
||||||
genre_id = cursor.fetchone()[0] + 1
|
genre_id = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO genre(genre_id, name) values(?, ?)"
|
query = "INSERT INTO genre(genre_id, name) values(?, ?)"
|
||||||
cursor.execute(query, (genre_id, genre))
|
self.cursor.execute(query, (genre_id, genre))
|
||||||
self.logMsg("Add Genres to media, processing: %s" % genre, 2)
|
self.logMsg("Add Genres to media, processing: %s" % genre, 2)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -489,16 +474,16 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (genre_id, kodiid, mediatype))
|
self.cursor.execute(query, (genre_id, kodiid, mediatype))
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
# Delete current genres for clean slate
|
# Delete current genres for clean slate
|
||||||
if "movie" in mediatype:
|
if "movie" in mediatype:
|
||||||
cursor.execute("DELETE FROM genrelinkmovie WHERE idMovie = ?", (kodiid,))
|
self.cursor.execute("DELETE FROM genrelinkmovie WHERE idMovie = ?", (kodiid,))
|
||||||
elif "tvshow" in mediatype:
|
elif "tvshow" in mediatype:
|
||||||
cursor.execute("DELETE FROM genrelinktvshow WHERE idShow = ?", (kodiid,))
|
self.cursor.execute("DELETE FROM genrelinktvshow WHERE idShow = ?", (kodiid,))
|
||||||
elif "musicvideo" in mediatype:
|
elif "musicvideo" in mediatype:
|
||||||
cursor.execute("DELETE FROM genrelinkmusicvideo WHERE idMVideo = ?", (kodiid,))
|
self.cursor.execute("DELETE FROM genrelinkmusicvideo WHERE idMVideo = ?", (kodiid,))
|
||||||
|
|
||||||
# Add genres
|
# Add genres
|
||||||
for genre in genres:
|
for genre in genres:
|
||||||
|
@ -510,18 +495,18 @@ class Kodidb_Functions():
|
||||||
"WHERE strGenre = ?",
|
"WHERE strGenre = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (genre,))
|
self.cursor.execute(query, (genre,))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
idGenre = cursor.fetchone()[0]
|
idGenre = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Create genre in database
|
# Create genre in database
|
||||||
cursor.execute("select coalesce(max(idGenre),0) from genre")
|
self.cursor.execute("select coalesce(max(idGenre),0) from genre")
|
||||||
idGenre = cursor.fetchone()[0] + 1
|
idGenre = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
|
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
|
||||||
cursor.execute(query, (idGenre, genre))
|
self.cursor.execute(query, (idGenre, genre))
|
||||||
self.logMsg("Add Genres to media, processing: %s" % genre, 2)
|
self.logMsg("Add Genres to media, processing: %s" % genre, 2)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -555,11 +540,10 @@ class Kodidb_Functions():
|
||||||
)
|
)
|
||||||
else: return # Item is invalid
|
else: return # Item is invalid
|
||||||
|
|
||||||
cursor.execute(query, (idGenre, kodiid))
|
self.cursor.execute(query, (idGenre, kodiid))
|
||||||
|
|
||||||
def addStudios(self, kodiid, studios, mediatype):
|
def addStudios(self, kodiid, studios, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
kodiversion = self.kodiversion
|
kodiversion = self.kodiversion
|
||||||
|
|
||||||
for studio in studios:
|
for studio in studios:
|
||||||
|
@ -573,17 +557,17 @@ class Kodidb_Functions():
|
||||||
"WHERE name = ?",
|
"WHERE name = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (studio,))
|
self.cursor.execute(query, (studio,))
|
||||||
try:
|
try:
|
||||||
studioid = cursor.fetchone()[0]
|
studioid = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Studio does not exists.
|
# Studio does not exists.
|
||||||
cursor.execute("select coalesce(max(studio_id),0) from studio")
|
self.cursor.execute("select coalesce(max(studio_id),0) from studio")
|
||||||
studioid = cursor.fetchone()[0] + 1
|
studioid = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO studio(studio_id, name) values(?, ?)"
|
query = "INSERT INTO studio(studio_id, name) values(?, ?)"
|
||||||
cursor.execute(query, (studioid, studio))
|
self.cursor.execute(query, (studioid, studio))
|
||||||
self.logMsg("Add Studios to media, processing: %s" % studio, 2)
|
self.logMsg("Add Studios to media, processing: %s" % studio, 2)
|
||||||
|
|
||||||
finally: # Assign studio to item
|
finally: # Assign studio to item
|
||||||
|
@ -594,7 +578,7 @@ class Kodidb_Functions():
|
||||||
|
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
''')
|
''')
|
||||||
cursor.execute(query, (studioid, kodiid, mediatype))
|
self.cursor.execute(query, (studioid, kodiid, mediatype))
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -604,17 +588,17 @@ class Kodidb_Functions():
|
||||||
"WHERE strstudio = ?",
|
"WHERE strstudio = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (studio,))
|
self.cursor.execute(query, (studio,))
|
||||||
try:
|
try:
|
||||||
studioid = cursor.fetchone()[0]
|
studioid = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Studio does not exists.
|
# Studio does not exists.
|
||||||
cursor.execute("select coalesce(max(idstudio),0) from studio")
|
self.cursor.execute("select coalesce(max(idstudio),0) from studio")
|
||||||
studioid = cursor.fetchone()[0] + 1
|
studioid = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO studio(idstudio, strstudio) values(?, ?)"
|
query = "INSERT INTO studio(idstudio, strstudio) values(?, ?)"
|
||||||
cursor.execute(query, (studioid, studio))
|
self.cursor.execute(query, (studioid, studio))
|
||||||
self.logMsg("Add Studios to media, processing: %s" % studio, 2)
|
self.logMsg("Add Studios to media, processing: %s" % studio, 2)
|
||||||
|
|
||||||
finally: # Assign studio to item
|
finally: # Assign studio to item
|
||||||
|
@ -642,14 +626,12 @@ class Kodidb_Functions():
|
||||||
INSERT OR REPLACE INTO studiolinkepisode(idstudio, idEpisode)
|
INSERT OR REPLACE INTO studiolinkepisode(idstudio, idEpisode)
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
''')
|
''')
|
||||||
cursor.execute(query, (studioid, kodiid))
|
self.cursor.execute(query, (studioid, kodiid))
|
||||||
|
|
||||||
def addStreams(self, fileid, streamdetails, runtime):
|
def addStreams(self, fileid, streamdetails, runtime):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
# First remove any existing entries
|
# First remove any existing entries
|
||||||
cursor.execute("DELETE FROM streamdetails WHERE idFile = ?", (fileid,))
|
self.cursor.execute("DELETE FROM streamdetails WHERE idFile = ?", (fileid,))
|
||||||
if streamdetails:
|
if streamdetails:
|
||||||
# Video details
|
# Video details
|
||||||
for videotrack in streamdetails['video']:
|
for videotrack in streamdetails['video']:
|
||||||
|
@ -662,7 +644,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (fileid, 0, videotrack['codec'],
|
self.cursor.execute(query, (fileid, 0, videotrack['codec'],
|
||||||
videotrack['aspect'], videotrack['width'], videotrack['height'],
|
videotrack['aspect'], videotrack['width'], videotrack['height'],
|
||||||
runtime ,videotrack['video3DFormat']))
|
runtime ,videotrack['video3DFormat']))
|
||||||
|
|
||||||
|
@ -676,7 +658,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (fileid, 1, audiotrack['codec'],
|
self.cursor.execute(query, (fileid, 1, audiotrack['codec'],
|
||||||
audiotrack['channels'], audiotrack['language']))
|
audiotrack['channels'], audiotrack['language']))
|
||||||
|
|
||||||
# Subtitles details
|
# Subtitles details
|
||||||
|
@ -689,19 +671,17 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (fileid, 2, subtitletrack))
|
self.cursor.execute(query, (fileid, 2, subtitletrack))
|
||||||
|
|
||||||
def addPlaystate(self, fileid, resume_seconds, total_seconds, playcount, dateplayed):
|
def addPlaystate(self, fileid, resume_seconds, total_seconds, playcount, dateplayed):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
# Delete existing resume point
|
# Delete existing resume point
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
"DELETE FROM bookmark",
|
"DELETE FROM bookmark",
|
||||||
"WHERE idFile = ?"
|
"WHERE idFile = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (fileid,))
|
self.cursor.execute(query, (fileid,))
|
||||||
|
|
||||||
# Set watched count
|
# Set watched count
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -710,12 +690,12 @@ class Kodidb_Functions():
|
||||||
"SET playCount = ?, lastPlayed = ?",
|
"SET playCount = ?, lastPlayed = ?",
|
||||||
"WHERE idFile = ?"
|
"WHERE idFile = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (playcount, dateplayed, fileid))
|
self.cursor.execute(query, (playcount, dateplayed, fileid))
|
||||||
|
|
||||||
# Set the resume bookmark
|
# Set the resume bookmark
|
||||||
if resume_seconds:
|
if resume_seconds:
|
||||||
cursor.execute("select coalesce(max(idBookmark),0) from bookmark")
|
self.cursor.execute("select coalesce(max(idBookmark),0) from bookmark")
|
||||||
bookmarkId = cursor.fetchone()[0] + 1
|
bookmarkId = self.cursor.fetchone()[0] + 1
|
||||||
query = (
|
query = (
|
||||||
'''
|
'''
|
||||||
INSERT INTO bookmark(
|
INSERT INTO bookmark(
|
||||||
|
@ -724,13 +704,11 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (bookmarkId, fileid, resume_seconds, total_seconds,
|
self.cursor.execute(query, (bookmarkId, fileid, resume_seconds, total_seconds,
|
||||||
"DVDPlayer", 1))
|
"DVDPlayer", 1))
|
||||||
|
|
||||||
def addTags(self, kodiid, tags, mediatype):
|
def addTags(self, kodiid, tags, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
# First, delete any existing tags associated to the id
|
# First, delete any existing tags associated to the id
|
||||||
if self.kodiversion in (15, 16, 17):
|
if self.kodiversion in (15, 16, 17):
|
||||||
# Kodi Isengard, Jarvis, Krypton
|
# Kodi Isengard, Jarvis, Krypton
|
||||||
|
@ -740,7 +718,7 @@ class Kodidb_Functions():
|
||||||
"WHERE media_id = ?",
|
"WHERE media_id = ?",
|
||||||
"AND media_type = ?"
|
"AND media_type = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid, mediatype))
|
self.cursor.execute(query, (kodiid, mediatype))
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -749,7 +727,7 @@ class Kodidb_Functions():
|
||||||
"WHERE idMedia = ?",
|
"WHERE idMedia = ?",
|
||||||
"AND media_type = ?"
|
"AND media_type = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid, mediatype))
|
self.cursor.execute(query, (kodiid, mediatype))
|
||||||
|
|
||||||
# Add tags
|
# Add tags
|
||||||
self.logMsg("Adding Tags: %s" % tags, 2)
|
self.logMsg("Adding Tags: %s" % tags, 2)
|
||||||
|
@ -758,8 +736,6 @@ class Kodidb_Functions():
|
||||||
|
|
||||||
def addTag(self, kodiid, tag, mediatype):
|
def addTag(self, kodiid, tag, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
if self.kodiversion in (15, 16, 17):
|
if self.kodiversion in (15, 16, 17):
|
||||||
# Kodi Isengard, Jarvis, Krypton
|
# Kodi Isengard, Jarvis, Krypton
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -769,9 +745,9 @@ class Kodidb_Functions():
|
||||||
"WHERE name = ?",
|
"WHERE name = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (tag,))
|
self.cursor.execute(query, (tag,))
|
||||||
try:
|
try:
|
||||||
tag_id = cursor.fetchone()[0]
|
tag_id = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Create the tag, because it does not exist
|
# Create the tag, because it does not exist
|
||||||
|
@ -788,7 +764,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (tag_id, kodiid, mediatype))
|
self.cursor.execute(query, (tag_id, kodiid, mediatype))
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -798,9 +774,9 @@ class Kodidb_Functions():
|
||||||
"WHERE strTag = ?",
|
"WHERE strTag = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (tag,))
|
self.cursor.execute(query, (tag,))
|
||||||
try:
|
try:
|
||||||
tag_id = cursor.fetchone()[0]
|
tag_id = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Create the tag
|
# Create the tag
|
||||||
|
@ -817,12 +793,10 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (tag_id, kodiid, mediatype))
|
self.cursor.execute(query, (tag_id, kodiid, mediatype))
|
||||||
|
|
||||||
def createTag(self, name):
|
def createTag(self, name):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
# This will create and return the tag_id
|
# This will create and return the tag_id
|
||||||
if self.kodiversion in (15, 16, 17):
|
if self.kodiversion in (15, 16, 17):
|
||||||
# Kodi Isengard, Jarvis, Krypton
|
# Kodi Isengard, Jarvis, Krypton
|
||||||
|
@ -833,16 +807,16 @@ class Kodidb_Functions():
|
||||||
"WHERE name = ?",
|
"WHERE name = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (name,))
|
self.cursor.execute(query, (name,))
|
||||||
try:
|
try:
|
||||||
tag_id = cursor.fetchone()[0]
|
tag_id = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
cursor.execute("select coalesce(max(tag_id),0) from tag")
|
self.cursor.execute("select coalesce(max(tag_id),0) from tag")
|
||||||
tag_id = cursor.fetchone()[0] + 1
|
tag_id = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO tag(tag_id, name) values(?, ?)"
|
query = "INSERT INTO tag(tag_id, name) values(?, ?)"
|
||||||
cursor.execute(query, (tag_id, name))
|
self.cursor.execute(query, (tag_id, name))
|
||||||
self.logMsg("Create tag_id: %s name: %s" % (tag_id, name), 2)
|
self.logMsg("Create tag_id: %s name: %s" % (tag_id, name), 2)
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
|
@ -853,23 +827,22 @@ class Kodidb_Functions():
|
||||||
"WHERE strTag = ?",
|
"WHERE strTag = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (name,))
|
self.cursor.execute(query, (name,))
|
||||||
try:
|
try:
|
||||||
tag_id = cursor.fetchone()[0]
|
tag_id = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
cursor.execute("select coalesce(max(idTag),0) from tag")
|
self.cursor.execute("select coalesce(max(idTag),0) from tag")
|
||||||
tag_id = cursor.fetchone()[0] + 1
|
tag_id = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO tag(idTag, strTag) values(?, ?)"
|
query = "INSERT INTO tag(idTag, strTag) values(?, ?)"
|
||||||
cursor.execute(query, (tag_id, name))
|
self.cursor.execute(query, (tag_id, name))
|
||||||
self.logMsg("Create idTag: %s name: %s" % (tag_id, name), 2)
|
self.logMsg("Create idTag: %s name: %s" % (tag_id, name), 2)
|
||||||
|
|
||||||
return tag_id
|
return tag_id
|
||||||
|
|
||||||
def updateTag(self, oldtag, newtag, kodiid, mediatype):
|
def updateTag(self, oldtag, newtag, kodiid, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
self.logMsg("Updating: %s with %s for %s: %s" % (oldtag, newtag, mediatype, kodiid), 2)
|
self.logMsg("Updating: %s with %s for %s: %s" % (oldtag, newtag, mediatype, kodiid), 2)
|
||||||
|
|
||||||
if self.kodiversion in (15, 16, 17):
|
if self.kodiversion in (15, 16, 17):
|
||||||
|
@ -883,7 +856,7 @@ class Kodidb_Functions():
|
||||||
"AND media_type = ?",
|
"AND media_type = ?",
|
||||||
"AND tag_id = ?"
|
"AND tag_id = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (newtag, kodiid, mediatype, oldtag,))
|
self.cursor.execute(query, (newtag, kodiid, mediatype, oldtag,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# The new tag we are going to apply already exists for this item
|
# The new tag we are going to apply already exists for this item
|
||||||
# delete current tag instead
|
# delete current tag instead
|
||||||
|
@ -895,7 +868,7 @@ class Kodidb_Functions():
|
||||||
"AND media_type = ?",
|
"AND media_type = ?",
|
||||||
"AND tag_id = ?"
|
"AND tag_id = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid, mediatype, oldtag,))
|
self.cursor.execute(query, (kodiid, mediatype, oldtag,))
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
try:
|
try:
|
||||||
|
@ -907,7 +880,7 @@ class Kodidb_Functions():
|
||||||
"AND media_type = ?",
|
"AND media_type = ?",
|
||||||
"AND idTag = ?"
|
"AND idTag = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (newtag, kodiid, mediatype, oldtag,))
|
self.cursor.execute(query, (newtag, kodiid, mediatype, oldtag,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# The new tag we are going to apply already exists for this item
|
# The new tag we are going to apply already exists for this item
|
||||||
# delete current tag instead
|
# delete current tag instead
|
||||||
|
@ -919,12 +892,10 @@ class Kodidb_Functions():
|
||||||
"AND media_type = ?",
|
"AND media_type = ?",
|
||||||
"AND idTag = ?"
|
"AND idTag = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid, mediatype, oldtag,))
|
self.cursor.execute(query, (kodiid, mediatype, oldtag,))
|
||||||
|
|
||||||
def removeTag(self, kodiid, tagname, mediatype):
|
def removeTag(self, kodiid, tagname, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
if self.kodiversion in (15, 16, 17):
|
if self.kodiversion in (15, 16, 17):
|
||||||
# Kodi Isengard, Jarvis, Krypton
|
# Kodi Isengard, Jarvis, Krypton
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -934,9 +905,9 @@ class Kodidb_Functions():
|
||||||
"WHERE name = ?",
|
"WHERE name = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (tagname,))
|
self.cursor.execute(query, (tagname,))
|
||||||
try:
|
try:
|
||||||
tag_id = cursor.fetchone()[0]
|
tag_id = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -947,7 +918,7 @@ class Kodidb_Functions():
|
||||||
"AND media_type = ?",
|
"AND media_type = ?",
|
||||||
"AND tag_id = ?"
|
"AND tag_id = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid, mediatype, tag_id,))
|
self.cursor.execute(query, (kodiid, mediatype, tag_id,))
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -957,9 +928,9 @@ class Kodidb_Functions():
|
||||||
"WHERE strTag = ?",
|
"WHERE strTag = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (tagname,))
|
self.cursor.execute(query, (tagname,))
|
||||||
try:
|
try:
|
||||||
tag_id = cursor.fetchone()[0]
|
tag_id = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -970,11 +941,10 @@ class Kodidb_Functions():
|
||||||
"AND media_type = ?",
|
"AND media_type = ?",
|
||||||
"AND idTag = ?"
|
"AND idTag = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid, mediatype, tag_id,))
|
self.cursor.execute(query, (kodiid, mediatype, tag_id,))
|
||||||
|
|
||||||
def createBoxset(self, boxsetname):
|
def createBoxset(self, boxsetname):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
self.logMsg("Adding boxset: %s" % boxsetname, 2)
|
self.logMsg("Adding boxset: %s" % boxsetname, 2)
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
|
@ -983,16 +953,16 @@ class Kodidb_Functions():
|
||||||
"WHERE strSet = ?",
|
"WHERE strSet = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (boxsetname,))
|
self.cursor.execute(query, (boxsetname,))
|
||||||
try:
|
try:
|
||||||
setid = cursor.fetchone()[0]
|
setid = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
cursor.execute("select coalesce(max(idSet),0) from sets")
|
self.cursor.execute("select coalesce(max(idSet),0) from sets")
|
||||||
setid = cursor.fetchone()[0] + 1
|
setid = self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO sets(idSet, strSet) values(?, ?)"
|
query = "INSERT INTO sets(idSet, strSet) values(?, ?)"
|
||||||
cursor.execute(query, (setid, boxsetname))
|
self.cursor.execute(query, (setid, boxsetname))
|
||||||
|
|
||||||
return setid
|
return setid
|
||||||
|
|
||||||
|
@ -1018,8 +988,6 @@ class Kodidb_Functions():
|
||||||
|
|
||||||
def addSeason(self, showid, seasonnumber):
|
def addSeason(self, showid, seasonnumber):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
"SELECT idSeason",
|
"SELECT idSeason",
|
||||||
|
@ -1027,30 +995,28 @@ class Kodidb_Functions():
|
||||||
"WHERE idShow = ?",
|
"WHERE idShow = ?",
|
||||||
"AND season = ?"
|
"AND season = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (showid, seasonnumber,))
|
self.cursor.execute(query, (showid, seasonnumber,))
|
||||||
try:
|
try:
|
||||||
seasonid = cursor.fetchone()[0]
|
seasonid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
cursor.execute("select coalesce(max(idSeason),0) from seasons")
|
self.cursor.execute("select coalesce(max(idSeason),0) from seasons")
|
||||||
seasonid = cursor.fetchone()[0] + 1
|
seasonid = self.cursor.fetchone()[0] + 1
|
||||||
query = "INSERT INTO seasons(idSeason, idShow, season) values(?, ?, ?)"
|
query = "INSERT INTO seasons(idSeason, idShow, season) values(?, ?, ?)"
|
||||||
cursor.execute(query, (seasonid, showid, seasonnumber))
|
self.cursor.execute(query, (seasonid, showid, seasonnumber))
|
||||||
|
|
||||||
return seasonid
|
return seasonid
|
||||||
|
|
||||||
def addArtist(self, name, musicbrainz):
|
def addArtist(self, name, musicbrainz):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
"SELECT idArtist, strArtist",
|
"SELECT idArtist, strArtist",
|
||||||
"FROM artist",
|
"FROM artist",
|
||||||
"WHERE strMusicBrainzArtistID = ?"
|
"WHERE strMusicBrainzArtistID = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (musicbrainz,))
|
self.cursor.execute(query, (musicbrainz,))
|
||||||
try:
|
try:
|
||||||
result = cursor.fetchone()
|
result = self.cursor.fetchone()
|
||||||
artistid = result[0]
|
artistid = result[0]
|
||||||
artistname = result[1]
|
artistname = result[1]
|
||||||
|
|
||||||
|
@ -1063,12 +1029,12 @@ class Kodidb_Functions():
|
||||||
"WHERE strArtist = ?",
|
"WHERE strArtist = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (name,))
|
self.cursor.execute(query, (name,))
|
||||||
try:
|
try:
|
||||||
artistid = cursor.fetchone()[0]
|
artistid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
cursor.execute("select coalesce(max(idArtist),0) from artist")
|
self.cursor.execute("select coalesce(max(idArtist),0) from artist")
|
||||||
artistid = cursor.fetchone()[0] + 1
|
artistid = self.cursor.fetchone()[0] + 1
|
||||||
query = (
|
query = (
|
||||||
'''
|
'''
|
||||||
INSERT INTO artist(idArtist, strArtist, strMusicBrainzArtistID)
|
INSERT INTO artist(idArtist, strArtist, strMusicBrainzArtistID)
|
||||||
|
@ -1076,18 +1042,17 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (artistid, name, musicbrainz))
|
self.cursor.execute(query, (artistid, name, musicbrainz))
|
||||||
else:
|
else:
|
||||||
if artistname != name:
|
if artistname != name:
|
||||||
query = "UPDATE artist SET strArtist = ? WHERE idArtist = ?"
|
query = "UPDATE artist SET strArtist = ? WHERE idArtist = ?"
|
||||||
cursor.execute(query, (name, artistid,))
|
self.cursor.execute(query, (name, artistid,))
|
||||||
|
|
||||||
return artistid
|
return artistid
|
||||||
|
|
||||||
def addAlbum(self, name, musicbrainz):
|
def addAlbum(self, name, musicbrainz):
|
||||||
|
|
||||||
kodiversion = self.kodiversion
|
kodiversion = self.kodiversion
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
|
||||||
|
@ -1095,13 +1060,13 @@ class Kodidb_Functions():
|
||||||
"FROM album",
|
"FROM album",
|
||||||
"WHERE strMusicBrainzAlbumID = ?"
|
"WHERE strMusicBrainzAlbumID = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (musicbrainz,))
|
self.cursor.execute(query, (musicbrainz,))
|
||||||
try:
|
try:
|
||||||
albumid = cursor.fetchone()[0]
|
albumid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Create the album
|
# Create the album
|
||||||
cursor.execute("select coalesce(max(idAlbum),0) from album")
|
self.cursor.execute("select coalesce(max(idAlbum),0) from album")
|
||||||
albumid = cursor.fetchone()[0] + 1
|
albumid = self.cursor.fetchone()[0] + 1
|
||||||
if kodiversion in (15, 16, 17):
|
if kodiversion in (15, 16, 17):
|
||||||
query = (
|
query = (
|
||||||
'''
|
'''
|
||||||
|
@ -1110,7 +1075,7 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?, ?)
|
VALUES (?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (albumid, name, musicbrainz, "album"))
|
self.cursor.execute(query, (albumid, name, musicbrainz, "album"))
|
||||||
else: # Helix
|
else: # Helix
|
||||||
query = (
|
query = (
|
||||||
'''
|
'''
|
||||||
|
@ -1119,14 +1084,12 @@ class Kodidb_Functions():
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (albumid, name, musicbrainz))
|
self.cursor.execute(query, (albumid, name, musicbrainz))
|
||||||
|
|
||||||
return albumid
|
return albumid
|
||||||
|
|
||||||
def addMusicGenres(self, kodiid, genres, mediatype):
|
def addMusicGenres(self, kodiid, genres, mediatype):
|
||||||
|
|
||||||
cursor = self.cursor
|
|
||||||
|
|
||||||
if mediatype == "album":
|
if mediatype == "album":
|
||||||
|
|
||||||
# Delete current genres for clean slate
|
# Delete current genres for clean slate
|
||||||
|
@ -1135,7 +1098,7 @@ class Kodidb_Functions():
|
||||||
"DELETE FROM album_genre",
|
"DELETE FROM album_genre",
|
||||||
"WHERE idAlbum = ?"
|
"WHERE idAlbum = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid,))
|
self.cursor.execute(query, (kodiid,))
|
||||||
|
|
||||||
for genre in genres:
|
for genre in genres:
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -1145,18 +1108,18 @@ class Kodidb_Functions():
|
||||||
"WHERE strGenre = ?",
|
"WHERE strGenre = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (genre,))
|
self.cursor.execute(query, (genre,))
|
||||||
try:
|
try:
|
||||||
genreid = cursor.fetchone()[0]
|
genreid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Create the genre
|
# Create the genre
|
||||||
cursor.execute("select coalesce(max(idGenre),0) from genre")
|
self.cursor.execute("select coalesce(max(idGenre),0) from genre")
|
||||||
genreid = cursor.fetchone()[0] + 1
|
genreid = self.cursor.fetchone()[0] + 1
|
||||||
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
|
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
|
||||||
cursor.execute(query, (genreid, genre))
|
self.cursor.execute(query, (genreid, genre))
|
||||||
|
|
||||||
query = "INSERT OR REPLACE INTO album_genre(idGenre, idAlbum) values(?, ?)"
|
query = "INSERT OR REPLACE INTO album_genre(idGenre, idAlbum) values(?, ?)"
|
||||||
cursor.execute(query, (genreid, kodiid))
|
self.cursor.execute(query, (genreid, kodiid))
|
||||||
|
|
||||||
elif mediatype == "song":
|
elif mediatype == "song":
|
||||||
|
|
||||||
|
@ -1166,7 +1129,7 @@ class Kodidb_Functions():
|
||||||
"DELETE FROM song_genre",
|
"DELETE FROM song_genre",
|
||||||
"WHERE idSong = ?"
|
"WHERE idSong = ?"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (kodiid,))
|
self.cursor.execute(query, (kodiid,))
|
||||||
|
|
||||||
for genre in genres:
|
for genre in genres:
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -1176,15 +1139,15 @@ class Kodidb_Functions():
|
||||||
"WHERE strGenre = ?",
|
"WHERE strGenre = ?",
|
||||||
"COLLATE NOCASE"
|
"COLLATE NOCASE"
|
||||||
))
|
))
|
||||||
cursor.execute(query, (genre,))
|
self.cursor.execute(query, (genre,))
|
||||||
try:
|
try:
|
||||||
genreid = cursor.fetchone()[0]
|
genreid = self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Create the genre
|
# Create the genre
|
||||||
cursor.execute("select coalesce(max(idGenre),0) from genre")
|
self.cursor.execute("select coalesce(max(idGenre),0) from genre")
|
||||||
genreid = cursor.fetchone()[0] + 1
|
genreid = self.cursor.fetchone()[0] + 1
|
||||||
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
|
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
|
||||||
cursor.execute(query, (genreid, genre))
|
self.cursor.execute(query, (genreid, genre))
|
||||||
|
|
||||||
query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)"
|
query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)"
|
||||||
cursor.execute(query, (genreid, kodiid))
|
self.cursor.execute(query, (genreid, kodiid))
|
Loading…
Reference in a new issue