fix delete item event

This commit is contained in:
shaun 2015-04-18 18:02:47 +10:00
parent 9e004fa1a1
commit 59713c80da
3 changed files with 42 additions and 6 deletions

View file

@ -195,7 +195,6 @@ class ReadKodiDB():
return episodes return episodes
def getKodiEpisodeByMbItem(self, episodeid, tvshowid): def getKodiEpisodeByMbItem(self, episodeid, tvshowid):
xbmc.sleep(sleepVal)
episode = None episode = None
tvshow = self.getKodiTVShow(tvshowid) tvshow = self.getKodiTVShow(tvshowid)
@ -213,6 +212,30 @@ class ReadKodiDB():
return episode 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): def getKodiMusicVideo(self, id):
#returns a single musicvideo from Kodi db selected on MB item ID #returns a single musicvideo from Kodi db selected on MB item ID
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
@ -226,6 +249,8 @@ class ReadKodiDB():
musicvideoid = result[0] musicvideoid = result[0]
cursor.close() cursor.close()
musicvideo = None
if musicvideoid != 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"}') 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')) jsonobject = json.loads(json_response.decode('utf-8','replace'))

View file

@ -204,11 +204,13 @@ class WebSocketThread(threading.Thread):
self.logMsg("Message : Doing LibraryChanged : Items Removed : " + str(itemsRemoved), 0) self.logMsg("Message : Doing LibraryChanged : Items Removed : " + str(itemsRemoved), 0)
itemsRemoved = data.get("ItemsRemoved") itemsRemoved = data.get("ItemsRemoved")
for item in itemsRemoved: for item in itemsRemoved:
WINDOW = xbmcgui.Window( 10000 ) self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteEpisodeFromKodiLibraryByMbId: " + item, 0)
itemInfo=WINDOW.getProperty(item) WriteKodiDB().deleteEpisodeFromKodiLibraryByMbId(item)
if "episode" in itemInfo: self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteMovieFromKodiLibrary: " + item, 0)
type, tvshowid, episodeid = WINDOW.getProperty(item).split(";;") WriteKodiDB().deleteMovieFromKodiLibrary(item)
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveEpisode", "params": { "episodeid": %i}, "id": 1 }' %int(episodeid)) self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteMusicVideoFromKodiLibrary: " + item, 0)
WriteKodiDB().deleteMusicVideoFromKodiLibrary(item)
# doing adds and updates # doing adds and updates
itemsAdded = data.get("ItemsAdded") itemsAdded = data.get("ItemsAdded")
self.logMsg("Message : Doing LibraryChanged : Items Added : " + str(itemsAdded), 0) self.logMsg("Message : Doing LibraryChanged : Items Added : " + str(itemsAdded), 0)

View file

@ -923,6 +923,15 @@ class WriteKodiDB():
else: else:
utils.logMsg("episode not found in kodi DB",episodeid) 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 ): 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 #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 #TODO: PR at Kodi team for a addTvShow endpoint on their API