mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
finished episode deletions
This commit is contained in:
parent
9287706ced
commit
62dda17680
3 changed files with 31 additions and 55 deletions
|
@ -489,7 +489,7 @@ class LibrarySync():
|
|||
show = ReadKodiDB().getKodiEpisodes(tvshow,False,False)
|
||||
if show != None:
|
||||
for episode in show:
|
||||
dict = {'mbid': str(episode["uniqueid"]["unknown"]),'kodiid': str(episode["episodeid"])}
|
||||
dict = {'episodeid': str(episode["uniqueid"]["unknown"]),'tvshowid': tvshow}
|
||||
allKodiEpisodeIds.append(dict)
|
||||
|
||||
showCurrent += 1
|
||||
|
@ -507,8 +507,8 @@ class LibrarySync():
|
|||
# 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'))
|
||||
if episode.get('episodeid') not in allMB3EpisodeIds:
|
||||
WriteKodiDB().deleteEpisodeFromKodiLibrary(episode.get('episodeid'),episode.get('tvshowid'))
|
||||
|
||||
# DELETES -- TV SHOWS
|
||||
if fullsync:
|
||||
|
@ -727,7 +727,7 @@ class LibrarySync():
|
|||
return True
|
||||
|
||||
MB3Episode = ReadEmbyDB().getItem(itemID)
|
||||
kodiItem = ReadKodiDB().getKodiEpisodeByMbItem(MB3Episode)
|
||||
kodiItem = ReadKodiDB().getKodiEpisodeByMbItem(MB3Episode["Id"], MB3Episode["SeriesId"])
|
||||
if (MB3Episode != None):
|
||||
userData=API().getUserData(MB3Episode)
|
||||
timeInfo = API().getTimeInfo(MB3Episode)
|
||||
|
|
|
@ -166,31 +166,21 @@ class ReadKodiDB():
|
|||
else:
|
||||
return episodes
|
||||
|
||||
def getKodiEpisodeByMbItem(self, MBitem):
|
||||
def getKodiEpisodeByMbItem(self, episodeid, tvshowid):
|
||||
xbmc.sleep(sleepVal)
|
||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "is", "field": "title", "value": "' + MBitem.get("SeriesName").encode('utf-8') + '"} }, "id": "libTvShows"}')
|
||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||
episode = None
|
||||
if(jsonobject.has_key('result')):
|
||||
result = jsonobject['result']
|
||||
if(result.has_key('tvshows')):
|
||||
tvshows = result['tvshows']
|
||||
tvshow = tvshows[0]
|
||||
|
||||
# find the episode by combination of season and episode
|
||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["playcount","season", "resume", "episode"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||
episodes = None
|
||||
if(jsonobject.has_key('result')):
|
||||
result = jsonobject['result']
|
||||
if(result.has_key('episodes')):
|
||||
episodes = result['episodes']
|
||||
|
||||
comparestring1 = str(MBitem.get("ParentIndexNumber")) + "-" + str(MBitem.get("IndexNumber"))
|
||||
for item in episodes:
|
||||
comparestring2 = str(item["season"]) + "-" + str(item["episode"])
|
||||
if comparestring1 == comparestring2:
|
||||
episode = item
|
||||
tvshow = self.getKodiTVShow(tvshowid)
|
||||
|
||||
if tvshow != None:
|
||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": ' + str(tvshow['tvshowid']) + ', "properties": ["playcount","season", "resume", "episode", "uniqueid", "file"], "sort": {"method": "episode"}}, "id": 1}')
|
||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||
if(jsonobject.has_key('result')):
|
||||
result = jsonobject['result']
|
||||
if(result.has_key('episodes')):
|
||||
episodes = result['episodes']
|
||||
for ep in episodes:
|
||||
if ep["uniqueid"]["unknown"] == episodeid:
|
||||
episode = ep
|
||||
break
|
||||
|
||||
return episode
|
||||
|
||||
|
|
|
@ -637,37 +637,21 @@ class WriteKodiDB():
|
|||
path = os.path.join(movieLibrary,id)
|
||||
allDirs, allFiles = xbmcvfs.listdir(path)
|
||||
for dir in allDirs:
|
||||
xbmcvfs.rmdir(dir)
|
||||
xbmcvfs.rmdir(os.path.join(path,dir))
|
||||
for file in allFiles:
|
||||
xbmcvfs.delete(file)
|
||||
xbmcvfs.delete(os.path.join(path,file))
|
||||
xbmcvfs.rmdir(path)
|
||||
|
||||
|
||||
def deleteEpisodeFromKodiLibrary(self, episodeid ):
|
||||
def deleteEpisodeFromKodiLibrary(self, episodeid, tvshowid ):
|
||||
utils.logMsg("deleting episode from Kodi library",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 "episodedetails --> " + jsonobject
|
||||
if(jsonobject.has_key('result')):
|
||||
result = jsonobject['result']
|
||||
if(result.has_key('episodedetails')):
|
||||
episodedetails = result['episodedetails']
|
||||
|
||||
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)
|
||||
xbmcvfs.delete(nfofile)
|
||||
episode = ReadKodiDB().getKodiEpisodeByMbItem(episodeid, tvshowid)
|
||||
if episode != None:
|
||||
strmfile = episode["file"]
|
||||
nfofile = strmfile.replace(".strm",".nfo")
|
||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveEpisode", "params": { "episodeid": %i}, "id": 1 }' %(episode["episodeid"]))
|
||||
xbmcvfs.delete(strmfile)
|
||||
xbmcvfs.delete(nfofile)
|
||||
|
||||
def addTVShowToKodiLibrary( self, item ):
|
||||
itemPath = os.path.join(tvLibrary,item["Id"])
|
||||
|
@ -698,7 +682,9 @@ class WriteKodiDB():
|
|||
xbmcvfs.rmdir(os.path.join(path,dir))
|
||||
for file in allFiles:
|
||||
xbmcvfs.delete(os.path.join(path,file))
|
||||
xbmcvfs.rmdir(path)
|
||||
succes = xbmcvfs.rmdir(path)
|
||||
if not succes:
|
||||
utils.logMsg("Error deleting TV show with ID ",id)
|
||||
|
||||
def updateSeasonArtwork(self,MBitem, KodiItem):
|
||||
#use sqlite to set the season artwork because no method in API available for this
|
||||
|
|
Loading…
Reference in a new issue