Finally make PKC compatible with Kodi 18 Leia Alpha 1

- Fixes #339
This commit is contained in:
Croneter 2018-04-05 08:06:48 +02:00
parent c12c9c08d8
commit 61065e0cc5
3 changed files with 124 additions and 140 deletions

View file

@ -1290,7 +1290,20 @@ class Music(Items):
checksum=checksum) checksum=checksum)
# Process the album info # Process the album info
if v.KODIVERSION >= 17: if v.KODIVERSION >= 18:
# Kodi Leia
query = '''
UPDATE album
SET strArtistDisp = ?, iYear = ?, strGenres = ?, strReview = ?,
strImage = ?, iUserrating = ?, lastScraped = ?,
strReleaseType = ?, strLabel = ?, bCompilation = ?
WHERE idAlbum = ?
'''
kodicursor.execute(query, (artistname, year, self.genre, bio,
thumb, rating, lastScraped,
v.KODI_TYPE_ALBUM, studio,
self.compilation, albumid))
elif v.KODIVERSION == 17:
# Kodi Krypton # Kodi Krypton
query = ''' query = '''
UPDATE album UPDATE album
@ -1316,30 +1329,6 @@ class Music(Items):
thumb, rating, lastScraped, thumb, rating, lastScraped,
v.KODI_TYPE_ALBUM, studio, v.KODI_TYPE_ALBUM, studio,
self.compilation, albumid)) self.compilation, albumid))
elif v.KODIVERSION == 15:
# Kodi Isengard
query = '''
UPDATE album
SET strArtists = ?, iYear = ?, strGenres = ?, strReview = ?,
strImage = ?, iRating = ?, lastScraped = ?, dateAdded = ?,
strReleaseType = ?, strLabel = ?
WHERE idAlbum = ?
'''
kodicursor.execute(query, (artistname, year, self.genre, bio,
thumb, rating, lastScraped, dateadded,
v.KODI_TYPE_ALBUM, studio, albumid))
else:
# Kodi Helix
query = '''
UPDATE album
SET strArtists = ?, iYear = ?, strGenres = ?, strReview = ?,
strImage = ?, iRating = ?, lastScraped = ?, dateAdded = ?,
strLabel = ?
WHERE idAlbum = ?
'''
kodicursor.execute(query, (artistname, year, self.genre, bio,
thumb, rating, lastScraped, dateadded,
studio, albumid))
# Associate the parentid for plex reference # Associate the parentid for plex reference
parent_id = api.parent_plex_id() parent_id = api.parent_plex_id()
@ -1400,8 +1389,8 @@ class Music(Items):
kodicursor.execute(query, (artistid, name, year)) kodicursor.execute(query, (artistid, name, year))
# Update plex reference with parentid # Update plex reference with parentid
plex_db.updateParentId(artist_id, albumid) plex_db.updateParentId(artist_id, albumid)
# Add genres if v.KODIVERSION < 18:
self.kodi_db.addMusicGenres(albumid, self.genres, v.KODI_TYPE_ALBUM) self.kodi_db.addMusicGenres(albumid, self.genres, v.KODI_TYPE_ALBUM)
# Update artwork # Update artwork
artwork.modify_artwork(artworks, albumid, v.KODI_TYPE_ALBUM, kodicursor) artwork.modify_artwork(artworks, albumid, v.KODI_TYPE_ALBUM, kodicursor)
# Add all children - all tracks # Add all children - all tracks
@ -1517,18 +1506,33 @@ class Music(Items):
kodicursor.execute(query, (path, '123', pathid)) kodicursor.execute(query, (path, '123', pathid))
# Update the song entry # Update the song entry
query = ''' if v.KODIVERSION >= 18:
UPDATE song # Kodi Leia
SET idAlbum = ?, strArtists = ?, strGenres = ?, strTitle = ?, query = '''
iTrack = ?, iDuration = ?, iYear = ?, strFilename = ?, UPDATE song
iTimesPlayed = ?, lastplayed = ?, rating = ?, comment = ?, SET idAlbum = ?, strArtistDisp = ?, strGenres = ?,
mood = ? strTitle = ?, iTrack = ?, iDuration = ?, iYear = ?,
WHERE idSong = ? strFilename = ?, iTimesPlayed = ?, lastplayed = ?,
''' rating = ?, comment = ?, mood = ?
kodicursor.execute(query, (albumid, artists, genre, title, track, WHERE idSong = ?
duration, year, filename, playcount, '''
dateplayed, rating, comment, mood, kodicursor.execute(query, (albumid, artists, genre, title,
songid)) track, duration, year, filename,
playcount, dateplayed, rating,
comment, mood, songid))
else:
query = '''
UPDATE song
SET idAlbum = ?, strArtists = ?, strGenres = ?,
strTitle = ?, iTrack = ?, iDuration = ?, iYear = ?,
strFilename = ?, iTimesPlayed = ?, lastplayed = ?,
rating = ?, comment = ?, mood = ?
WHERE idSong = ?
'''
kodicursor.execute(query, (albumid, artists, genre, title,
track, duration, year, filename,
playcount, dateplayed, rating,
comment, mood, songid))
# Update the checksum in plex table # Update the checksum in plex table
plex_db.updateReference(itemid, checksum) plex_db.updateReference(itemid, checksum)
@ -1615,18 +1619,33 @@ class Music(Items):
dateadded)) dateadded))
# Create the song entry # Create the song entry
query = ''' if v.KODIVERSION >= 18:
INSERT INTO song( # Kodi Leia
idSong, idAlbum, idPath, strArtists, strGenres, strTitle, query = '''
iTrack, iDuration, iYear, strFileName, INSERT INTO song(
strMusicBrainzTrackID, iTimesPlayed, lastplayed, idSong, idAlbum, idPath, strArtistDisp, strGenres,
rating, iStartOffset, iEndOffset, mood) strTitle, iTrack, iDuration, iYear, strFileName,
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) strMusicBrainzTrackID, iTimesPlayed, lastplayed,
''' rating, iStartOffset, iEndOffset, mood)
kodicursor.execute( VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
query, (songid, albumid, pathid, artists, genre, title, track, '''
duration, year, filename, musicBrainzId, playcount, kodicursor.execute(
dateplayed, rating, 0, 0, mood)) query, (songid, albumid, pathid, artists, genre, title,
track, duration, year, filename, musicBrainzId,
playcount, dateplayed, rating, 0, 0, mood))
else:
query = '''
INSERT INTO song(
idSong, idAlbum, idPath, strArtists, strGenres,
strTitle, iTrack, iDuration, iYear, strFileName,
strMusicBrainzTrackID, iTimesPlayed, lastplayed,
rating, iStartOffset, iEndOffset, mood)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''
kodicursor.execute(
query, (songid, albumid, pathid, artists, genre, title,
track, duration, year, filename, musicBrainzId,
playcount, dateplayed, rating, 0, 0, mood))
# Create the reference in plex table # Create the reference in plex table
plex_db.addReference(itemid, plex_db.addReference(itemid,
@ -1637,15 +1656,14 @@ class Music(Items):
parent_id=albumid, parent_id=albumid,
checksum=checksum, checksum=checksum,
view_id=viewid) view_id=viewid)
if v.KODIVERSION < 18:
# Link song to album # Link song to album
query = ''' query = '''
INSERT OR REPLACE INTO albuminfosong( INSERT OR REPLACE INTO albuminfosong(
idAlbumInfoSong, idAlbumInfo, iTrack, strTitle, iDuration) idAlbumInfoSong, idAlbumInfo, iTrack, strTitle, iDuration)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
''' '''
kodicursor.execute(query, (songid, albumid, track, title, duration)) kodicursor.execute(query, (songid, albumid, track, title, duration))
# Link song to artists # Link song to artists
artist_loop = [{ artist_loop = [{
'Name': api.grandparent_title(), 'Name': api.grandparent_title(),

View file

@ -869,28 +869,20 @@ class KodiDBMethods(object):
return seasonid return seasonid
def addArtist(self, name, musicbrainz): def addArtist(self, name, musicbrainz):
query = '''
query = ' '.join(( SELECT idArtist, strArtist
FROM artist
"SELECT idArtist, strArtist", WHERE strMusicBrainzArtistID = ?
"FROM artist", '''
"WHERE strMusicBrainzArtistID = ?"
))
self.cursor.execute(query, (musicbrainz,)) self.cursor.execute(query, (musicbrainz,))
try: try:
result = self.cursor.fetchone() result = self.cursor.fetchone()
artistid = result[0] artistid = result[0]
artistname = result[1] artistname = result[1]
except TypeError: except TypeError:
query = '''
query = ' '.join(( SELECT idArtist FROM artist WHERE strArtist = ? COLLATE NOCASE
'''
"SELECT idArtist",
"FROM artist",
"WHERE strArtist = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (name,)) self.cursor.execute(query, (name,))
try: try:
artistid = self.cursor.fetchone()[0] artistid = self.cursor.fetchone()[0]
@ -899,113 +891,87 @@ class KodiDBMethods(object):
# [Missing Tag] strMusicBrainzArtistID: Artist Tag Missing # [Missing Tag] strMusicBrainzArtistID: Artist Tag Missing
if v.KODIVERSION >= 17: if v.KODIVERSION >= 17:
self.cursor.execute( self.cursor.execute(
"select coalesce(max(idArtist),1) from artist") "SELECT COALESCE(MAX(idArtist),1) FROM artist")
else: else:
self.cursor.execute( self.cursor.execute(
"select coalesce(max(idArtist),0) from artist") "SELECT COALESCE(MAX(idArtist),0) FROM artist")
artistid = self.cursor.fetchone()[0] + 1 artistid = self.cursor.fetchone()[0] + 1
query = ( query = '''
''' INSERT INTO artist(idArtist, strArtist,
INSERT INTO artist(idArtist, strArtist, strMusicBrainzArtistID) strMusicBrainzArtistID)
VALUES (?, ?, ?) VALUES (?, ?, ?)
''' '''
)
self.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 = ?"
self.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):
query = 'SELECT idAlbum FROM album WHERE strMusicBrainzAlbumID = ?'
query = ' '.join((
"SELECT idAlbum",
"FROM album",
"WHERE strMusicBrainzAlbumID = ?"
))
self.cursor.execute(query, (musicbrainz,)) self.cursor.execute(query, (musicbrainz,))
try: try:
albumid = self.cursor.fetchone()[0] albumid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
# 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
query = ( query = '''
''' INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID,
INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType) strReleaseType)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)
''' '''
) self.cursor.execute(query, (albumid, name, musicbrainz, 'album'))
self.cursor.execute(query, (albumid, name, musicbrainz, "album"))
return albumid return albumid
def addMusicGenres(self, kodiid, genres, mediatype): def addMusicGenres(self, kodiid, genres, mediatype):
if mediatype == "album": if mediatype == "album":
# Delete current genres for clean slate # Delete current genres for clean slate
query = ' '.join(( query = 'DELETE FROM album_genre WHERE idAlbum = ?'
"DELETE FROM album_genre",
"WHERE idAlbum = ?"
))
self.cursor.execute(query, (kodiid,)) self.cursor.execute(query, (kodiid,))
for genre in genres: for genre in genres:
query = ' '.join(( query = '''
SELECT idGenre FROM genre WHERE strGenre = ? COLLATE NOCASE
"SELECT idGenre", '''
"FROM genre",
"WHERE strGenre = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (genre,)) self.cursor.execute(query, (genre,))
try: try:
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") query = 'SELECT COALESCE(MAX(idGenre),0) FROM genre'
self.cursor.execute(query)
genreid = self.cursor.fetchone()[0] + 1 genreid = self.cursor.fetchone()[0] + 1
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)" query = 'INSERT INTO genre(idGenre, strGenre) VALUES(?, ?)'
self.cursor.execute(query, (genreid, genre)) self.cursor.execute(query, (genreid, genre))
query = '''
query = "INSERT OR REPLACE INTO album_genre(idGenre, idAlbum) values(?, ?)" INSERT OR REPLACE INTO album_genre(idGenre, idAlbum)
VALUES (?, ?)
'''
self.cursor.execute(query, (genreid, kodiid)) self.cursor.execute(query, (genreid, kodiid))
elif mediatype == "song": elif mediatype == "song":
# Delete current genres for clean slate # Delete current genres for clean slate
query = ' '.join(( query = 'DELETE FROM song_genre WHERE idSong = ?'
"DELETE FROM song_genre",
"WHERE idSong = ?"
))
self.cursor.execute(query, (kodiid,)) self.cursor.execute(query, (kodiid,))
for genre in genres: for genre in genres:
query = ' '.join(( query = '''
SELECT idGenre FROM genre WHERE strGenre = ?
"SELECT idGenre", COLLATE NOCASE
"FROM genre", '''
"WHERE strGenre = ?",
"COLLATE NOCASE"
))
self.cursor.execute(query, (genre,)) self.cursor.execute(query, (genre,))
try: try:
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") query = 'SELECT COALESCE(MAX(idGenre),0) FROM genre'
self.cursor.execute(query)
genreid = self.cursor.fetchone()[0] + 1 genreid = self.cursor.fetchone()[0] + 1
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)" query = 'INSERT INTO genre(idGenre, strGenre) values(?, ?)'
self.cursor.execute(query, (genreid, genre)) self.cursor.execute(query, (genreid, genre))
query = '''
query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)" INSERT OR REPLACE INTO song_genre(idGenre, idSong)
VALUES (?, ?)
'''
self.cursor.execute(query, (genreid, kodiid)) self.cursor.execute(query, (genreid, kodiid))
# Krypton only stuff ############################## # Krypton only stuff ##############################

View file

@ -85,7 +85,7 @@ _DB_VIDEO_VERSION = {
15: 93, # Isengard 15: 93, # Isengard
16: 99, # Jarvis 16: 99, # Jarvis
17: 107, # Krypton 17: 107, # Krypton
18: 108 # Leia 18: 109 # Leia
} }
DB_VIDEO_PATH = try_decode(xbmc.translatePath( DB_VIDEO_PATH = try_decode(xbmc.translatePath(
"special://database/MyVideos%s.db" % _DB_VIDEO_VERSION[KODIVERSION])) "special://database/MyVideos%s.db" % _DB_VIDEO_VERSION[KODIVERSION]))
@ -96,7 +96,7 @@ _DB_MUSIC_VERSION = {
15: 52, # Isengard 15: 52, # Isengard
16: 56, # Jarvis 16: 56, # Jarvis
17: 60, # Krypton 17: 60, # Krypton
18: 62 # Leia 18: 70 # Leia
} }
DB_MUSIC_PATH = try_decode(xbmc.translatePath( DB_MUSIC_PATH = try_decode(xbmc.translatePath(
"special://database/MyMusic%s.db" % _DB_MUSIC_VERSION[KODIVERSION])) "special://database/MyMusic%s.db" % _DB_MUSIC_VERSION[KODIVERSION]))