diff --git a/resources/lib/ReadKodiDB.py b/resources/lib/ReadKodiDB.py index 1981591e..f5acdb26 100644 --- a/resources/lib/ReadKodiDB.py +++ b/resources/lib/ReadKodiDB.py @@ -195,7 +195,6 @@ class ReadKodiDB(): return episodes def getKodiEpisodeByMbItem(self, episodeid, tvshowid): - xbmc.sleep(sleepVal) episode = None tvshow = self.getKodiTVShow(tvshowid) @@ -213,6 +212,30 @@ class ReadKodiDB(): return episode + def getKodiEpisodeByMbItemEx(self, id): + connection = utils.KodiSQL() + cursor = connection.cursor() + cursor.execute("SELECT idEpisode FROM episode WHERE c20 = ?", (id,)) + result = cursor.fetchone() + kodiId = None + if result != None: + kodiId = result[0] + cursor.close() + + episode = None + if(kodiId != None): + print "Kodi Episode ID : " + str(kodiId) + json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid": %d, "properties": ["playcount", "season", "resume", "episode", "lastplayed", "uniqueid", "file"]}, "id": 1}' %kodiId) + #json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid": ' + str(kodiId) + ', "properties": ["playcount", "season", "resume", "episode", "lastplayed", "uniqueid", "file"], "sort": {"method": "episode"}}, "id": 1}') + jsonobject = json.loads(json_response.decode('utf-8','replace')) + print "Kodi_Item: " + str(jsonobject) + if(jsonobject.has_key("result")): + result = jsonobject["result"] + if(result.has_key("episodedetails")): + episode = result["episodedetails"] + + return episode + def getKodiMusicVideo(self, id): #returns a single musicvideo from Kodi db selected on MB item ID xbmc.sleep(sleepVal) @@ -226,6 +249,8 @@ class ReadKodiDB(): musicvideoid = result[0] cursor.close() + musicvideo = None + if musicvideoid != None: json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideosDetails", "params": { "musicvideoid": ' + musicvideoid + ', "properties" : ["art", "thumbnail", "fanart", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track","plot", "director", "playcount", "lastplayed", "tag", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMusicVideos"}') jsonobject = json.loads(json_response.decode('utf-8','replace')) diff --git a/resources/lib/WebSocketClient.py b/resources/lib/WebSocketClient.py index 450bae49..eaf5c586 100644 --- a/resources/lib/WebSocketClient.py +++ b/resources/lib/WebSocketClient.py @@ -204,11 +204,13 @@ class WebSocketThread(threading.Thread): self.logMsg("Message : Doing LibraryChanged : Items Removed : " + str(itemsRemoved), 0) itemsRemoved = data.get("ItemsRemoved") for item in itemsRemoved: - WINDOW = xbmcgui.Window( 10000 ) - itemInfo=WINDOW.getProperty(item) - if "episode" in itemInfo: - type, tvshowid, episodeid = WINDOW.getProperty(item).split(";;") - xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveEpisode", "params": { "episodeid": %i}, "id": 1 }' %int(episodeid)) + self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteEpisodeFromKodiLibraryByMbId: " + item, 0) + WriteKodiDB().deleteEpisodeFromKodiLibraryByMbId(item) + self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteMovieFromKodiLibrary: " + item, 0) + WriteKodiDB().deleteMovieFromKodiLibrary(item) + self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteMusicVideoFromKodiLibrary: " + item, 0) + WriteKodiDB().deleteMusicVideoFromKodiLibrary(item) + # doing adds and updates itemsAdded = data.get("ItemsAdded") self.logMsg("Message : Doing LibraryChanged : Items Added : " + str(itemsAdded), 0) diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index 33df8bc7..cfad50c7 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -923,6 +923,15 @@ class WriteKodiDB(): else: utils.logMsg("episode not found in kodi DB",episodeid) + def deleteEpisodeFromKodiLibraryByMbId(self, id ): + utils.logMsg("deleting episode from Kodi library", id) + kodiItem = ReadKodiDB().getKodiEpisodeByMbItemEx(id) + if kodiItem != None: + xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveEpisode", "params": { "episodeid": %i}, "id": 1 }' %(kodiItem["episodeid"])) + utils.logMsg("episode deleted succesfully!", id) + else: + utils.logMsg("episode not found in kodi DB", id) + def addTVShowToKodiLibrary( self, MBitem, connection, cursor ): #adds a Tvshow to Kodi by directly inserting it to the DB while there is no addTvShow available on the json API #TODO: PR at Kodi team for a addTvShow endpoint on their API