Use json.dumps to do the string escaping for the JsonApi calls

This commit is contained in:
shaun 2015-04-12 14:28:42 +10:00
parent d0c7246de0
commit ff437bc439

View file

@ -402,8 +402,11 @@ class WriteKodiDB():
episode = int(MBitem.get("IndexNumber")) episode = int(MBitem.get("IndexNumber"))
changes |= self.updateProperty(KodiItem,"episode",episode,"episode") changes |= self.updateProperty(KodiItem,"episode",episode,"episode")
plot = utils.convertEncoding(API().getOverview(MBitem)) #plot = utils.convertEncoding(API().getOverview(MBitem))
plot = MBitem.get("Overview")
if(plot != None):
changes |= self.updateProperty(KodiItem,"plot",plot,"episode") changes |= self.updateProperty(KodiItem,"plot",plot,"episode")
title = utils.convertEncoding(MBitem["Name"]) title = utils.convertEncoding(MBitem["Name"])
changes |= self.updateProperty(KodiItem,"title",title,"episode") changes |= self.updateProperty(KodiItem,"title",title,"episode")
changes |= self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"episode") changes |= self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"episode")
@ -563,9 +566,10 @@ class WriteKodiDB():
changes = True changes = True
else: else:
#xbmc.sleep(sleepVal) #xbmc.sleep(sleepVal)
propValue = json.dumps(propertyValue)
utils.logMsg("Emby","updating property..." + str(propertyName)) utils.logMsg("Emby","updating property..." + str(propertyName))
utils.logMsg("Emby","kodi value:" + KodiItem[propertyName] + " MB value: " + propertyValue) utils.logMsg("Emby","kodi value:" + KodiItem[propertyName] + " MB value: " + propValue)
params.append("\"" + propertyName + "\": \"" + propertyValue + "\"") params.append("\"" + propertyName + "\": " + propValue)
#xbmc.executeJSONRPC(jsoncommand_s %(id, propertyName, propertyValue.encode('utf-8'))) #xbmc.executeJSONRPC(jsoncommand_s %(id, propertyName, propertyValue.encode('utf-8')))
changes = True changes = True
@ -575,20 +579,16 @@ class WriteKodiDB():
def updateProperty(self,KodiItem,propertyName,propertyValue,fileType,forced=False): def updateProperty(self,KodiItem,propertyName,propertyValue,fileType,forced=False):
if fileType == "tvshow": if fileType == "tvshow":
id = KodiItem['tvshowid'] id = KodiItem['tvshowid']
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": %s}, "id": 1 }' jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": %s}, "id": 1 }'
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": "%s"}, "id": 1 }'
elif fileType == "episode": elif fileType == "episode":
id = KodiItem['episodeid'] id = KodiItem['episodeid']
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": %s}, "id": 1 }' jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": %s}, "id": 1 }'
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": "%s"}, "id": 1 }'
elif fileType == "musicvideo": elif fileType == "musicvideo":
id = KodiItem['musicvideoid'] id = KodiItem['musicvideoid']
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": %s}, "id": 1 }' jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": %s}, "id": 1 }'
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": "%s"}, "id": 1 }'
elif fileType == "movie": elif fileType == "movie":
id = KodiItem['movieid'] id = KodiItem['movieid']
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %s}, "id": 1 }' jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %s}, "id": 1 }'
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": "%s"}, "id": 1 }'
changes = False changes = False
if ((propertyValue != KodiItem[propertyName]) or forced): if ((propertyValue != KodiItem[propertyName]) or forced):
@ -597,7 +597,7 @@ class WriteKodiDB():
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
utils.logMsg("Emby","updating property..." + str(propertyName)) utils.logMsg("Emby","updating property..." + str(propertyName))
utils.logMsg("Emby","kodi value:" + str(KodiItem[propertyName]) + " MB value: " + str(propertyValue)) utils.logMsg("Emby","kodi value:" + str(KodiItem[propertyName]) + " MB value: " + str(propertyValue))
xbmc.executeJSONRPC(jsoncommand_i %(id, propertyName, propertyValue)) xbmc.executeJSONRPC(jsoncommand %(id, propertyName, propertyValue))
changes = True changes = True
elif type(propertyValue) is Decimal: elif type(propertyValue) is Decimal:
#extra compare decimals as int (rounded) #extra compare decimals as int (rounded)
@ -605,13 +605,14 @@ class WriteKodiDB():
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
utils.logMsg("Emby","updating property..." + str(propertyName)) utils.logMsg("Emby","updating property..." + str(propertyName))
utils.logMsg("Emby","kodi value:" + str(KodiItem[propertyName]) + " MB value: " + str(propertyValue)) utils.logMsg("Emby","kodi value:" + str(KodiItem[propertyName]) + " MB value: " + str(propertyValue))
xbmc.executeJSONRPC(jsoncommand_i %(id, propertyName, propertyValue)) xbmc.executeJSONRPC(jsoncommand %(id, propertyName, propertyValue))
changes = True changes = True
else: else:
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
propValue = json.dumps(propertyValue)
utils.logMsg("Emby","updating property..." + str(propertyName)) utils.logMsg("Emby","updating property..." + str(propertyName))
utils.logMsg("Emby","kodi value:" + KodiItem[propertyName] + " MB value: " + propertyValue) utils.logMsg("Emby","kodi value:" + KodiItem[propertyName] + " MB value: " + propValue)
xbmc.executeJSONRPC(jsoncommand_s %(id, propertyName, propertyValue.encode('utf-8'))) xbmc.executeJSONRPC(jsoncommand %(id, propertyName, propValue))
changes = True changes = True
return changes return changes