mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-24 17:56:11 +00:00
just some more safety checks for the music import
musicbrainzID is unique in Kodi while it's not in emby ?
This commit is contained in:
parent
833e2b553f
commit
4a3200f6df
1 changed files with 79 additions and 52 deletions
|
@ -113,7 +113,7 @@ class WriteKodiMusicDB():
|
|||
if artistid == None:
|
||||
|
||||
utils.logMsg("ADD artist to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||
|
||||
try:
|
||||
#create the artist
|
||||
cursor.execute("select coalesce(max(idArtist),0) as artistid from artist")
|
||||
artistid = cursor.fetchone()[0]
|
||||
|
@ -125,14 +125,22 @@ class WriteKodiMusicDB():
|
|||
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||
cursor.execute(pathsql, (MBitem["Id"], artistid, "artist", API().getChecksum(MBitem)))
|
||||
|
||||
except Exception, e:
|
||||
utils.logMsg("Error while adding artist to Kodi library: ", e)
|
||||
return
|
||||
|
||||
#### UPDATE THE ARTIST #####
|
||||
else:
|
||||
utils.logMsg("UPDATE artist to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||
try:
|
||||
pathsql="update artist SET strArtist = ?, strMusicBrainzArtistID = ?, strGenres = ?, strBiography = ?, strImage = ?, strFanart = ?, lastScraped = ?, dateAdded = ? WHERE idArtist = ?"
|
||||
cursor.execute(pathsql, (name, musicBrainsId, genres, bio, thumb, fanart, lastScraped, dateadded, artistid))
|
||||
|
||||
#update the checksum in emby table
|
||||
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
|
||||
except Exception, e:
|
||||
utils.logMsg("Error while updating artist to Kodi library: ", e)
|
||||
return
|
||||
|
||||
#update artwork
|
||||
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), artistid, "artist", "thumb", cursor)
|
||||
|
@ -196,20 +204,19 @@ class WriteKodiMusicDB():
|
|||
|
||||
lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
|
||||
|
||||
##### ADD THE ALBUM ############
|
||||
if albumid == None:
|
||||
|
||||
utils.logMsg("ADD album to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||
|
||||
#safety check: does the musicbrainzartistId already exist?
|
||||
#safety check: does the strMusicBrainzAlbumID already exist?
|
||||
cursor.execute("SELECT idAlbum FROM album WHERE strMusicBrainzAlbumID = ?",(musicBrainsId,))
|
||||
result = cursor.fetchone()
|
||||
if result != None:
|
||||
albumid = result[0]
|
||||
else:
|
||||
#create the album
|
||||
try:
|
||||
cursor.execute("select coalesce(max(idAlbum),0) as albumid from album")
|
||||
albumid = cursor.fetchone()[0]
|
||||
albumid = albumid + 1
|
||||
|
@ -224,9 +231,18 @@ class WriteKodiMusicDB():
|
|||
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||
cursor.execute(pathsql, (MBitem["Id"], albumid, "album", API().getChecksum(MBitem)))
|
||||
|
||||
except Exception, e:
|
||||
utils.logMsg("Error while adding album to Kodi library: ", e)
|
||||
return
|
||||
|
||||
#create the reference in emby table
|
||||
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||
cursor.execute(pathsql, (MBitem["Id"], albumid, "album", API().getChecksum(MBitem)))
|
||||
|
||||
#### UPDATE THE ALBUM #####
|
||||
else:
|
||||
utils.logMsg("UPDATE album to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||
try:
|
||||
if kodiVersion == 15:
|
||||
pathsql="update album SET strAlbum=?, strMusicBrainzAlbumID=?, strArtists=?, iYear=?, strGenres=?, strReview=?, strImage=?, lastScraped=?, dateAdded=?, strReleaseType=? WHERE idAlbum = ?"
|
||||
cursor.execute(pathsql, (name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, "album", albumid))
|
||||
|
@ -237,6 +253,10 @@ class WriteKodiMusicDB():
|
|||
#update the checksum in emby table
|
||||
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
|
||||
|
||||
except Exception, e:
|
||||
utils.logMsg("Error while updating album to Kodi library: ", e)
|
||||
return
|
||||
|
||||
#update artwork
|
||||
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), albumid, "album", "thumb", cursor)
|
||||
self.addOrUpdateArt(API().getArtwork(MBitem, "BoxRear"), albumid, "album", "poster", cursor)
|
||||
|
@ -366,7 +386,7 @@ class WriteKodiMusicDB():
|
|||
filename = playurl.rsplit("/",1)[-1]
|
||||
path = playurl.replace(filename,"")
|
||||
else:
|
||||
#for transcoding we just use the server's streaming path because I couldn't figure out how to set a http or plugin path in the music DB
|
||||
#for transcoding we just use the server's streaming path because I couldn't figure out how to set the plugin path in the music DB
|
||||
path = server + "/Audio/%s/" %MBitem["Id"]
|
||||
filename = "stream.mp3"
|
||||
|
||||
|
@ -387,7 +407,7 @@ class WriteKodiMusicDB():
|
|||
if songid == None:
|
||||
|
||||
utils.logMsg("ADD song to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||
|
||||
try:
|
||||
#create the song
|
||||
cursor.execute("select coalesce(max(idSong),0) as songid from song")
|
||||
songid = cursor.fetchone()[0]
|
||||
|
@ -398,15 +418,22 @@ class WriteKodiMusicDB():
|
|||
#create the reference in emby table
|
||||
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||
cursor.execute(pathsql, (MBitem["Id"], songid, "song", API().getChecksum(MBitem)))
|
||||
except Exception, e:
|
||||
utils.logMsg("Error while adding song to Kodi library: ", e)
|
||||
return
|
||||
|
||||
#### UPDATE THE SONG #####
|
||||
else:
|
||||
utils.logMsg("UPDATE song to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||
try:
|
||||
pathsql="update song SET idAlbum=?, strArtists=?, strGenres=?, strTitle=?, iTrack=?, iDuration=?, iYear=?, strFileName=?, strMusicBrainzTrackID=?, iTimesPlayed=?, lastplayed=? WHERE idSong = ?"
|
||||
cursor.execute(pathsql, (albumid, artists, genres, name, track, duration, year, filename, musicBrainzId, playcount, lastplayed, songid))
|
||||
|
||||
#update the checksum in emby table
|
||||
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
|
||||
except Exception, e:
|
||||
utils.logMsg("Error while updating song to Kodi library: ", e)
|
||||
return
|
||||
|
||||
#add genres
|
||||
self.AddGenresToMedia(songid, MBitem.get("Genres"), "song", cursor)
|
||||
|
|
Loading…
Reference in a new issue