mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Queue updated items in playback, process on stop
This commit is contained in:
parent
59713c80da
commit
fca5f3c9f2
2 changed files with 66 additions and 34 deletions
|
@ -9,6 +9,7 @@ import inspect
|
||||||
import KodiMonitor
|
import KodiMonitor
|
||||||
import Utils as utils
|
import Utils as utils
|
||||||
from DownloadUtils import DownloadUtils
|
from DownloadUtils import DownloadUtils
|
||||||
|
from WebSocketClient import WebSocketThread
|
||||||
from PlayUtils import PlayUtils
|
from PlayUtils import PlayUtils
|
||||||
from ClientInformation import ClientInformation
|
from ClientInformation import ClientInformation
|
||||||
from LibrarySync import LibrarySync
|
from LibrarySync import LibrarySync
|
||||||
|
@ -59,6 +60,7 @@ class Player( xbmc.Player ):
|
||||||
|
|
||||||
def stopAll(self):
|
def stopAll(self):
|
||||||
|
|
||||||
|
WebSocketThread().processPendingActions()
|
||||||
if(len(self.played_information) == 0):
|
if(len(self.played_information) == 0):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -103,7 +105,7 @@ class Player( xbmc.Player ):
|
||||||
txt_mac = clientInfo.getMachineId()
|
txt_mac = clientInfo.getMachineId()
|
||||||
url = "%s/mediabrowser/Videos/ActiveEncodings" % server
|
url = "%s/mediabrowser/Videos/ActiveEncodings" % server
|
||||||
url = url + '?DeviceId=' + txt_mac
|
url = url + '?DeviceId=' + txt_mac
|
||||||
self.downloadUtils.downloadUrl(url, type="DELETE")
|
self.downloadUtils.downloadUrl(url, type="DELETE")
|
||||||
|
|
||||||
def stopPlayback(self, data):
|
def stopPlayback(self, data):
|
||||||
self.printDebug("stopPlayback called")
|
self.printDebug("stopPlayback called")
|
||||||
|
|
|
@ -20,6 +20,9 @@ from LibrarySync import LibrarySync
|
||||||
from WriteKodiDB import WriteKodiDB
|
from WriteKodiDB import WriteKodiDB
|
||||||
import Utils as utils
|
import Utils as utils
|
||||||
|
|
||||||
|
pendingUserDataList = []
|
||||||
|
pendingItemsToRemove = []
|
||||||
|
pendingItemsToUpdate = []
|
||||||
_MODE_BASICPLAY=12
|
_MODE_BASICPLAY=12
|
||||||
|
|
||||||
class WebSocketThread(threading.Thread):
|
class WebSocketThread(threading.Thread):
|
||||||
|
@ -65,9 +68,7 @@ class WebSocketThread(threading.Thread):
|
||||||
self.logMsg("Exception : " + str(e), level=0)
|
self.logMsg("Exception : " + str(e), level=0)
|
||||||
else:
|
else:
|
||||||
self.logMsg("Sending Playback Started NO Object ERROR")
|
self.logMsg("Sending Playback Started NO Object ERROR")
|
||||||
'''
|
|
||||||
|
|
||||||
'''
|
|
||||||
def playbackStopped(self, itemId, ticks):
|
def playbackStopped(self, itemId, ticks):
|
||||||
if(self.client != None):
|
if(self.client != None):
|
||||||
try:
|
try:
|
||||||
|
@ -133,6 +134,9 @@ class WebSocketThread(threading.Thread):
|
||||||
self.logMsg("Stopping Client NO Object ERROR")
|
self.logMsg("Stopping Client NO Object ERROR")
|
||||||
|
|
||||||
def on_message(self, ws, message):
|
def on_message(self, ws, message):
|
||||||
|
global pendingUserDataList
|
||||||
|
global pendingItemsToRemove
|
||||||
|
global pendingItemsToUpdate
|
||||||
self.logMsg("Message : " + str(message), 0)
|
self.logMsg("Message : " + str(message), 0)
|
||||||
result = json.loads(message)
|
result = json.loads(message)
|
||||||
|
|
||||||
|
@ -188,12 +192,10 @@ class WebSocketThread(threading.Thread):
|
||||||
userDataList = data.get("UserDataList")
|
userDataList = data.get("UserDataList")
|
||||||
self.logMsg("Message : Doing UserDataChanged : UserDataList : " + str(userDataList), 0)
|
self.logMsg("Message : Doing UserDataChanged : UserDataList : " + str(userDataList), 0)
|
||||||
if(userDataList != None):
|
if(userDataList != None):
|
||||||
for userData in userDataList:
|
if xbmc.Player().isPlaying():
|
||||||
self.logMsg("Message : Doing UserDataChanged : UserData : " + str(userData), 0)
|
pendingUserDataList += userDataList
|
||||||
itemId = userData.get("ItemId")
|
else:
|
||||||
if(itemId != None):
|
self.user_data_update(userDataList)
|
||||||
self.logMsg("Message : Doing UserDataChanged : calling updatePlayCount with ID : " + str(itemId), 0)
|
|
||||||
LibrarySync().updatePlayCount(itemId)
|
|
||||||
|
|
||||||
elif(messageType != None and messageType == "LibraryChanged"):
|
elif(messageType != None and messageType == "LibraryChanged"):
|
||||||
foldersAddedTo = data.get("FoldersAddedTo")
|
foldersAddedTo = data.get("FoldersAddedTo")
|
||||||
|
@ -201,30 +203,48 @@ class WebSocketThread(threading.Thread):
|
||||||
|
|
||||||
# doing items removed
|
# doing items removed
|
||||||
itemsRemoved = data.get("ItemsRemoved")
|
itemsRemoved = data.get("ItemsRemoved")
|
||||||
self.logMsg("Message : Doing LibraryChanged : Items Removed : " + str(itemsRemoved), 0)
|
|
||||||
itemsRemoved = data.get("ItemsRemoved")
|
|
||||||
for item in itemsRemoved:
|
|
||||||
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteEpisodeFromKodiLibraryByMbId: " + item, 0)
|
|
||||||
WriteKodiDB().deleteEpisodeFromKodiLibraryByMbId(item)
|
|
||||||
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteMovieFromKodiLibrary: " + item, 0)
|
|
||||||
WriteKodiDB().deleteMovieFromKodiLibrary(item)
|
|
||||||
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteMusicVideoFromKodiLibrary: " + item, 0)
|
|
||||||
WriteKodiDB().deleteMusicVideoFromKodiLibrary(item)
|
|
||||||
|
|
||||||
# doing adds and updates
|
|
||||||
itemsAdded = data.get("ItemsAdded")
|
itemsAdded = data.get("ItemsAdded")
|
||||||
self.logMsg("Message : Doing LibraryChanged : Items Added : " + str(itemsAdded), 0)
|
|
||||||
itemsUpdated = data.get("ItemsUpdated")
|
itemsUpdated = data.get("ItemsUpdated")
|
||||||
self.logMsg("Message : Doing LibraryChanged : Items Updated : " + str(itemsUpdated), 0)
|
|
||||||
itemsToUpdate = itemsAdded + itemsUpdated
|
itemsToUpdate = itemsAdded + itemsUpdated
|
||||||
if(len(itemsToUpdate) > 0):
|
self.logMsg("Message : WebSocket LibraryChanged : Items Added : " + str(itemsAdded), 0)
|
||||||
self.logMsg("Message : Doing LibraryChanged : Processing Added and Updated : " + str(itemsToUpdate), 0)
|
self.logMsg("Message : WebSocket LibraryChanged : Items Updated : " + str(itemsUpdated), 0)
|
||||||
connection = utils.KodiSQL()
|
self.logMsg("Message : WebSocket LibraryChanged : Items Removed : " + str(itemsRemoved), 0)
|
||||||
cursor = connection.cursor()
|
|
||||||
LibrarySync().MoviesSync(connection, cursor, fullsync = False, installFirstRun = False, itemList = itemsToUpdate)
|
if xbmc.Player().isPlaying():
|
||||||
LibrarySync().TvShowsSync(connection, cursor, fullsync = False, installFirstRun = False, itemList = itemsToUpdate)
|
pendingItemsToRemove += itemsRemoved
|
||||||
cursor.close()
|
pendingItemsToUpdate += itemsToUpdate
|
||||||
|
else:
|
||||||
|
self.remove_items(itemsRemoved)
|
||||||
|
self.update_items(itemsToUpdate)
|
||||||
|
|
||||||
|
def remove_items(self, itemsRemoved):
|
||||||
|
for item in itemsRemoved:
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteEpisodeFromKodiLibraryByMbId: " + item, 0)
|
||||||
|
WriteKodiDB().deleteEpisodeFromKodiLibraryByMbId(item)
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteMovieFromKodiLibrary: " + item, 0)
|
||||||
|
WriteKodiDB().deleteMovieFromKodiLibrary(item)
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteMusicVideoFromKodiLibrary: " + item, 0)
|
||||||
|
WriteKodiDB().deleteMusicVideoFromKodiLibrary(item)
|
||||||
|
|
||||||
|
def update_items(self, itemsToUpdate):
|
||||||
|
# doing adds and updates
|
||||||
|
if(len(itemsToUpdate) > 0):
|
||||||
|
self.logMsg("Message : Doing LibraryChanged : Processing Added and Updated : " + str(itemsToUpdate), 0)
|
||||||
|
connection = utils.KodiSQL()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
LibrarySync().MoviesSync(connection, cursor, fullsync = False, installFirstRun = False, itemList = itemsToUpdate)
|
||||||
|
LibrarySync().TvShowsSync(connection, cursor, fullsync = False, installFirstRun = False, itemList = itemsToUpdate)
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
def user_data_update(self, userData):
|
||||||
|
|
||||||
|
for userData in userDataList:
|
||||||
|
self.logMsg("Message : Doing UserDataChanged : UserData : " + str(userData), 0)
|
||||||
|
itemId = userData.get("ItemId")
|
||||||
|
if(itemId != None):
|
||||||
|
self.logMsg("Message : Doing UserDataChanged : calling updatePlayCount with ID : " + str(itemId), 0)
|
||||||
|
LibrarySync().updatePlayCount(itemId)
|
||||||
|
|
||||||
def on_error(self, ws, error):
|
def on_error(self, ws, error):
|
||||||
self.logMsg("Error : " + str(error))
|
self.logMsg("Error : " + str(error))
|
||||||
#raise
|
#raise
|
||||||
|
@ -273,7 +293,6 @@ class WebSocketThread(threading.Thread):
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
addonSettings = xbmcaddon.Addon(id='plugin.video.emby')
|
addonSettings = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
WINDOW = xbmcgui.Window(10000)
|
WINDOW = xbmcgui.Window(10000)
|
||||||
username = WINDOW.getProperty('currUser')
|
username = WINDOW.getProperty('currUser')
|
||||||
|
@ -310,9 +329,20 @@ class WebSocketThread(threading.Thread):
|
||||||
self.logMsg("Client Needs To Restart")
|
self.logMsg("Client Needs To Restart")
|
||||||
if self.KodiMonitor.waitForAbort(5):
|
if self.KodiMonitor.waitForAbort(5):
|
||||||
break
|
break
|
||||||
|
|
||||||
self.logMsg("Thread Exited")
|
self.logMsg("Thread Exited")
|
||||||
|
|
||||||
|
|
||||||
|
def processPendingActions(self):
|
||||||
|
global pendingUserDataList
|
||||||
|
global pendingItemsToRemove
|
||||||
|
global pendingItemsToUpdate
|
||||||
|
if pendingUserDataList != []:
|
||||||
|
self.user_data_update(pendingUserDataList)
|
||||||
|
pendingUserDataList = []
|
||||||
|
if pendingItemsToRemove != []:
|
||||||
|
self.remove_items(pendingItemsToRemove)
|
||||||
|
pendingItemsToRemove = []
|
||||||
|
if pendingItemsToUpdate != []:
|
||||||
|
self.update_items(pendingItemsToUpdate)
|
||||||
|
pendingItemsToUpdate = []
|
||||||
|
|
Loading…
Reference in a new issue