From 9287706ced95561ee373a9d00f9ccf62e0577484 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sat, 21 Mar 2015 11:32:21 +0100 Subject: [PATCH] fixed tv show deletions --- resources/lib/LibrarySync.py | 3 ++- resources/lib/WriteKodiDB.py | 31 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index d3f2f834..186a82bf 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -503,13 +503,14 @@ class LibrarySync(): cleanNeeded = False + # DELETES -- EPISODES # process any deletes only at fullsync allMB3EpisodeIds = set(allMB3EpisodeIds) for episode in allKodiEpisodeIds: if episode.get('mbid') not in allMB3EpisodeIds: WriteKodiDB().deleteEpisodeFromKodiLibrary(episode.get('kodiid')) - # TODO --> process deletes for episodes !!! + # DELETES -- TV SHOWS if fullsync: allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary) allMB3TVShows = set(allTVShows) diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index 7b96d01a..7d9e5a1a 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -635,16 +635,25 @@ class WriteKodiDB(): xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMovie", "params": { "movieid": %i}, "id": 1 }' %(kodiItem["movieid"])) path = os.path.join(movieLibrary,id) - xbmcvfs.rmdir(path) - + allDirs, allFiles = xbmcvfs.listdir(path) + for dir in allDirs: + xbmcvfs.rmdir(dir) + for file in allFiles: + xbmcvfs.delete(file) + xbmcvfs.rmdir(path) + + def deleteEpisodeFromKodiLibrary(self, episodeid ): utils.logMsg("deleting episode from Kodi library",episodeid) - json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": { "episodeid": %i}, "properties" : ["file","episodeid"] }, "id": 1}' %(int(episodeid))) + json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": { "episodeid": %s}, "properties": ["file","originaltitle"] }, "id": 1}' %(str(episodeid))) + + print "episodedetails --> " + json_response + if json_response != None and json_response != "" and json_response != []: jsonobject = json.loads(json_response.decode('utf-8','replace')) - print jsonobject + print "episodedetails --> " + jsonobject if(jsonobject.has_key('result')): result = jsonobject['result'] if(result.has_key('episodedetails')): @@ -652,7 +661,9 @@ class WriteKodiDB(): strmfile = episodedetails["file"] nfofile = strmfile.replace(".strm",".nfo") - + print "strmfile -->" + strmfile + print "nfofile -->" + nfofile + xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveEpisode", "params": { "episodeid": %i}, "id": 1 }' %(int(episodeid))) xbmcvfs.delete(strmfile) @@ -677,11 +688,17 @@ class WriteKodiDB(): xbmc.sleep(sleepVal) kodiItem = ReadKodiDB().getKodiTVShow(id) utils.logMsg("deleting tvshow from Kodi library",id) + if kodiItem != None: xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveTVShow", "params": { "tvshowid": %i}, "id": 1 }' %(kodiItem["tvshowid"])) + path = os.path.join(tvLibrary,id) - xbmcvfs.rmdir(path) - + allDirs, allFiles = xbmcvfs.listdir(path) + for dir in allDirs: + xbmcvfs.rmdir(os.path.join(path,dir)) + for file in allFiles: + xbmcvfs.delete(os.path.join(path,file)) + xbmcvfs.rmdir(path) def updateSeasonArtwork(self,MBitem, KodiItem): #use sqlite to set the season artwork because no method in API available for this