Optimize adding values to Kodi databases by not using sqlite COALESCE command

This commit is contained in:
croneter 2019-12-06 11:56:16 +01:00
parent f4ea051c81
commit e257e5426e
4 changed files with 141 additions and 260 deletions

View file

@ -74,31 +74,21 @@ class Movie(ItemBase):
api.date_created()) api.date_created())
if file_id != old_kodi_fileid: if file_id != old_kodi_fileid:
self.kodidb.remove_file(old_kodi_fileid) self.kodidb.remove_file(old_kodi_fileid)
rating_id = self.kodidb.get_ratingid(kodi_id, rating_id = self.kodidb.update_ratings(kodi_id,
v.KODI_TYPE_MOVIE)
self.kodidb.update_ratings(kodi_id,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
"default", "default",
api.rating(), api.rating(),
api.votecount(), api.votecount())
rating_id)
# update new uniqueid Kodi 17
if api.provider('imdb') is not None: if api.provider('imdb') is not None:
uniqueid = self.kodidb.get_uniqueid(kodi_id, uniqueid = self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_MOVIE)
self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
api.provider('imdb'), 'imdb',
"imdb", api.provider('imdb'))
uniqueid)
elif api.provider('tmdb') is not None: elif api.provider('tmdb') is not None:
uniqueid = self.kodidb.get_uniqueid(kodi_id, uniqueid = self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_MOVIE)
self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
api.provider('tmdb'), 'tmdb',
"tmdb", api.provider('tmdb'))
uniqueid)
else: else:
self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_MOVIE) self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_MOVIE)
uniqueid = -1 uniqueid = -1
@ -114,24 +104,18 @@ class Movie(ItemBase):
file_id = self.kodidb.add_file(filename, file_id = self.kodidb.add_file(filename,
kodi_pathid, kodi_pathid,
api.date_created()) api.date_created())
rating_id = self.kodidb.add_ratingid() rating_id = self.kodidb.add_ratings(kodi_id,
self.kodidb.add_ratings(rating_id,
kodi_id,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
"default", "default",
api.rating(), api.rating(),
api.votecount()) api.votecount())
if api.provider('imdb') is not None: if api.provider('imdb') is not None:
uniqueid = self.kodidb.add_uniqueid_id() uniqueid = self.kodidb.add_uniqueid(kodi_id,
self.kodidb.add_uniqueid(uniqueid,
kodi_id,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
api.provider('imdb'), api.provider('imdb'),
"imdb") "imdb")
elif api.provider('tmdb') is not None: elif api.provider('tmdb') is not None:
uniqueid = self.kodidb.add_uniqueid_id() uniqueid = self.kodidb.add_uniqueid(kodi_id,
self.kodidb.add_uniqueid(uniqueid,
kodi_id,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
api.provider('tmdb'), api.provider('tmdb'),
"tmdb") "tmdb")

View file

@ -189,29 +189,21 @@ class Show(TvShowMixin, ItemBase):
if update_item: if update_item:
LOG.info("UPDATE tvshow plex_id: %s - %s", plex_id, api.title()) LOG.info("UPDATE tvshow plex_id: %s - %s", plex_id, api.title())
# update new ratings Kodi 17 # update new ratings Kodi 17
rating_id = self.kodidb.get_ratingid(kodi_id, v.KODI_TYPE_SHOW) rating_id = self.kodidb.update_ratings(kodi_id,
self.kodidb.update_ratings(kodi_id,
v.KODI_TYPE_SHOW, v.KODI_TYPE_SHOW,
"default", "default",
api.rating(), api.rating(),
api.votecount(), api.votecount())
rating_id)
if api.provider('tvdb') is not None: if api.provider('tvdb') is not None:
uniqueid = self.kodidb.get_uniqueid(kodi_id, uniqueid = self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_SHOW)
self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_SHOW, v.KODI_TYPE_SHOW,
api.provider('tvdb'),
'tvdb', 'tvdb',
uniqueid) api.provider('tvdb'))
elif api.provider('tmdb') is not None: elif api.provider('tmdb') is not None:
uniqueid = self.kodidb.get_uniqueid(kodi_id, uniqueid = self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_SHOW)
self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_SHOW, v.KODI_TYPE_SHOW,
api.provider('tmdb'),
'tmdb', 'tmdb',
uniqueid) api.provider('tmdb'))
else: else:
self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_SHOW) self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_SHOW)
uniqueid = -1 uniqueid = -1
@ -239,24 +231,18 @@ class Show(TvShowMixin, ItemBase):
LOG.info("ADD tvshow plex_id: %s - %s", plex_id, api.title()) LOG.info("ADD tvshow plex_id: %s - %s", plex_id, api.title())
# Link the path # Link the path
self.kodidb.add_showlinkpath(kodi_id, kodi_pathid) self.kodidb.add_showlinkpath(kodi_id, kodi_pathid)
rating_id = self.kodidb.get_ratingid(kodi_id, v.KODI_TYPE_SHOW) rating_id = self.kodidb.add_ratings(kodi_id,
self.kodidb.add_ratings(rating_id,
kodi_id,
v.KODI_TYPE_SHOW, v.KODI_TYPE_SHOW,
"default", "default",
api.rating(), api.rating(),
api.votecount()) api.votecount())
if api.provider('tvdb'): if api.provider('tvdb'):
uniqueid = self.kodidb.add_uniqueid_id() uniqueid = self.kodidb.add_uniqueid(kodi_id,
self.kodidb.add_uniqueid(uniqueid,
kodi_id,
v.KODI_TYPE_SHOW, v.KODI_TYPE_SHOW,
api.provider('tvdb'), api.provider('tvdb'),
'tvdb') 'tvdb')
if api.provider('tmdb'): if api.provider('tmdb'):
uniqueid = self.kodidb.add_uniqueid_id() uniqueid = self.kodidb.add_uniqueid(kodi_id,
self.kodidb.add_uniqueid(uniqueid,
kodi_id,
v.KODI_TYPE_SHOW, v.KODI_TYPE_SHOW,
api.provider('tmdb'), api.provider('tmdb'),
'tmdb') 'tmdb')
@ -489,30 +475,21 @@ class Episode(TvShowMixin, ItemBase):
self.kodidb.remove_file(old_kodi_fileid) self.kodidb.remove_file(old_kodi_fileid)
if not app.SYNC.direct_paths: if not app.SYNC.direct_paths:
self.kodidb.remove_file(old_kodi_fileid_2) self.kodidb.remove_file(old_kodi_fileid_2)
ratingid = self.kodidb.get_ratingid(kodi_id, ratingid = self.kodidb.update_ratings(kodi_id,
v.KODI_TYPE_EPISODE)
self.kodidb.update_ratings(kodi_id,
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
"default", "default",
api.rating(), api.rating(),
api.votecount(), api.votecount())
ratingid)
if api.provider('tvdb'): if api.provider('tvdb'):
uniqueid = self.kodidb.get_uniqueid(kodi_id, uniqueid = self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_EPISODE)
self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
api.provider('tvdb'), 'tvdb',
"tvdb", api.provider('tvdb'))
uniqueid)
elif api.provider('tmdb'): elif api.provider('tmdb'):
uniqueid = self.kodidb.get_uniqueid(kodi_id, uniqueid = self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_EPISODE)
self.kodidb.update_uniqueid(kodi_id,
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
api.provider('tmdb'), 'tmdb',
"tmdb", api.provider('tmdb'))
uniqueid)
else: else:
self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_EPISODE) self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_EPISODE)
uniqueid = -1 uniqueid = -1
@ -537,6 +514,7 @@ class Episode(TvShowMixin, ItemBase):
airs_before_episode, airs_before_episode,
playurl, playurl,
kodi_pathid, kodi_pathid,
uniqueid,
kodi_fileid, # and NOT kodi_fileid_2 kodi_fileid, # and NOT kodi_fileid_2
parent_id, parent_id,
api.userrating(), api.userrating(),
@ -577,24 +555,18 @@ class Episode(TvShowMixin, ItemBase):
else: else:
kodi_fileid_2 = None kodi_fileid_2 = None
rating_id = self.kodidb.add_ratingid() rating_id = self.kodidb.add_ratings(kodi_id,
self.kodidb.add_ratings(rating_id,
kodi_id,
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
"default", "default",
api.rating(), api.rating(),
api.votecount()) api.votecount())
if api.provider('tvdb'): if api.provider('tvdb'):
uniqueid = self.kodidb.add_uniqueid_id() uniqueid = self.kodidb.add_uniqueid(kodi_id,
self.kodidb.add_uniqueid(uniqueid,
kodi_id,
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
api.provider('tvdb'), api.provider('tvdb'),
"tvdb") "tvdb")
elif api.provider('tmdb'): elif api.provider('tmdb'):
uniqueid = self.kodidb.add_uniqueid_id() uniqueid = self.kodidb.add_uniqueid(kodi_id,
self.kodidb.add_uniqueid(uniqueid,
kodi_id,
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
api.provider('tmdb'), api.provider('tmdb'),
"tmdb") "tmdb")
@ -624,6 +596,7 @@ class Episode(TvShowMixin, ItemBase):
airs_before_episode, airs_before_episode,
playurl, playurl,
kodi_pathid, kodi_pathid,
uniqueid,
parent_id, parent_id,
api.userrating()) api.userrating())
self.kodidb.set_resume(kodi_fileid, self.kodidb.set_resume(kodi_fileid,

View file

@ -25,13 +25,9 @@ class KodiMusicDB(common.KodiDBBase):
try: try:
pathid = self.cursor.fetchone()[0] pathid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path") self.cursor.execute('INSERT INTO path(strPath, strHash) VALUES (?, ?)',
pathid = self.cursor.fetchone()[0] + 1 (path, '123'))
self.cursor.execute(''' pathid = self.cursor.lastrowid
INSERT INTO path(idPath, strPath, strHash)
VALUES (?, ?, ?)
''',
(pathid, path, '123'))
return pathid return pathid
@db.catch_operationalerrors @db.catch_operationalerrors
@ -382,10 +378,9 @@ class KodiMusicDB(common.KodiDBBase):
genreid = self.cursor.fetchone()[0] genreid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
# Create the genre # Create the genre
self.cursor.execute('SELECT COALESCE(MAX(idGenre),0) FROM genre') self.cursor.execute('INSERT INTO genre(strGenre) VALUES(?)',
genreid = self.cursor.fetchone()[0] + 1 (genre, ))
self.cursor.execute('INSERT INTO genre(idGenre, strGenre) VALUES(?, ?)', genreid = self.cursor.lastrowid
(genreid, genre))
self.cursor.execute(''' self.cursor.execute('''
INSERT OR REPLACE INTO album_genre( INSERT OR REPLACE INTO album_genre(
idGenre, idGenre,
@ -403,10 +398,9 @@ class KodiMusicDB(common.KodiDBBase):
genreid = self.cursor.fetchone()[0] genreid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
# Create the genre # Create the genre
self.cursor.execute('SELECT COALESCE(MAX(idGenre),0) FROM genre') self.cursor.execute('INSERT INTO genre(strGenre) VALUES (?)',
genreid = self.cursor.fetchone()[0] + 1 (genre, ))
self.cursor.execute('INSERT INTO genre(idGenre, strGenre) values(?, ?)', genreid = self.cursor.lastrowid
(genreid, genre))
self.cursor.execute(''' self.cursor.execute('''
INSERT OR REPLACE INTO song_genre( INSERT OR REPLACE INTO song_genre(
idGenre, idGenre,
@ -550,15 +544,11 @@ class KodiMusicDB(common.KodiDBBase):
except TypeError: except TypeError:
# Krypton has a dummy first entry idArtist: 1 strArtist: # Krypton has a dummy first entry idArtist: 1 strArtist:
# [Missing Tag] strMusicBrainzArtistID: Artist Tag Missing # [Missing Tag] strMusicBrainzArtistID: Artist Tag Missing
self.cursor.execute('SELECT COALESCE(MAX(idArtist),1) FROM artist')
artistid = self.cursor.fetchone()[0] + 1
self.cursor.execute(''' self.cursor.execute('''
INSERT INTO artist( INSERT INTO artist(strArtist, strMusicBrainzArtistID)
idArtist, VALUES (?, ?)
strArtist, ''', (name, musicbrainz))
strMusicBrainzArtistID) artistid = self.cursor.lastrowid
VALUES (?, ?, ?)
''', (artistid, name, musicbrainz))
else: else:
if artistname != name: if artistname != name:
self.cursor.execute('UPDATE artist SET strArtist = ? WHERE idArtist = ?', self.cursor.execute('UPDATE artist SET strArtist = ? WHERE idArtist = ?',

View file

@ -40,19 +40,15 @@ class KodiVideoDB(common.KodiDBBase):
""" """
path_id = self.get_path(MOVIE_PATH) path_id = self.get_path(MOVIE_PATH)
if path_id is None: if path_id is None:
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
path_id = self.cursor.fetchone()[0] + 1
query = ''' query = '''
INSERT INTO path(idPath, INSERT INTO path(strPath,
strPath,
strContent, strContent,
strScraper, strScraper,
noUpdate, noUpdate,
exclude) exclude)
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
''' '''
self.cursor.execute(query, (path_id, self.cursor.execute(query, (MOVIE_PATH,
MOVIE_PATH,
'movies', 'movies',
'metadata.local', 'metadata.local',
1, 1,
@ -60,19 +56,15 @@ class KodiVideoDB(common.KodiDBBase):
# And TV shows # And TV shows
path_id = self.get_path(SHOW_PATH) path_id = self.get_path(SHOW_PATH)
if path_id is None: if path_id is None:
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
path_id = self.cursor.fetchone()[0] + 1
query = ''' query = '''
INSERT INTO path(idPath, INSERT INTO path(strPath,
strPath,
strContent, strContent,
strScraper, strScraper,
noUpdate, noUpdate,
exclude) exclude)
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
''' '''
self.cursor.execute(query, (path_id, self.cursor.execute(query, (SHOW_PATH,
SHOW_PATH,
'tvshows', 'tvshows',
'metadata.local', 'metadata.local',
1, 1,
@ -89,13 +81,12 @@ class KodiVideoDB(common.KodiDBBase):
path_ops.decode_path(path_ops.path.pardir))) path_ops.decode_path(path_ops.path.pardir)))
pathid = self.get_path(parentpath) pathid = self.get_path(parentpath)
if pathid is None: if pathid is None:
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
pathid = self.cursor.fetchone()[0] + 1
self.cursor.execute(''' self.cursor.execute('''
INSERT INTO path(idPath, strPath, dateAdded) INSERT INTO path(strPath, dateAdded)
VALUES (?, ?, ?) VALUES (?, ?)
''', ''',
(pathid, parentpath, timing.kodi_now())) (parentpath, timing.kodi_now()))
pathid = self.cursor.lastrowid
if parentpath != path: if parentpath != path:
# In case we end up having media in the filesystem root, C:\ # In case we end up having media in the filesystem root, C:\
parent_id = self.parent_path_id(parentpath) parent_id = self.parent_path_id(parentpath)
@ -127,21 +118,19 @@ class KodiVideoDB(common.KodiDBBase):
try: try:
pathid = self.cursor.fetchone()[0] pathid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("SELECT COALESCE(MAX(idPath),0) FROM path")
pathid = self.cursor.fetchone()[0] + 1
self.cursor.execute(''' self.cursor.execute('''
INSERT INTO path( INSERT INTO path(
idPath,
strPath, strPath,
dateAdded, dateAdded,
idParentPath, idParentPath,
strContent, strContent,
strScraper, strScraper,
noUpdate) noUpdate)
VALUES (?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
''', ''',
(pathid, path, date_added, id_parent_path, (path, date_added, id_parent_path, content,
content, scraper, 1)) scraper, 1))
pathid = self.cursor.lastrowid
return pathid return pathid
def get_path(self, path): def get_path(self, path):
@ -161,18 +150,12 @@ class KodiVideoDB(common.KodiDBBase):
Adds the filename [unicode] to the table files if not already added Adds the filename [unicode] to the table files if not already added
and returns the idFile. and returns the idFile.
""" """
self.cursor.execute('SELECT COALESCE(MAX(idFile), 0) FROM files')
file_id = self.cursor.fetchone()[0] + 1
self.cursor.execute(''' self.cursor.execute('''
INSERT INTO files( INSERT INTO files(idPath, strFilename, dateAdded)
idFile, VALUES (?, ?, ?)
idPath,
strFilename,
dateAdded)
VALUES (?, ?, ?, ?)
''', ''',
(file_id, path_id, filename, date_added)) (path_id, filename, date_added))
return file_id return self.cursor.lastrowid
def modify_file(self, filename, path_id, date_added): def modify_file(self, filename, path_id, date_added):
self.cursor.execute('SELECT idFile FROM files WHERE idPath = ? AND strFilename = ?', self.cursor.execute('SELECT idFile FROM files WHERE idPath = ? AND strFilename = ?',
@ -261,11 +244,9 @@ class KodiVideoDB(common.KodiDBBase):
try: try:
entry_id = self.cursor.fetchone()[0] entry_id = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute('SELECT COALESCE(MAX(%s), %s) FROM %s' self.cursor.execute('INSERT INTO %s(name) VALUES(?)' % table,
% (key, first_id - 1, table)) (entry, ))
entry_id = self.cursor.fetchone()[0] + 1 entry_id = self.cursor.lastrowid
self.cursor.execute('INSERT INTO %s(%s, name) values(?, ?)'
% (table, key), (entry_id, entry))
finally: finally:
entry_ids.append(entry_id) entry_ids.append(entry_id)
# Now process the ids obtained from the names # Now process the ids obtained from the names
@ -458,10 +439,8 @@ class KodiVideoDB(common.KodiDBBase):
@db.catch_operationalerrors @db.catch_operationalerrors
def _new_actor_id(self, name, art_url): def _new_actor_id(self, name, art_url):
# Not yet in actor DB, add person # Not yet in actor DB, add person
self.cursor.execute('SELECT COALESCE(MAX(actor_id), 0) FROM actor') self.cursor.execute('INSERT INTO actor(name) VALUES (?)', (name, ))
actor_id = self.cursor.fetchone()[0] + 1 actor_id = self.cursor.lastrowid
self.cursor.execute('INSERT INTO actor(actor_id, name) VALUES (?, ?)',
(actor_id, name))
if art_url: if art_url:
self.add_art(art_url, actor_id, 'actor', 'thumb') self.add_art(art_url, actor_id, 'actor', 'thumb')
return actor_id return actor_id
@ -649,12 +628,8 @@ class KodiVideoDB(common.KodiDBBase):
(playcount or None, dateplayed, file_id)) (playcount or None, dateplayed, file_id))
# Set the resume bookmark # Set the resume bookmark
if resume_seconds: if resume_seconds:
self.cursor.execute(
'SELECT COALESCE(MAX(idBookmark), 0) FROM bookmark')
bookmark_id = self.cursor.fetchone()[0] + 1
self.cursor.execute(''' self.cursor.execute('''
INSERT INTO bookmark( INSERT INTO bookmark(
idBookmark,
idFile, idFile,
timeInSeconds, timeInSeconds,
totalTimeInSeconds, totalTimeInSeconds,
@ -662,9 +637,8 @@ class KodiVideoDB(common.KodiDBBase):
player, player,
playerState, playerState,
type) type)
VALUES (?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?)
''', (bookmark_id, ''', (file_id,
file_id,
resume_seconds, resume_seconds,
total_seconds, total_seconds,
'', '',
@ -682,10 +656,8 @@ class KodiVideoDB(common.KodiDBBase):
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('INSERT INTO tag(name) VALUES(?)', (name, ))
tag_id = self.cursor.fetchone()[0] + 1 tag_id = self.cursor.lastrowid
self.cursor.execute('INSERT INTO tag(tag_id, name) VALUES(?, ?)',
(tag_id, name))
return tag_id return tag_id
@db.catch_operationalerrors @db.catch_operationalerrors
@ -717,10 +689,8 @@ class KodiVideoDB(common.KodiDBBase):
try: try:
setid = self.cursor.fetchone()[0] setid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("SELECT COALESCE(MAX(idSet), 0) FROM sets") self.cursor.execute('INSERT INTO sets(strSet) VALUES(?)', (set_name, ))
setid = self.cursor.fetchone()[0] + 1 setid = self.cursor.lastrowid
self.cursor.execute('INSERT INTO sets(idSet, strSet) VALUES(?, ?)',
(setid, set_name))
return setid return setid
@db.catch_operationalerrors @db.catch_operationalerrors
@ -768,19 +738,14 @@ class KodiVideoDB(common.KodiDBBase):
Adds a TV show season to the Kodi video DB or simply returns the ID, Adds a TV show season to the Kodi video DB or simply returns the ID,
if there already is an entry in the DB if there already is an entry in the DB
""" """
self.cursor.execute("SELECT COALESCE(MAX(idSeason),0) FROM seasons") self.cursor.execute('INSERT INTO seasons(idShow, season) VALUES (?, ?)',
seasonid = self.cursor.fetchone()[0] + 1 (showid, seasonnumber))
self.cursor.execute(''' return self.cursor.lastrowid
INSERT INTO seasons(idSeason, idShow, season)
VALUES (?, ?, ?)
''', (seasonid, showid, seasonnumber))
return seasonid
@db.catch_operationalerrors @db.catch_operationalerrors
def add_uniqueid(self, *args): def add_uniqueid(self, *args):
""" """
Feed with: Feed with:
uniqueid_id: int
media_id: int media_id: int
media_type: string media_type: string
value: string value: string
@ -788,39 +753,24 @@ class KodiVideoDB(common.KodiDBBase):
""" """
self.cursor.execute(''' self.cursor.execute('''
INSERT INTO uniqueid( INSERT INTO uniqueid(
uniqueid_id,
media_id, media_id,
media_type, media_type,
value, value,
type) type)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?)
''', (args)) ''', (args))
return self.cursor.lastrowid
def add_uniqueid_id(self):
self.cursor.execute('SELECT COALESCE(MAX(uniqueid_id), 0) FROM uniqueid')
return self.cursor.fetchone()[0] + 1
def get_uniqueid(self, kodi_id, kodi_type):
"""
Returns the uniqueid_id
"""
self.cursor.execute('SELECT uniqueid_id FROM uniqueid WHERE media_id = ? AND media_type =?',
(kodi_id, kodi_type))
try:
return self.cursor.fetchone()[0]
except TypeError:
return self.add_uniqueid_id()
@db.catch_operationalerrors @db.catch_operationalerrors
def update_uniqueid(self, *args): def update_uniqueid(self, *args):
""" """
Pass in media_id, media_type, value, type, uniqueid_id Pass in value, media_id, media_type, type
""" """
self.cursor.execute(''' self.cursor.execute('''
UPDATE uniqueid INSERT OR REPLACE INTO uniqueid(media_id, media_type, type, value)
SET media_id = ?, media_type = ?, value = ?, type = ? VALUES(?, ?, ?, ?)
WHERE uniqueid_id = ?
''', (args)) ''', (args))
return self.cursor.lastrowid
@db.catch_operationalerrors @db.catch_operationalerrors
def remove_uniqueid(self, kodi_id, kodi_type): def remove_uniqueid(self, kodi_id, kodi_type):
@ -830,54 +780,36 @@ class KodiVideoDB(common.KodiDBBase):
self.cursor.execute('DELETE FROM uniqueid WHERE media_id = ? AND media_type = ?', self.cursor.execute('DELETE FROM uniqueid WHERE media_id = ? AND media_type = ?',
(kodi_id, kodi_type)) (kodi_id, kodi_type))
def add_ratingid(self):
self.cursor.execute('SELECT COALESCE(MAX(rating_id),0) FROM rating')
return self.cursor.fetchone()[0] + 1
def get_ratingid(self, kodi_id, kodi_type):
"""
Create if needed and return the unique rating_id from rating table
"""
self.cursor.execute('SELECT rating_id FROM rating WHERE media_id = ? AND media_type = ?',
(kodi_id, kodi_type))
try:
return self.cursor.fetchone()[0]
except TypeError:
return self.add_ratingid()
@db.catch_operationalerrors @db.catch_operationalerrors
def update_ratings(self, *args): def update_ratings(self, *args):
""" """
Feed with media_id, media_type, rating_type, rating, votes, rating_id Feed with media_id, media_type, rating_type, rating, votes, rating_id
""" """
self.cursor.execute(''' self.cursor.execute('''
UPDATE rating INSERT OR REPLACE INTO
SET media_id = ?, rating(media_id, media_type, rating_type, rating, votes)
media_type = ?, VALUES (?, ?, ?, ?, ?)
rating_type = ?,
rating = ?,
votes = ?
WHERE rating_id = ?
''', (args)) ''', (args))
return self.cursor.lastrowid
@db.catch_operationalerrors @db.catch_operationalerrors
def add_ratings(self, *args): def add_ratings(self, *args):
""" """
feed with: feed with:
rating_id, media_id, media_type, rating_type, rating, votes media_id, media_type, rating_type, rating, votes
rating_type = 'default' rating_type = 'default'
""" """
self.cursor.execute(''' self.cursor.execute('''
INSERT INTO rating( INSERT INTO rating(
rating_id,
media_id, media_id,
media_type, media_type,
rating_type, rating_type,
rating, rating,
votes) votes)
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
''', (args)) ''', (args))
return self.cursor.lastrowid
@db.catch_operationalerrors @db.catch_operationalerrors
def remove_ratings(self, kodi_id, kodi_type): def remove_ratings(self, kodi_id, kodi_type):
@ -917,10 +849,11 @@ class KodiVideoDB(common.KodiDBBase):
c16, c16,
c18, c18,
c19, c19,
c20,
idSeason, idSeason,
userrating) userrating)
VALUES VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args)) ''', (args))
@db.catch_operationalerrors @db.catch_operationalerrors
@ -942,6 +875,7 @@ class KodiVideoDB(common.KodiDBBase):
c16 = ?, c16 = ?,
c18 = ?, c18 = ?,
c19 = ?, c19 = ?,
c20 = ?,
idFile=?, idFile=?,
idSeason = ?, idSeason = ?,
userrating = ? userrating = ?