mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Implement LibraryChanged WebSocket event
This commit is contained in:
parent
e9646407a0
commit
c8e1d8ae54
4 changed files with 42 additions and 15 deletions
|
@ -67,7 +67,7 @@ class LibrarySync():
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def MoviesSync(self, fullsync, installFirstRun):
|
def MoviesSync(self, fullsync, installFirstRun, itemList = []):
|
||||||
|
|
||||||
WINDOW = xbmcgui.Window( 10000 )
|
WINDOW = xbmcgui.Window( 10000 )
|
||||||
pDialog = None
|
pDialog = None
|
||||||
|
@ -99,7 +99,7 @@ class LibrarySync():
|
||||||
for view in views:
|
for view in views:
|
||||||
|
|
||||||
#process new movies
|
#process new movies
|
||||||
allMB3Movies = ReadEmbyDB().getMovies(view.get('id'), True, fullsync)
|
allMB3Movies = ReadEmbyDB().getMovies(id = view.get('id'), fullinfo=True, fullSync = fullsync, itemList = itemList)
|
||||||
allKodiIds = set(ReadKodiDB().getKodiMoviesIds(True))
|
allKodiIds = set(ReadKodiDB().getKodiMoviesIds(True))
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
|
@ -255,7 +255,7 @@ class LibrarySync():
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def TvShowsSync(self, fullsync, installFirstRun):
|
def TvShowsSync(self, fullsync, installFirstRun, itemList = []):
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
WINDOW = xbmcgui.Window( 10000 )
|
WINDOW = xbmcgui.Window( 10000 )
|
||||||
|
@ -282,7 +282,8 @@ class LibrarySync():
|
||||||
# incremental sync --> new episodes only
|
# incremental sync --> new episodes only
|
||||||
if not fullsync:
|
if not fullsync:
|
||||||
|
|
||||||
latestMBEpisodes = ReadEmbyDB().getLatestEpisodes(True)
|
latestMBEpisodes = ReadEmbyDB().getLatestEpisodes(fullinfo = True, itemList = itemList)
|
||||||
|
utils.logMsg("Sync TV", "Inc Sync Started on : " + str(len(latestMBEpisodes)) + " : " + str(itemList), 1)
|
||||||
|
|
||||||
if latestMBEpisodes != None:
|
if latestMBEpisodes != None:
|
||||||
allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds(True))
|
allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds(True))
|
||||||
|
|
|
@ -12,7 +12,7 @@ from DownloadUtils import DownloadUtils
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
|
|
||||||
class ReadEmbyDB():
|
class ReadEmbyDB():
|
||||||
def getMovies(self, id, fullinfo = False, fullSync = True):
|
def getMovies(self, id, fullinfo = False, fullSync = True, itemList = []):
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
|
@ -23,10 +23,13 @@ class ReadEmbyDB():
|
||||||
downloadUtils = DownloadUtils()
|
downloadUtils = DownloadUtils()
|
||||||
userid = downloadUtils.getUserId()
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
if not fullSync:
|
if fullSync:
|
||||||
sortstring = "&Limit=20&SortBy=DateCreated"
|
|
||||||
else:
|
|
||||||
sortstring = "&SortBy=SortName"
|
sortstring = "&SortBy=SortName"
|
||||||
|
else:
|
||||||
|
if(len(itemList) > 0): # if we want a certain list specify it
|
||||||
|
sortstring = "&Ids=" + ",".join(itemList)
|
||||||
|
else: # just get the last 20 created items
|
||||||
|
sortstring = "&Limit=20&SortBy=DateCreated"
|
||||||
|
|
||||||
if fullinfo:
|
if fullinfo:
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + id + sortstring + '&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Movie&CollapseBoxSetItems=false&format=json&ImageTypeLimit=1'
|
url = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + id + sortstring + '&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Movie&CollapseBoxSetItems=false&format=json&ImageTypeLimit=1'
|
||||||
|
@ -179,7 +182,7 @@ class ReadEmbyDB():
|
||||||
result = result['Items']
|
result = result['Items']
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def getLatestEpisodes(self,fullinfo = False):
|
def getLatestEpisodes(self, fullinfo = False, itemList = []):
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
|
@ -190,10 +193,14 @@ class ReadEmbyDB():
|
||||||
downloadUtils = DownloadUtils()
|
downloadUtils = DownloadUtils()
|
||||||
userid = downloadUtils.getUserId()
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
|
limitString = "Limit=20&SortBy=DateCreated&"
|
||||||
|
if(len(itemList) > 0): # if we want a certain list specify it
|
||||||
|
limitString = "Ids=" + ",".join(itemList) + "&"
|
||||||
|
|
||||||
if fullinfo:
|
if fullinfo:
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
url = server + '/mediabrowser/Users/' + userid + '/Items?' + limitString + 'IsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
||||||
else:
|
else:
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
url = server + '/mediabrowser/Users/' + userid + '/Items?' + limitString + 'IsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
||||||
|
|
||||||
jsonData = downloadUtils.downloadUrl(url, suppress=False, popup=0)
|
jsonData = downloadUtils.downloadUrl(url, suppress=False, popup=0)
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,25 @@ class WebSocketThread(threading.Thread):
|
||||||
if(embyItemId != None and len(embyItemId) == 2):
|
if(embyItemId != None and len(embyItemId) == 2):
|
||||||
LibrarySync().updatePlayCount(embyItemId[0], embyItemId[1])
|
LibrarySync().updatePlayCount(embyItemId[0], embyItemId[1])
|
||||||
|
|
||||||
|
elif(messageType != None and messageType == "LibraryChanged"):
|
||||||
|
foldersAddedTo = data.get("FoldersAddedTo")
|
||||||
|
foldersRemovedFrom = data.get("FoldersRemovedFrom")
|
||||||
|
|
||||||
|
# doing items removed
|
||||||
|
itemsRemoved = data.get("ItemsRemoved")
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Items Removed : " + str(itemsRemoved), 0)
|
||||||
|
|
||||||
|
# doing adds and updates
|
||||||
|
itemsAdded = data.get("ItemsAdded")
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Items Added : " + str(itemsAdded), 0)
|
||||||
|
itemsUpdated = data.get("ItemsUpdated")
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Items Updated : " + str(itemsUpdated), 0)
|
||||||
|
itemsToUpdate = itemsAdded + itemsUpdated
|
||||||
|
if(len(itemsToUpdate) > 0):
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Processing Added and Updated : " + str(itemsToUpdate), 0)
|
||||||
|
LibrarySync().MoviesSync(fullsync = False, installFirstRun = False, itemList = itemsToUpdate)
|
||||||
|
LibrarySync().TvShowsSync(fullsync = False, installFirstRun = False, itemList = itemsToUpdate)
|
||||||
|
|
||||||
def on_error(self, ws, error):
|
def on_error(self, ws, error):
|
||||||
self.logMsg("Error : " + str(error))
|
self.logMsg("Error : " + str(error))
|
||||||
#raise
|
#raise
|
||||||
|
|
|
@ -39,8 +39,8 @@ class Service():
|
||||||
player = Player()
|
player = Player()
|
||||||
lastProgressUpdate = datetime.today()
|
lastProgressUpdate = datetime.today()
|
||||||
|
|
||||||
interval_FullSync = 120
|
interval_FullSync = 600
|
||||||
interval_IncrementalSync = 30
|
interval_IncrementalSync = 300
|
||||||
|
|
||||||
cur_seconds_fullsync = interval_FullSync
|
cur_seconds_fullsync = interval_FullSync
|
||||||
cur_seconds_incrsync = interval_IncrementalSync
|
cur_seconds_incrsync = interval_IncrementalSync
|
||||||
|
|
Loading…
Reference in a new issue