Prettify
This commit is contained in:
parent
411f691547
commit
818f370c46
1 changed files with 11 additions and 28 deletions
|
@ -470,51 +470,34 @@ class KodiDBMethods(object):
|
||||||
result['Backdrop'] = [d[0] for d in data]
|
result['Backdrop'] = [d[0] for d in data]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def addGenres(self, kodiid, genres, mediatype):
|
def addGenres(self, kodi_id, genres, kodi_type):
|
||||||
|
"""
|
||||||
|
Adds the genres (list of strings) to the Kodi DB and associates them
|
||||||
|
with the element kodi_id, kodi_type
|
||||||
|
"""
|
||||||
# Delete current genres for clean slate
|
# Delete current genres for clean slate
|
||||||
query = ' '.join((
|
query = 'DELETE FROM genre_link WHERE media_id = ? AND media_type = ?'
|
||||||
|
self.cursor.execute(query, (kodi_id, kodi_type,))
|
||||||
"DELETE FROM genre_link",
|
|
||||||
"WHERE media_id = ?",
|
|
||||||
"AND media_type = ?"
|
|
||||||
))
|
|
||||||
self.cursor.execute(query, (kodiid, mediatype,))
|
|
||||||
|
|
||||||
# Add genres
|
# Add genres
|
||||||
for genre in genres:
|
for genre in genres:
|
||||||
|
query = ' SELECT genre_id FROM genre WHERE name = ? COLLATE NOCASE'
|
||||||
query = ' '.join((
|
|
||||||
|
|
||||||
"SELECT genre_id",
|
|
||||||
"FROM genre",
|
|
||||||
"WHERE name = ?",
|
|
||||||
"COLLATE NOCASE"
|
|
||||||
))
|
|
||||||
self.cursor.execute(query, (genre,))
|
self.cursor.execute(query, (genre,))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
genre_id = self.cursor.fetchone()[0]
|
genre_id = self.cursor.fetchone()[0]
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Create genre in database
|
# Create genre in database
|
||||||
self.cursor.execute("select coalesce(max(genre_id),0) from genre")
|
self.cursor.execute("select coalesce(max(genre_id),0) from genre")
|
||||||
genre_id = self.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(?, ?)"
|
||||||
self.cursor.execute(query, (genre_id, genre))
|
self.cursor.execute(query, (genre_id, genre))
|
||||||
LOG.debug("Add Genres to media, processing: %s", genre)
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Assign genre to item
|
# Assign genre to item
|
||||||
query = (
|
query = '''
|
||||||
'''
|
|
||||||
INSERT OR REPLACE INTO genre_link(
|
INSERT OR REPLACE INTO genre_link(
|
||||||
genre_id, media_id, media_type)
|
genre_id, media_id, media_type)
|
||||||
|
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
self.cursor.execute(query, (genre_id, kodi_id, kodi_type))
|
||||||
self.cursor.execute(query, (genre_id, kodiid, mediatype))
|
|
||||||
|
|
||||||
def addStudios(self, kodiid, studios, mediatype):
|
def addStudios(self, kodiid, studios, mediatype):
|
||||||
for studio in studios:
|
for studio in studios:
|
||||||
|
|
Loading…
Reference in a new issue