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,11 +197,18 @@ 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?
cursor.execute("SELECT idAlbum FROM album WHERE strMusicBrainzAlbumID = ?",(musicBrainsId,))
result = cursor.fetchone()
if result != None:
albumid = result[0]
else:
#create the album #create the album
cursor.execute("select coalesce(max(idAlbum),0) as albumid from album") cursor.execute("select coalesce(max(idAlbum),0) as albumid from album")
albumid = cursor.fetchone()[0] albumid = cursor.fetchone()[0]
@ -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")