mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
support for episode deletions
This commit is contained in:
parent
63bd250c4b
commit
09e62d570c
5 changed files with 63 additions and 29 deletions
|
@ -108,6 +108,8 @@ class CreateFiles():
|
||||||
xbmcvfs.mkdir(itemPath)
|
xbmcvfs.mkdir(itemPath)
|
||||||
root = Element(rootelement)
|
root = Element(rootelement)
|
||||||
SubElement(root, "id").text = item["Id"]
|
SubElement(root, "id").text = item["Id"]
|
||||||
|
SubElement(root, "uniqueid").text = item["Id"]
|
||||||
|
|
||||||
if item.get("Tag") != None:
|
if item.get("Tag") != None:
|
||||||
for tag in item.get("Tag"):
|
for tag in item.get("Tag"):
|
||||||
SubElement(root, "tag").text = tag
|
SubElement(root, "tag").text = tag
|
||||||
|
|
|
@ -20,15 +20,9 @@ class Kodi_Monitor(xbmc.Monitor):
|
||||||
|
|
||||||
#this library monitor is used to detect a watchedstate change by the user through the library
|
#this library monitor is used to detect a watchedstate change by the user through the library
|
||||||
def onNotification (self,sender,method,data):
|
def onNotification (self,sender,method,data):
|
||||||
|
|
||||||
if method == "VideoLibrary.OnUpdate":
|
if method == "VideoLibrary.OnUpdate":
|
||||||
|
|
||||||
#check windowprop if the sync is busy to prevent any false updates
|
|
||||||
#WINDOW = xbmcgui.Window( 10000 )
|
|
||||||
#if WINDOW.getProperty("librarysync") != "busy":
|
|
||||||
# I don't thing we need this, the playcount is not present in updates that don't touch that
|
|
||||||
# and when the playcount is updated byt he sync it just sends the same data back to the server
|
|
||||||
# if you add this back in you will never be able to trigger a play status update while the sync is running
|
|
||||||
|
|
||||||
jsondata = json.loads(data)
|
jsondata = json.loads(data)
|
||||||
if jsondata != None:
|
if jsondata != None:
|
||||||
|
|
||||||
|
@ -37,6 +31,6 @@ class Kodi_Monitor(xbmc.Monitor):
|
||||||
item = jsondata.get("item").get("id")
|
item = jsondata.get("item").get("id")
|
||||||
type = jsondata.get("item").get("type")
|
type = jsondata.get("item").get("type")
|
||||||
if playcount != None:
|
if playcount != None:
|
||||||
xbmc.log("Kodi_Monitor -> onNotification -> VideoLibrary.OnUpdate : " + str(data))
|
utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2)
|
||||||
WriteKodiDB().updatePlayCountFromKodi(item, type, playcount)
|
WriteKodiDB().updatePlayCountFromKodi(item, type, playcount)
|
||||||
|
|
||||||
|
|
|
@ -251,7 +251,7 @@ class LibrarySync():
|
||||||
for episode in latestMBEpisodes:
|
for episode in latestMBEpisodes:
|
||||||
if episode["SeriesId"] in allKodiTvShowsIds:
|
if episode["SeriesId"] in allKodiTvShowsIds:
|
||||||
#only process tvshows that already exist in the db at incremental updates
|
#only process tvshows that already exist in the db at incremental updates
|
||||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(episode["SeriesId"])
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(episode["SeriesId"],True,True)
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
return True
|
return True
|
||||||
|
@ -295,7 +295,7 @@ class LibrarySync():
|
||||||
for episode in latestMBEpisodes:
|
for episode in latestMBEpisodes:
|
||||||
if episode["SeriesId"] in allKodiTvShowsIds:
|
if episode["SeriesId"] in allKodiTvShowsIds:
|
||||||
#only process tvshows that already exist in the db at incremental updates
|
#only process tvshows that already exist in the db at incremental updates
|
||||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(episode["SeriesId"])
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(episode["SeriesId"],True,True)
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
return True
|
return True
|
||||||
|
@ -321,8 +321,9 @@ class LibrarySync():
|
||||||
# full sync --> Tv shows and Episodes
|
# full sync --> Tv shows and Episodes
|
||||||
if fullsync:
|
if fullsync:
|
||||||
allTVShows = list()
|
allTVShows = list()
|
||||||
allEpisodes = list()
|
allMB3EpisodeIds = list() #for use with deletions
|
||||||
#FIXME --> for now pull all tv shows and use the incremental update only at episode level
|
allKodiEpisodeIds = [] # for use with deletions
|
||||||
|
|
||||||
tvShowData = ReadEmbyDB().getTVShows(True,True)
|
tvShowData = ReadEmbyDB().getTVShows(True,True)
|
||||||
allKodiIds = set(ReadKodiDB().getKodiTvShowsIds(True))
|
allKodiIds = set(ReadKodiDB().getKodiTvShowsIds(True))
|
||||||
updateNeeded = False
|
updateNeeded = False
|
||||||
|
@ -366,7 +367,7 @@ class LibrarySync():
|
||||||
for tvshow in allTVShows:
|
for tvshow in allTVShows:
|
||||||
|
|
||||||
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
||||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow)
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow,True,True)
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
return True
|
return True
|
||||||
|
@ -458,7 +459,7 @@ class LibrarySync():
|
||||||
for tvshow in allTVShows:
|
for tvshow in allTVShows:
|
||||||
|
|
||||||
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
||||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow)
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow,True,True)
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
return True
|
return True
|
||||||
|
@ -471,6 +472,10 @@ class LibrarySync():
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
for item in episodeData:
|
for item in episodeData:
|
||||||
|
|
||||||
|
#add episodeId to the list of all episodes for use later on the deletes
|
||||||
|
allMB3EpisodeIds.append(item["Id"])
|
||||||
|
|
||||||
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
||||||
matchFound = False
|
matchFound = False
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
|
@ -486,7 +491,14 @@ class LibrarySync():
|
||||||
percentage = int(((float(count) / float(total)) * 100))
|
percentage = int(((float(count) / float(total)) * 100))
|
||||||
pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
|
pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
|
||||||
|
#add all kodi episodes to a list with episodes for use later on to delete episodes
|
||||||
|
#the mediabrowser ID is set as uniqueID in the NFO... for some reason this has key 'unknown' in the json response
|
||||||
|
for episode in ReadKodiDB().getKodiEpisodes(tvshow,False,False):
|
||||||
|
dict = {'mbid': str(episode["uniqueid"]["unknown"]),'kodiid': str(episode["episodeid"])}
|
||||||
|
allKodiEpisodeIds.append(dict)
|
||||||
|
|
||||||
showCurrent += 1
|
showCurrent += 1
|
||||||
|
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
|
@ -499,6 +511,11 @@ class LibrarySync():
|
||||||
cleanNeeded = False
|
cleanNeeded = False
|
||||||
|
|
||||||
# process any deletes only at fullsync
|
# 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 !!!
|
# TODO --> process deletes for episodes !!!
|
||||||
if fullsync:
|
if fullsync:
|
||||||
allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary)
|
allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary)
|
||||||
|
@ -631,7 +648,7 @@ class LibrarySync():
|
||||||
for item in tvshowData:
|
for item in tvshowData:
|
||||||
|
|
||||||
episodeData = ReadEmbyDB().getEpisodes(item["Id"], False)
|
episodeData = ReadEmbyDB().getEpisodes(item["Id"], False)
|
||||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(item["Id"],False)
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(item["Id"],False,True)
|
||||||
|
|
||||||
if (episodeData != None):
|
if (episodeData != None):
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
|
|
|
@ -134,7 +134,7 @@ class ReadKodiDB():
|
||||||
tvshow = tvshows[0]
|
tvshow = tvshows[0]
|
||||||
return tvshow
|
return tvshow
|
||||||
|
|
||||||
def getKodiEpisodes(self, id, fullInfo = True):
|
def getKodiEpisodes(self, id, fullInfo = True, returnmap = True):
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
episodes = None
|
episodes = None
|
||||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["title", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["title", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
||||||
|
@ -146,24 +146,25 @@ class ReadKodiDB():
|
||||||
tvshows = result['tvshows']
|
tvshows = result['tvshows']
|
||||||
tvshow = tvshows[0]
|
tvshow = tvshows[0]
|
||||||
if fullInfo:
|
if fullInfo:
|
||||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "file", "lastplayed", "rating", "resume", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "file", "lastplayed", "rating", "resume", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded","uniqueid"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
||||||
else:
|
else:
|
||||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "season", "episode", "lastplayed", "resume"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "season", "episode", "lastplayed", "resume","file","uniqueid"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
||||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
episodes = None
|
episodes = None
|
||||||
if(jsonobject.has_key('result')):
|
if(jsonobject.has_key('result')):
|
||||||
result = jsonobject['result']
|
result = jsonobject['result']
|
||||||
if(result.has_key('episodes')):
|
if(result.has_key('episodes')):
|
||||||
episodes = result['episodes']
|
episodes = result['episodes']
|
||||||
|
if returnmap:
|
||||||
episodeMap = None
|
episodeMap = None
|
||||||
if(episodes != None):
|
if(episodes != None):
|
||||||
episodeMap = {}
|
episodeMap = {}
|
||||||
for KodiItem in episodes:
|
for KodiItem in episodes:
|
||||||
key = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
key = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
||||||
episodeMap[key] = KodiItem
|
episodeMap[key] = KodiItem
|
||||||
|
return episodeMap
|
||||||
return episodeMap
|
else:
|
||||||
|
return episodes
|
||||||
|
|
||||||
def getKodiEpisodeByMbItem(self, MBitem):
|
def getKodiEpisodeByMbItem(self, MBitem):
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
|
|
|
@ -419,7 +419,27 @@ class WriteKodiDB():
|
||||||
|
|
||||||
path = os.path.join(movieLibrary,id)
|
path = os.path.join(movieLibrary,id)
|
||||||
xbmcvfs.rmdir(path)
|
xbmcvfs.rmdir(path)
|
||||||
|
|
||||||
|
def deleteEpisodeFromKodiLibrary(self, episodeid ):
|
||||||
|
utils.logMsg("deleting movie from Kodi library",id)
|
||||||
|
|
||||||
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": { "episodeid": %i}, "properties" : ["file","episodeid"] }, "id": "libTvShows"}' %(int(episodeid)))
|
||||||
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
|
|
||||||
|
print 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")
|
||||||
|
|
||||||
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveEpisode", "params": { "episodeid": %i}, "id": 1 }' %(int(episodeid)))
|
||||||
|
|
||||||
|
xbmcvfs.delete(strmfile)
|
||||||
|
xbmcvfs.delete(nfofile)
|
||||||
|
|
||||||
def addTVShowToKodiLibrary( self, item ):
|
def addTVShowToKodiLibrary( self, item ):
|
||||||
itemPath = os.path.join(tvLibrary,item["Id"])
|
itemPath = os.path.join(tvLibrary,item["Id"])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue