Remove Kodi Helix support

This commit is contained in:
croneter 2018-02-25 13:35:09 +01:00
parent eb0d1d21bb
commit ae6fb9ecfa

View file

@ -234,76 +234,38 @@ class Kodidb_Functions():
self.cursor.execute(query, (pathid, filename,)) self.cursor.execute(query, (pathid, filename,))
def addCountries(self, kodiid, countries, mediatype): def addCountries(self, kodiid, countries, mediatype):
if v.KODIVERSION > 14: for country in countries:
# Kodi Isengard, Jarvis, Krypton query = ' '.join((
for country in countries:
query = ' '.join((
"SELECT country_id", "SELECT country_id",
"FROM country", "FROM country",
"WHERE name = ?", "WHERE name = ?",
"COLLATE NOCASE" "COLLATE NOCASE"
)) ))
self.cursor.execute(query, (country,)) self.cursor.execute(query, (country,))
try: try:
country_id = self.cursor.fetchone()[0] country_id = self.cursor.fetchone()[0]
except TypeError: except TypeError:
# Country entry does not exists # Country entry does not exists
self.cursor.execute("select coalesce(max(country_id),0) from country") self.cursor.execute("select coalesce(max(country_id),0) from country")
country_id = self.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(?, ?)"
self.cursor.execute(query, (country_id, country)) self.cursor.execute(query, (country_id, country))
log.debug("Add country to media, processing: %s" % country) log.debug("Add country to media, processing: %s" % country)
finally: # Assign country to content finally: # Assign country to content
query = ( query = (
''' '''
INSERT OR REPLACE INTO country_link( INSERT OR REPLACE INTO country_link(
country_id, media_id, media_type) country_id, media_id, media_type)
VALUES (?, ?, ?) VALUES (?, ?, ?)
''' '''
) )
self.cursor.execute(query, (country_id, kodiid, mediatype)) self.cursor.execute(query, (country_id, kodiid, mediatype))
else:
# Kodi Helix
for country in countries:
query = ' '.join((
"SELECT idCountry",
"FROM country",
"WHERE strCountry = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (country,))
try:
idCountry = self.cursor.fetchone()[0]
except TypeError:
# Country entry does not exists
self.cursor.execute("select coalesce(max(idCountry),0) from country")
idCountry = self.cursor.fetchone()[0] + 1
query = "INSERT INTO country(idCountry, strCountry) values(?, ?)"
self.cursor.execute(query, (idCountry, country))
log.debug("Add country to media, processing: %s" % country)
finally:
# Only movies have a country field
if "movie" in mediatype:
query = (
'''
INSERT OR REPLACE INTO countrylinkmovie(
idCountry, idMovie)
VALUES (?, ?)
'''
)
self.cursor.execute(query, (idCountry, kodiid))
def _getactorid(self, name): def _getactorid(self, name):
""" """
@ -420,202 +382,82 @@ class Kodidb_Functions():
return result return result
def addGenres(self, kodiid, genres, mediatype): def addGenres(self, kodiid, genres, mediatype):
# Delete current genres for clean slate
query = ' '.join((
"DELETE FROM genre_link",
# Kodi Isengard, Jarvis, Krypton "WHERE media_id = ?",
if v.KODIVERSION > 14: "AND media_type = ?"
# Delete current genres for clean slate ))
self.cursor.execute(query, (kodiid, mediatype,))
# Add genres
for genre in genres:
query = ' '.join(( query = ' '.join((
"DELETE FROM genre_link", "SELECT genre_id",
"WHERE media_id = ?", "FROM genre",
"AND media_type = ?" "WHERE name = ?",
"COLLATE NOCASE"
)) ))
self.cursor.execute(query, (kodiid, mediatype,)) self.cursor.execute(query, (genre,))
# Add genres try:
for genre in genres: genre_id = self.cursor.fetchone()[0]
except TypeError:
# Create genre in database
self.cursor.execute("select coalesce(max(genre_id),0) from genre")
genre_id = self.cursor.fetchone()[0] + 1
query = ' '.join(( query = "INSERT INTO genre(genre_id, name) values(?, ?)"
self.cursor.execute(query, (genre_id, genre))
log.debug("Add Genres to media, processing: %s" % genre)
finally:
# Assign genre to item
query = (
'''
INSERT OR REPLACE INTO genre_link(
genre_id, media_id, media_type)
"SELECT genre_id", VALUES (?, ?, ?)
"FROM genre", '''
"WHERE name = ?", )
"COLLATE NOCASE" self.cursor.execute(query, (genre_id, kodiid, mediatype))
))
self.cursor.execute(query, (genre,))
try:
genre_id = self.cursor.fetchone()[0]
except TypeError:
# Create genre in database
self.cursor.execute("select coalesce(max(genre_id),0) from genre")
genre_id = self.cursor.fetchone()[0] + 1
query = "INSERT INTO genre(genre_id, name) values(?, ?)"
self.cursor.execute(query, (genre_id, genre))
log.debug("Add Genres to media, processing: %s" % genre)
finally:
# Assign genre to item
query = (
'''
INSERT OR REPLACE INTO genre_link(
genre_id, media_id, media_type)
VALUES (?, ?, ?)
'''
)
self.cursor.execute(query, (genre_id, kodiid, mediatype))
else:
# Kodi Helix
# Delete current genres for clean slate
if "movie" in mediatype:
self.cursor.execute("DELETE FROM genrelinkmovie WHERE idMovie = ?", (kodiid,))
elif "tvshow" in mediatype:
self.cursor.execute("DELETE FROM genrelinktvshow WHERE idShow = ?", (kodiid,))
elif "musicvideo" in mediatype:
self.cursor.execute("DELETE FROM genrelinkmusicvideo WHERE idMVideo = ?", (kodiid,))
# Add genres
for genre in genres:
query = ' '.join((
"SELECT idGenre",
"FROM genre",
"WHERE strGenre = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (genre,))
try:
idGenre = self.cursor.fetchone()[0]
except TypeError:
# Create genre in database
self.cursor.execute("select coalesce(max(idGenre),0) from genre")
idGenre = self.cursor.fetchone()[0] + 1
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
self.cursor.execute(query, (idGenre, genre))
log.debug("Add Genres to media, processing: %s" % genre)
finally:
# Assign genre to item
if "movie" in mediatype:
query = (
'''
INSERT OR REPLACE into genrelinkmovie(
idGenre, idMovie)
VALUES (?, ?)
'''
)
elif "tvshow" in mediatype:
query = (
'''
INSERT OR REPLACE into genrelinktvshow(
idGenre, idShow)
VALUES (?, ?)
'''
)
elif "musicvideo" in mediatype:
query = (
'''
INSERT OR REPLACE into genrelinkmusicvideo(
idGenre, idMVideo)
VALUES (?, ?)
'''
)
else: return # Item is invalid
self.cursor.execute(query, (idGenre, kodiid))
def addStudios(self, kodiid, studios, mediatype): def addStudios(self, kodiid, studios, mediatype):
for studio in studios: for studio in studios:
if v.KODIVERSION > 14: query = ' '.join((
# Kodi Isengard, Jarvis, Krypton
query = ' '.join((
"SELECT studio_id", "SELECT studio_id",
"FROM studio", "FROM studio",
"WHERE name = ?", "WHERE name = ?",
"COLLATE NOCASE" "COLLATE NOCASE"
)) ))
self.cursor.execute(query, (studio,)) self.cursor.execute(query, (studio,))
try: try:
studioid = self.cursor.fetchone()[0] studioid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
# Studio does not exists. # Studio does not exists.
self.cursor.execute("select coalesce(max(studio_id),0) from studio") self.cursor.execute("select coalesce(max(studio_id),0) from studio")
studioid = self.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(?, ?)"
self.cursor.execute(query, (studioid, studio)) self.cursor.execute(query, (studioid, studio))
log.debug("Add Studios to media, processing: %s" % studio) log.debug("Add Studios to media, processing: %s" % studio)
finally: # Assign studio to item finally: # Assign studio to item
query = ( query = (
''' '''
INSERT OR REPLACE INTO studio_link( INSERT OR REPLACE INTO studio_link(
studio_id, media_id, media_type) studio_id, media_id, media_type)
VALUES (?, ?, ?) VALUES (?, ?, ?)
''') ''')
self.cursor.execute(query, (studioid, kodiid, mediatype)) self.cursor.execute(query, (studioid, kodiid, mediatype))
else:
# Kodi Helix
query = ' '.join((
"SELECT idstudio",
"FROM studio",
"WHERE strstudio = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (studio,))
try:
studioid = self.cursor.fetchone()[0]
except TypeError:
# Studio does not exists.
self.cursor.execute("select coalesce(max(idstudio),0) from studio")
studioid = self.cursor.fetchone()[0] + 1
query = "INSERT INTO studio(idstudio, strstudio) values(?, ?)"
self.cursor.execute(query, (studioid, studio))
log.debug("Add Studios to media, processing: %s" % studio)
finally: # Assign studio to item
if "movie" in mediatype:
query = (
'''
INSERT OR REPLACE INTO studiolinkmovie(idstudio, idMovie)
VALUES (?, ?)
''')
elif "musicvideo" in mediatype:
query = (
'''
INSERT OR REPLACE INTO studiolinkmusicvideo(idstudio, idMVideo)
VALUES (?, ?)
''')
elif "tvshow" in mediatype:
query = (
'''
INSERT OR REPLACE INTO studiolinktvshow(idstudio, idShow)
VALUES (?, ?)
''')
elif "episode" in mediatype:
query = (
'''
INSERT OR REPLACE INTO studiolinkepisode(idstudio, idEpisode)
VALUES (?, ?)
''')
self.cursor.execute(query, (studioid, kodiid))
def addStreams(self, fileid, streamdetails, runtime): def addStreams(self, fileid, streamdetails, runtime):
@ -904,24 +746,13 @@ class Kodidb_Functions():
def addTags(self, kodiid, tags, mediatype): def addTags(self, kodiid, tags, mediatype):
# First, delete any existing tags associated to the id # First, delete any existing tags associated to the id
if v.KODIVERSION > 14: query = ' '.join((
# Kodi Isengard, Jarvis, Krypton
query = ' '.join((
"DELETE FROM tag_link", "DELETE FROM tag_link",
"WHERE media_id = ?", "WHERE media_id = ?",
"AND media_type = ?" "AND media_type = ?"
)) ))
self.cursor.execute(query, (kodiid, mediatype)) self.cursor.execute(query, (kodiid, mediatype))
else:
# Kodi Helix
query = ' '.join((
"DELETE FROM taglinks",
"WHERE idMedia = ?",
"AND media_type = ?"
))
self.cursor.execute(query, (kodiid, mediatype))
# Add tags # Add tags
log.debug("Adding Tags: %s" % tags) log.debug("Adding Tags: %s" % tags)
@ -929,205 +760,101 @@ class Kodidb_Functions():
self.addTag(kodiid, tag, mediatype) self.addTag(kodiid, tag, mediatype)
def addTag(self, kodiid, tag, mediatype): def addTag(self, kodiid, tag, mediatype):
if v.KODIVERSION > 14: query = ' '.join((
# Kodi Isengard, Jarvis, Krypton
query = ' '.join((
"SELECT tag_id", "SELECT tag_id",
"FROM tag", "FROM tag",
"WHERE name = ?", "WHERE name = ?",
"COLLATE NOCASE" "COLLATE NOCASE"
)) ))
self.cursor.execute(query, (tag,)) self.cursor.execute(query, (tag,))
try: try:
tag_id = self.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
tag_id = self.createTag(tag) tag_id = self.createTag(tag)
log.debug("Adding tag: %s" % tag) log.debug("Adding tag: %s" % tag)
finally: finally:
# Assign tag to item # Assign tag to item
query = ( query = (
''' '''
INSERT OR REPLACE INTO tag_link( INSERT OR REPLACE INTO tag_link(
tag_id, media_id, media_type) tag_id, media_id, media_type)
VALUES (?, ?, ?) VALUES (?, ?, ?)
''' '''
) )
self.cursor.execute(query, (tag_id, kodiid, mediatype)) self.cursor.execute(query, (tag_id, kodiid, mediatype))
else:
# Kodi Helix
query = ' '.join((
"SELECT idTag",
"FROM tag",
"WHERE strTag = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (tag,))
try:
tag_id = self.cursor.fetchone()[0]
except TypeError:
# Create the tag
tag_id = self.createTag(tag)
log.debug("Adding tag: %s" % tag)
finally:
# Assign tag to item
query = (
'''
INSERT OR REPLACE INTO taglinks(
idTag, idMedia, media_type)
VALUES (?, ?, ?)
'''
)
self.cursor.execute(query, (tag_id, kodiid, mediatype))
def createTag(self, name): def createTag(self, name):
# This will create and return the tag_id # This will create and return the tag_id
if v.KODIVERSION > 14: query = ' '.join((
# Kodi Isengard, Jarvis, Krypton
query = ' '.join((
"SELECT tag_id", "SELECT tag_id",
"FROM tag", "FROM tag",
"WHERE name = ?", "WHERE name = ?",
"COLLATE NOCASE" "COLLATE NOCASE"
)) ))
self.cursor.execute(query, (name,)) self.cursor.execute(query, (name,))
try: try:
tag_id = self.cursor.fetchone()[0] tag_id = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("select coalesce(max(tag_id),0) from tag") self.cursor.execute("select coalesce(max(tag_id),0) from tag")
tag_id = self.cursor.fetchone()[0] + 1 tag_id = self.cursor.fetchone()[0] + 1
query = "INSERT INTO tag(tag_id, name) values(?, ?)"
self.cursor.execute(query, (tag_id, name))
log.debug("Create tag_id: %s name: %s" % (tag_id, name))
else:
# Kodi Helix
query = ' '.join((
"SELECT idTag",
"FROM tag",
"WHERE strTag = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (name,))
try:
tag_id = self.cursor.fetchone()[0]
except TypeError:
self.cursor.execute("select coalesce(max(idTag),0) from tag")
tag_id = self.cursor.fetchone()[0] + 1
query = "INSERT INTO tag(idTag, strTag) values(?, ?)"
self.cursor.execute(query, (tag_id, name))
log.debug("Create idTag: %s name: %s" % (tag_id, name))
query = "INSERT INTO tag(tag_id, name) values(?, ?)"
self.cursor.execute(query, (tag_id, name))
log.debug("Create tag_id: %s name: %s" % (tag_id, name))
return tag_id return tag_id
def updateTag(self, oldtag, newtag, kodiid, mediatype): def updateTag(self, oldtag, newtag, kodiid, mediatype):
if v.KODIVERSION > 14: try:
# Kodi Isengard, Jarvis, Krypton query = ' '.join((
try:
query = ' '.join((
"UPDATE tag_link", "UPDATE tag_link",
"SET tag_id = ?", "SET tag_id = ?",
"WHERE media_id = ?", "WHERE media_id = ?",
"AND media_type = ?", "AND media_type = ?",
"AND tag_id = ?" "AND tag_id = ?"
)) ))
self.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
query = ' '.join(( query = ' '.join((
"DELETE FROM tag_link", "DELETE FROM tag_link",
"WHERE media_id = ?", "WHERE media_id = ?",
"AND media_type = ?", "AND media_type = ?",
"AND tag_id = ?" "AND tag_id = ?"
)) ))
self.cursor.execute(query, (kodiid, mediatype, oldtag,)) self.cursor.execute(query, (kodiid, mediatype, oldtag,))
else:
# Kodi Helix
try:
query = ' '.join((
"UPDATE taglinks",
"SET idTag = ?",
"WHERE idMedia = ?",
"AND media_type = ?",
"AND idTag = ?"
))
self.cursor.execute(query, (newtag, kodiid, mediatype, oldtag,))
except Exception as e:
# The new tag we are going to apply already exists for this item
# delete current tag instead
query = ' '.join((
"DELETE FROM taglinks",
"WHERE idMedia = ?",
"AND media_type = ?",
"AND idTag = ?"
))
self.cursor.execute(query, (kodiid, mediatype, oldtag,))
def removeTag(self, kodiid, tagname, mediatype): def removeTag(self, kodiid, tagname, mediatype):
if v.KODIVERSION > 14: query = ' '.join((
# Kodi Isengard, Jarvis, Krypton
query = ' '.join((
"SELECT tag_id", "SELECT tag_id",
"FROM tag", "FROM tag",
"WHERE name = ?", "WHERE name = ?",
"COLLATE NOCASE" "COLLATE NOCASE"
)) ))
self.cursor.execute(query, (tagname,)) self.cursor.execute(query, (tagname,))
try: try:
tag_id = self.cursor.fetchone()[0] tag_id = self.cursor.fetchone()[0]
except TypeError: except TypeError:
return return
else:
query = ' '.join((
"DELETE FROM tag_link",
"WHERE media_id = ?",
"AND media_type = ?",
"AND tag_id = ?"
))
self.cursor.execute(query, (kodiid, mediatype, tag_id,))
else: else:
# Kodi Helix
query = ' '.join(( query = ' '.join((
"SELECT idTag", "DELETE FROM tag_link",
"FROM tag", "WHERE media_id = ?",
"WHERE strTag = ?", "AND media_type = ?",
"COLLATE NOCASE" "AND tag_id = ?"
)) ))
self.cursor.execute(query, (tagname,)) self.cursor.execute(query, (kodiid, mediatype, tag_id,))
try:
tag_id = self.cursor.fetchone()[0]
except TypeError:
return
else:
query = ' '.join((
"DELETE FROM taglinks",
"WHERE idMedia = ?",
"AND media_type = ?",
"AND idTag = ?"
))
self.cursor.execute(query, (kodiid, mediatype, tag_id,))
def addSets(self, movieid, collections, kodicursor): def addSets(self, movieid, collections, kodicursor):
for setname in collections: for setname in collections:
@ -1263,25 +990,14 @@ class Kodidb_Functions():
# Create the album # Create the album
self.cursor.execute("select coalesce(max(idAlbum),0) from album") self.cursor.execute("select coalesce(max(idAlbum),0) from album")
albumid = self.cursor.fetchone()[0] + 1 albumid = self.cursor.fetchone()[0] + 1
if v.KODIVERSION > 14: query = (
query = ( '''
''' INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType)
INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType)
VALUES (?, ?, ?, ?)
'''
)
self.cursor.execute(query, (albumid, name, musicbrainz, "album"))
else: # Helix
query = (
'''
INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID)
VALUES (?, ?, ?)
'''
)
self.cursor.execute(query, (albumid, name, musicbrainz))
VALUES (?, ?, ?, ?)
'''
)
self.cursor.execute(query, (albumid, name, musicbrainz, "album"))
return albumid return albumid
def addMusicGenres(self, kodiid, genres, mediatype): def addMusicGenres(self, kodiid, genres, mediatype):