From eff7d7b68b1451b2b14125e8e3fa8c423455b74d Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sat, 23 Jul 2016 18:06:47 +0200 Subject: [PATCH] Use 1 PKC xbmc.player instance --- resources/lib/PlexCompanion.py | 13 +++++++++---- resources/lib/kodimonitor.py | 4 ++-- resources/lib/librarysync.py | 8 ++++---- resources/lib/playlist.py | 5 +++-- service.py | 13 +++++++------ 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/resources/lib/PlexCompanion.py b/resources/lib/PlexCompanion.py index 485bcc65..29f2fe82 100644 --- a/resources/lib/PlexCompanion.py +++ b/resources/lib/PlexCompanion.py @@ -21,7 +21,7 @@ class PlexCompanion(threading.Thread): """ Initialize with a Queue for callbacks """ - def __init__(self): + def __init__(self, player=None): self.logMsg("----===## Starting PlexCompanion ##===----", 1) self.settings = settings.getSettings() @@ -35,6 +35,9 @@ class PlexCompanion(threading.Thread): self.queueId = None self.playlist = None + # kodi player instance + self.player = player + threading.Thread.__init__(self) def _getStartItem(self, string): @@ -82,11 +85,13 @@ class PlexCompanion(threading.Thread): self.queueId = None if self.playlist is None: if data.get('type') == 'music': - self.playlist = playlist.Playlist('music') + self.playlist = playlist.Playlist('music', + player=self.player) elif data.get('type') == 'video': - self.playlist = playlist.Playlist('video') + self.playlist = playlist.Playlist('video', + player=self.player) else: - self.playlist = playlist.Playlist() + self.playlist = playlist.Playlist(player=self.player) if queueId != self.queueId: self.logMsg('New playlist received, updating!', 1) self.queueId = queueId diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 97b807b1..5a814402 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -20,10 +20,10 @@ from PlexFunctions import scrobble @utils.logging class KodiMonitor(xbmc.Monitor): - def __init__(self): + def __init__(self, player=None): self.doUtils = downloadutils.DownloadUtils().downloadUrl - self.xbmcplayer = xbmc.Player() + self.xbmcplayer = player xbmc.Monitor.__init__(self) self.logMsg("Kodi monitor started.", 1) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 9eeaed22..7c87d6f4 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -1549,9 +1549,9 @@ class LibrarySync(Thread): with itemFkt() as Fkt: Fkt.updatePlaystate(item) - def run(self): + def run(self, player=None): try: - self.run_internal() + self.run_internal(player) except Exception as e: utils.window('plex_dbScan', clear=True) self.logMsg('LibrarySync thread crashed', -1) @@ -1563,7 +1563,7 @@ class LibrarySync(Thread): self.__language__(39400)) raise - def run_internal(self): + def run_internal(self, player=None): # Re-assign handles to have faster calls window = utils.window settings = utils.settings @@ -1582,7 +1582,7 @@ class LibrarySync(Thread): lastProcessing = 0 oneDay = 60*60*24 - xbmcplayer = xbmc.Player() + xbmcplayer = player queue = self.queue diff --git a/resources/lib/playlist.py b/resources/lib/playlist.py index e48fb4a2..a38b1897 100644 --- a/resources/lib/playlist.py +++ b/resources/lib/playlist.py @@ -21,7 +21,7 @@ class Playlist(): """ Initiate with Playlist(typus='video' or 'music') """ - def __init__(self, typus=None): + def __init__(self, typus=None, player=None): self.userid = utils.window('currUserId') self.server = utils.window('pms_server') # Construct the Kodi playlist instance @@ -38,7 +38,8 @@ class Playlist(): self.typus = None if self.playlist is not None: self.playlistId = self.playlist.getPlayListId() - self.player = xbmc.Player() + # kodi player instance + self.player = player # "interal" PKC playlist self.items = [] diff --git a/service.py b/service.py index 9642ffa5..e2003332 100644 --- a/service.py +++ b/service.py @@ -140,7 +140,6 @@ class Service(): ws = wsc.WebSocket(queue) library = librarysync.LibrarySync(queue) kplayer = player.Player() - xplayer = xbmc.Player() plx = PlexAPI.PlexAPI() # Sync and progress report @@ -167,11 +166,11 @@ class Service(): # Verify if user is set and has access to the server if (user.currUser is not None) and user.HasAccess: # If an item is playing - if xplayer.isPlaying(): + if kplayer.isPlaying(): try: # Update and report progress - playtime = xplayer.getTime() - totalTime = xplayer.getTotalTime() + playtime = kplayer.getTime() + totalTime = kplayer.getTotalTime() currentFile = kplayer.currentFile # Update positionticks @@ -209,7 +208,8 @@ class Service(): time=2000, sound=False) # Start monitoring kodi events - self.kodimonitor_running = kodimonitor.KodiMonitor() + self.kodimonitor_running = kodimonitor.KodiMonitor( + player=kplayer) # Start the Websocket Client if not self.websocket_running: @@ -222,7 +222,8 @@ class Service(): # Start the Plex Companion thread if not self.plexCompanion_running: self.plexCompanion_running = True - plexCompanion = PlexCompanion.PlexCompanion() + plexCompanion = PlexCompanion.PlexCompanion( + player=kplayer) plexCompanion.start() else: if (user.currUser is None) and self.warn_auth: