Merge pull request #32 from jmeacoe/master

Fix music syncing for Kodi 18 retaining Kodi 17 compatibility
This commit is contained in:
Odd Stråbø 2019-06-02 03:42:44 +02:00 committed by GitHub
commit 24ffc886f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 12 deletions

View file

@ -16,10 +16,11 @@ LOG = logging.getLogger("JELLYFIN."+__name__)
class Music(Kodi): class Music(Kodi):
def __init__(self, cursor): def __init__(self, cursor):
self.cursor = cursor self.cursor = cursor
self.version_id = self.get_version()
self.update_versiontagscan()
Kodi.__init__(self) Kodi.__init__(self)
def create_entry(self): def create_entry(self):
@ -128,7 +129,10 @@ class Music(Kodi):
self.cursor.execute(QU.get_album, (musicbrainz,)) self.cursor.execute(QU.get_album, (musicbrainz,))
album = None album = None
else: else:
self.cursor.execute(QU.get_album_by_name, (name,)) if self.version_id < 72:
self.cursor.execute(QU.get_album_by_name, (name,))
else:
self.cursor.execute(QU.get_album_by_name72, (name,))
album = self.cursor.fetchone() album = self.cursor.fetchone()
if album[1] and album[1].split(' / ')[0] not in artists.split(' / '): if album[1] and album[1].split(' / ')[0] not in artists.split(' / '):
@ -146,17 +150,25 @@ class Music(Kodi):
def add_album(self, album_id, *args): def add_album(self, album_id, *args):
album_id = album_id or self.create_entry_album() album_id = album_id or self.create_entry_album()
self.cursor.execute(QU.add_album, (album_id,) + args) if self.version_id < 72:
self.cursor.execute(QU.add_album, (album_id,) + args)
else:
self.cursor.execute(QU.add_album72, (album_id,) + args)
return album_id return album_id
def update_album(self, *args): def update_album(self, *args):
self.cursor.execute(QU.update_album, args) if self.version_id < 72:
self.cursor.execute(QU.update_album, args)
else:
self.cursor.execute(QU.update_album72, args)
def get_album_artist(self, album_id, artists): def get_album_artist(self, album_id, artists):
try: try:
self.cursor.execute(QU.get_album_artist, (album_id,)) if self.version_id < 72:
self.cursor.execute(QU.get_album_artist, (album_id,))
else:
self.cursor.execute(QU.get_album_artist72, (album_id,))
curr_artists = self.cursor.fetchone()[0] curr_artists = self.cursor.fetchone()[0]
except TypeError: except TypeError:
return return
@ -165,22 +177,32 @@ class Music(Kodi):
self.update_album_artist(artists, album_id) self.update_album_artist(artists, album_id)
def update_album_artist(self, *args): def update_album_artist(self, *args):
self.cursor.execute(QU.update_album_artist, args) if self.version_id < 72:
self.cursor.execute(QU.update_album_artist, args)
else:
self.cursor.execute(QU.update_album_artist72, args)
def add_single(self, *args): def add_single(self, *args):
self.cursor.execute(QU.add_single, args) self.cursor.execute(QU.add_single, args)
def add_song(self, *args): def add_song(self, *args):
self.cursor.execute(QU.add_song, args) if self.version_id < 72:
self.cursor.execute(QU.add_song, args)
else:
self.cursor.execute(QU.add_song72, args)
def update_song(self, *args): def update_song(self, *args):
self.cursor.execute(QU.update_song, args) if self.version_id < 72:
self.cursor.execute(QU.update_song, args)
else:
self.cursor.execute(QU.update_song72, args)
def link_song_artist(self, *args): def link_song_artist(self, *args):
self.cursor.execute(QU.update_song_artist, args) self.cursor.execute(QU.update_song_artist, args)
def link_song_album(self, *args): def link_song_album(self, *args):
self.cursor.execute(QU.update_song_album, args) if self.version_id < 72:
self.cursor.execute(QU.update_song_album, args)
def rate_song(self, *args): def rate_song(self, *args):
self.cursor.execute(QU.update_song_rating, args) self.cursor.execute(QU.update_song_rating, args)
@ -188,8 +210,9 @@ class Music(Kodi):
def add_genres(self, kodi_id, genres, media): def add_genres(self, kodi_id, genres, media):
''' Add genres, but delete current genres first. ''' Add genres, but delete current genres first.
Album_genres was removed in kodi 18
''' '''
if media == 'album': if media == 'album' and self.version_id < 72 :
self.cursor.execute(QU.delete_genres_album, (kodi_id,)) self.cursor.execute(QU.delete_genres_album, (kodi_id,))
for genre in genres: for genre in genres:
@ -197,7 +220,7 @@ class Music(Kodi):
genre_id = self.get_genre(genre) genre_id = self.get_genre(genre)
self.cursor.execute(QU.update_genre_album, (genre_id, kodi_id)) self.cursor.execute(QU.update_genre_album, (genre_id, kodi_id))
elif media == 'song': if media == 'song':
self.cursor.execute(QU.delete_genres_song, (kodi_id,)) self.cursor.execute(QU.delete_genres_song, (kodi_id,))
for genre in genres: for genre in genres:
@ -229,3 +252,17 @@ class Music(Kodi):
def delete_song(self, *args): def delete_song(self, *args):
self.cursor.execute(QU.delete_song, args) self.cursor.execute(QU.delete_song, args)
def get_version(self):
self.cursor.execute(QU.get_version)
return self.cursor.fetchone()[0]
#current bug in Kodi 18 that will ask for a scan of music tags unless this is set without a lastscanned
def update_versiontagscan(self):
if self.version_id < 72:
return
else:
self.cursor.execute(QU.get_versiontagcount)
if self.cursor.fetchone()[0] == 0:
self.cursor.execute(QU.update_versiontag, (self.version_id,))

View file

@ -53,10 +53,18 @@ get_album_by_name = """ SELECT idAlbum, strArtists
FROM album FROM album
WHERE strAlbum = ? WHERE strAlbum = ?
""" """
get_album_by_name72 = """ SELECT idAlbum, strArtistDisp
FROM album
WHERE strAlbum = ?
"""
get_album_artist = """ SELECT strArtists get_album_artist = """ SELECT strArtists
FROM album FROM album
WHERE idAlbum = ? WHERE idAlbum = ?
""" """
get_album_artist72 = """ SELECT strArtistDisp
FROM album
WHERE idAlbum = ?
"""
get_album_artist_obj = [ "{AlbumId}","{strAlbumArtists}" get_album_artist_obj = [ "{AlbumId}","{strAlbumArtists}"
] ]
get_genre = """ SELECT idGenre get_genre = """ SELECT idGenre
@ -77,6 +85,9 @@ add_artist = """ INSERT INTO artist(idArtist, strArtist, strMusicBrainzArti
add_album = """ INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType) add_album = """ INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)
""" """
add_album72 = """ INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType, bScrapedMBID)
VALUES (?, ?, ?, ?, 1)
"""
add_single = """ INSERT INTO album(idAlbum, strGenres, iYear, strReleaseType) add_single = """ INSERT INTO album(idAlbum, strGenres, iYear, strReleaseType)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)
""" """
@ -87,6 +98,11 @@ add_song = """ INSERT INTO song(idSong, idAlbum, idPath, strArtists, strG
rating, comment, dateAdded) rating, comment, dateAdded)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""" """
add_song72 = """ INSERT INTO song(idSong, idAlbum, idPath, strArtistDisp, strGenres, strTitle, iTrack,
iDuration, iYear, strFileName, strMusicBrainzTrackID, iTimesPlayed, lastplayed,
rating, comment, dateAdded)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
"""
add_song_obj = [ "{SongId}","{AlbumId}","{PathId}","{Artists}","{Genre}","{Title}","{Index}", add_song_obj = [ "{SongId}","{AlbumId}","{PathId}","{Artists}","{Genre}","{Title}","{Index}",
"{Runtime}","{Year}","{Filename}","{UniqueId}","{PlayCount}","{DatePlayed}","{Rating}", "{Runtime}","{Year}","{Filename}","{UniqueId}","{PlayCount}","{DatePlayed}","{Rating}",
"{Comment}","{DateAdded}" "{Comment}","{DateAdded}"
@ -135,19 +151,35 @@ update_album = """ UPDATE album
iUserrating = ?, lastScraped = ?, strReleaseType = ? iUserrating = ?, lastScraped = ?, strReleaseType = ?
WHERE idAlbum = ? WHERE idAlbum = ?
""" """
update_album72 = """ UPDATE album
SET strArtistDisp = ?, iYear = ?, strGenres = ?, strReview = ?, strImage = ?,
iUserrating = ?, lastScraped = ?, bScrapedMBID = 1, strReleaseType = ?
WHERE idAlbum = ?
"""
update_album_obj = [ "{Artists}","{Year}","{Genre}","{Bio}","{Thumb}","{Rating}","{LastScraped}", update_album_obj = [ "{Artists}","{Year}","{Genre}","{Bio}","{Thumb}","{Rating}","{LastScraped}",
"album","{AlbumId}" "album","{AlbumId}"
] ]
update_album_artist = """ UPDATE album update_album_artist = """ UPDATE album
SET strArtists = ? SET strArtists = ?
WHERE idAlbum = ? WHERE idAlbum = ?
""" """
update_album_artist72 = """ UPDATE album
SET strArtistDisp = ?
WHERE idAlbum = ?
"""
update_song = """ UPDATE song update_song = """ UPDATE song
SET idAlbum = ?, strArtists = ?, strGenres = ?, strTitle = ?, iTrack = ?, SET idAlbum = ?, strArtists = ?, strGenres = ?, strTitle = ?, iTrack = ?,
iDuration = ?, iYear = ?, strFilename = ?, iTimesPlayed = ?, lastplayed = ?, iDuration = ?, iYear = ?, strFilename = ?, iTimesPlayed = ?, lastplayed = ?,
rating = ?, comment = ?, dateAdded = ? rating = ?, comment = ?, dateAdded = ?
WHERE idSong = ? WHERE idSong = ?
""" """
update_song72 = """ UPDATE song
SET idAlbum = ?, strArtistDisp = ?, strGenres = ?, strTitle = ?, iTrack = ?,
iDuration = ?, iYear = ?, strFilename = ?, iTimesPlayed = ?, lastplayed = ?,
rating = ?, comment = ?, dateAdded = ?
WHERE idSong = ?
"""
update_song_obj = [ "{AlbumId}","{Artists}","{Genre}","{Title}","{Index}","{Runtime}","{Year}", update_song_obj = [ "{AlbumId}","{Artists}","{Genre}","{Title}","{Index}","{Runtime}","{Year}",
"{Filename}","{PlayCount}","{DatePlayed}","{Rating}","{Comment}", "{Filename}","{PlayCount}","{DatePlayed}","{Rating}","{Comment}",
"{DateAdded}","{SongId}" "{DateAdded}","{SongId}"
@ -195,3 +227,12 @@ delete_album = """ DELETE FROM album
delete_song = """ DELETE FROM song delete_song = """ DELETE FROM song
WHERE idSong = ? WHERE idSong = ?
""" """
get_version = """ SELECT idVersion
FROM version
"""
update_versiontag = """ INSERT OR REPLACE INTO versiontagscan(idVersion, iNeedsScan)
VALUES (?, 0)
"""
get_versiontagcount = """ SELECT COUNT(*)
FROM versiontagscan
"""