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')
addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
dataPath = os.path.join(addondir,",musicfiles" + os.sep)
class WriteKodiMusicDB():
@ -198,11 +197,18 @@ 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?
cursor.execute("SELECT idAlbum FROM album WHERE strMusicBrainzAlbumID = ?",(musicBrainsId,))
result = cursor.fetchone()
if result != None:
albumid = result[0]
else:
#create the album
cursor.execute("select coalesce(max(idAlbum),0) as albumid from album")
albumid = cursor.fetchone()[0]
@ -362,10 +368,11 @@ class WriteKodiMusicDB():
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
playurl = "plugin://plugin.video.emby/music/?id=%s&mode=play" %MBitem["Id"]
dataPath = os.path.join(addondir,"musicfiles" + os.sep)
#create fake strm file
if not xbmcvfs.exists(dataPath):
xbmcvfs.mkdir(dataPath)
filename = item["Id"] + ".strm"
filename = MBitem["Id"] + ".strm"
path = dataPath
strmFile = os.path.join(dataPath,filename)
text_file = open(strmFile, "w")