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,26 +113,34 @@ class WriteKodiMusicDB():
|
||||||
if artistid == None:
|
if artistid == None:
|
||||||
|
|
||||||
utils.logMsg("ADD artist to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
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]
|
||||||
|
artistid = artistid + 1
|
||||||
|
pathsql="insert into artist(idArtist, strArtist, strMusicBrainzArtistID, strGenres, strBiography, strImage, strFanart, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
|
cursor.execute(pathsql, (artistid, name, musicBrainsId, genres, bio, thumb, fanart, lastScraped, dateadded))
|
||||||
|
|
||||||
#create the artist
|
#create the reference in emby table
|
||||||
cursor.execute("select coalesce(max(idArtist),0) as artistid from artist")
|
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||||
artistid = cursor.fetchone()[0]
|
cursor.execute(pathsql, (MBitem["Id"], artistid, "artist", API().getChecksum(MBitem)))
|
||||||
artistid = artistid + 1
|
|
||||||
pathsql="insert into artist(idArtist, strArtist, strMusicBrainzArtistID, strGenres, strBiography, strImage, strFanart, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
||||||
cursor.execute(pathsql, (artistid, name, musicBrainsId, genres, bio, thumb, fanart, lastScraped, dateadded))
|
|
||||||
|
|
||||||
#create the reference in emby table
|
except Exception, e:
|
||||||
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
utils.logMsg("Error while adding artist to Kodi library: ", e)
|
||||||
cursor.execute(pathsql, (MBitem["Id"], artistid, "artist", API().getChecksum(MBitem)))
|
return
|
||||||
|
|
||||||
#### UPDATE THE ARTIST #####
|
#### UPDATE THE ARTIST #####
|
||||||
else:
|
else:
|
||||||
utils.logMsg("UPDATE artist to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
utils.logMsg("UPDATE artist to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||||
pathsql="update artist SET strArtist = ?, strMusicBrainzArtistID = ?, strGenres = ?, strBiography = ?, strImage = ?, strFanart = ?, lastScraped = ?, dateAdded = ? WHERE idArtist = ?"
|
try:
|
||||||
cursor.execute(pathsql, (name, musicBrainsId, genres, bio, thumb, fanart, lastScraped, dateadded, artistid))
|
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
|
#update the checksum in emby table
|
||||||
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
|
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
|
#update artwork
|
||||||
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), artistid, "artist", "thumb", cursor)
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), artistid, "artist", "thumb", cursor)
|
||||||
|
@ -196,29 +204,36 @@ class WriteKodiMusicDB():
|
||||||
|
|
||||||
lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##### ADD THE ALBUM ############
|
##### ADD THE ALBUM ############
|
||||||
if albumid == None:
|
if albumid == None:
|
||||||
|
|
||||||
utils.logMsg("ADD album to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
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,))
|
cursor.execute("SELECT idAlbum FROM album WHERE strMusicBrainzAlbumID = ?",(musicBrainsId,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
if result != None:
|
if result != None:
|
||||||
albumid = result[0]
|
albumid = result[0]
|
||||||
else:
|
else:
|
||||||
#create the album
|
#create the album
|
||||||
cursor.execute("select coalesce(max(idAlbum),0) as albumid from album")
|
try:
|
||||||
albumid = cursor.fetchone()[0]
|
cursor.execute("select coalesce(max(idAlbum),0) as albumid from album")
|
||||||
albumid = albumid + 1
|
albumid = cursor.fetchone()[0]
|
||||||
if kodiVersion == 15:
|
albumid = albumid + 1
|
||||||
pathsql="insert into album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded, strReleaseType) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
if kodiVersion == 15:
|
||||||
cursor.execute(pathsql, (albumid, name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, "album"))
|
pathsql="insert into album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded, strReleaseType) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
else:
|
cursor.execute(pathsql, (albumid, name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, "album"))
|
||||||
pathsql="insert into album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
else:
|
||||||
cursor.execute(pathsql, (albumid, name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded))
|
pathsql="insert into album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
|
cursor.execute(pathsql, (albumid, name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded))
|
||||||
|
|
||||||
|
#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)))
|
||||||
|
|
||||||
|
except Exception, e:
|
||||||
|
utils.logMsg("Error while adding album to Kodi library: ", e)
|
||||||
|
return
|
||||||
|
|
||||||
#create the reference in emby table
|
#create the reference in emby table
|
||||||
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||||
|
@ -227,15 +242,20 @@ class WriteKodiMusicDB():
|
||||||
#### UPDATE THE ALBUM #####
|
#### UPDATE THE ALBUM #####
|
||||||
else:
|
else:
|
||||||
utils.logMsg("UPDATE album to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
utils.logMsg("UPDATE album to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||||
if kodiVersion == 15:
|
try:
|
||||||
pathsql="update album SET strAlbum=?, strMusicBrainzAlbumID=?, strArtists=?, iYear=?, strGenres=?, strReview=?, strImage=?, lastScraped=?, dateAdded=?, strReleaseType=? WHERE idAlbum = ?"
|
if kodiVersion == 15:
|
||||||
cursor.execute(pathsql, (name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, "album", albumid))
|
pathsql="update album SET strAlbum=?, strMusicBrainzAlbumID=?, strArtists=?, iYear=?, strGenres=?, strReview=?, strImage=?, lastScraped=?, dateAdded=?, strReleaseType=? WHERE idAlbum = ?"
|
||||||
else:
|
cursor.execute(pathsql, (name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, "album", albumid))
|
||||||
pathsql="update album SET strAlbum=?, strMusicBrainzAlbumID=?, strArtists=?, iYear=?, strGenres=?, strReview=?, strImage=?, lastScraped=?, dateAdded=? WHERE idAlbum = ?"
|
else:
|
||||||
cursor.execute(pathsql, (name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, albumid))
|
pathsql="update album SET strAlbum=?, strMusicBrainzAlbumID=?, strArtists=?, iYear=?, strGenres=?, strReview=?, strImage=?, lastScraped=?, dateAdded=? WHERE idAlbum = ?"
|
||||||
|
cursor.execute(pathsql, (name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, albumid))
|
||||||
|
|
||||||
#update the checksum in emby table
|
#update the checksum in emby table
|
||||||
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
|
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
|
#update artwork
|
||||||
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), albumid, "album", "thumb", cursor)
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), albumid, "album", "thumb", cursor)
|
||||||
|
@ -366,7 +386,7 @@ class WriteKodiMusicDB():
|
||||||
filename = playurl.rsplit("/",1)[-1]
|
filename = playurl.rsplit("/",1)[-1]
|
||||||
path = playurl.replace(filename,"")
|
path = playurl.replace(filename,"")
|
||||||
else:
|
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"]
|
path = server + "/Audio/%s/" %MBitem["Id"]
|
||||||
filename = "stream.mp3"
|
filename = "stream.mp3"
|
||||||
|
|
||||||
|
@ -387,26 +407,33 @@ class WriteKodiMusicDB():
|
||||||
if songid == None:
|
if songid == None:
|
||||||
|
|
||||||
utils.logMsg("ADD song to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
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]
|
||||||
|
songid = songid + 1
|
||||||
|
pathsql="insert into song(idSong, idAlbum, idPath, strArtists, strGenres, strTitle, iTrack, iDuration, iYear, strFileName, strMusicBrainzTrackID, iTimesPlayed, lastplayed) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||||
|
cursor.execute(pathsql, (songid, albumid, pathid, artists, genres, name, track, duration, year, filename, musicBrainzId, playcount, lastplayed))
|
||||||
|
|
||||||
#create the song
|
#create the reference in emby table
|
||||||
cursor.execute("select coalesce(max(idSong),0) as songid from song")
|
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||||
songid = cursor.fetchone()[0]
|
cursor.execute(pathsql, (MBitem["Id"], songid, "song", API().getChecksum(MBitem)))
|
||||||
songid = songid + 1
|
except Exception, e:
|
||||||
pathsql="insert into song(idSong, idAlbum, idPath, strArtists, strGenres, strTitle, iTrack, iDuration, iYear, strFileName, strMusicBrainzTrackID, iTimesPlayed, lastplayed) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
utils.logMsg("Error while adding song to Kodi library: ", e)
|
||||||
cursor.execute(pathsql, (songid, albumid, pathid, artists, genres, name, track, duration, year, filename, musicBrainzId, playcount, lastplayed))
|
return
|
||||||
|
|
||||||
#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)))
|
|
||||||
|
|
||||||
#### UPDATE THE SONG #####
|
#### UPDATE THE SONG #####
|
||||||
else:
|
else:
|
||||||
utils.logMsg("UPDATE song to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
utils.logMsg("UPDATE song to Kodi library","Id: %s - Title: %s" % (embyId, name))
|
||||||
pathsql="update song SET idAlbum=?, strArtists=?, strGenres=?, strTitle=?, iTrack=?, iDuration=?, iYear=?, strFileName=?, strMusicBrainzTrackID=?, iTimesPlayed=?, lastplayed=? WHERE idSong = ?"
|
try:
|
||||||
cursor.execute(pathsql, (albumid, artists, genres, name, track, duration, year, filename, musicBrainzId, playcount, lastplayed, songid))
|
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
|
#update the checksum in emby table
|
||||||
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
|
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
|
#add genres
|
||||||
self.AddGenresToMedia(songid, MBitem.get("Genres"), "song", cursor)
|
self.AddGenresToMedia(songid, MBitem.get("Genres"), "song", cursor)
|
||||||
|
|
Loading…
Reference in a new issue