add safety check for album adds

This commit is contained in:
Marcel van der Veldt 2015-05-08 13:16:21 +02:00
parent 4b190bab34
commit 25ae3cea76

View file

@ -28,7 +28,6 @@ import xml.etree.cElementTree as ET
addon = xbmcaddon.Addon(id='plugin.video.emby') addon = xbmcaddon.Addon(id='plugin.video.emby')
addondir = xbmc.translatePath(addon.getAddonInfo('profile')) addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
dataPath = os.path.join(addondir,",musicfiles" + os.sep)
class WriteKodiMusicDB(): class WriteKodiMusicDB():
@ -198,21 +197,28 @@ 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))
#create the album #safety check: does the musicbrainzartistId already exist?
cursor.execute("select coalesce(max(idAlbum),0) as albumid from album") cursor.execute("SELECT idAlbum FROM album WHERE strMusicBrainzAlbumID = ?",(musicBrainsId,))
albumid = cursor.fetchone()[0] result = cursor.fetchone()
albumid = albumid + 1 if result != None:
if kodiVersion == 15: albumid = result[0]
pathsql="insert into album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded, strReleaseType) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
cursor.execute(pathsql, (albumid, name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, "album"))
else: else:
pathsql="insert into album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" #create the album
cursor.execute(pathsql, (albumid, name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded)) cursor.execute("select coalesce(max(idAlbum),0) as albumid from album")
albumid = cursor.fetchone()[0]
albumid = albumid + 1
if kodiVersion == 15:
pathsql="insert into album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded, strReleaseType) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
cursor.execute(pathsql, (albumid, name, musicBrainsId, artists, year, genres, bio, thumb, lastScraped, dateadded, "album"))
else:
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 #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(?, ?, ?, ?)"
@ -362,10 +368,11 @@ class WriteKodiMusicDB():
else: else:
#for transcoding we need to create a fake strm file because I couldn't figure out how to set a http or plugin path in the music DB #for transcoding we need to create a fake strm file because I couldn't figure out how to set a http or plugin path in the music DB
playurl = "plugin://plugin.video.emby/music/?id=%s&mode=play" %MBitem["Id"] playurl = "plugin://plugin.video.emby/music/?id=%s&mode=play" %MBitem["Id"]
dataPath = os.path.join(addondir,"musicfiles" + os.sep)
#create fake strm file #create fake strm file
if not xbmcvfs.exists(dataPath): if not xbmcvfs.exists(dataPath):
xbmcvfs.mkdir(dataPath) xbmcvfs.mkdir(dataPath)
filename = item["Id"] + ".strm" filename = MBitem["Id"] + ".strm"
path = dataPath path = dataPath
strmFile = os.path.join(dataPath,filename) strmFile = os.path.join(dataPath,filename)
text_file = open(strmFile, "w") text_file = open(strmFile, "w")