Revert "Use Plex Companion for Playstate Reporting"
This reverts commit f22369a14a
.
This commit is contained in:
parent
f22369a14a
commit
8b04f6175d
4 changed files with 77 additions and 72 deletions
|
@ -22,17 +22,17 @@ class PlexCompanion(threading.Thread):
|
||||||
self.client = plexgdm.plexgdm()
|
self.client = plexgdm.plexgdm()
|
||||||
self.client.clientDetails(self.settings)
|
self.client.clientDetails(self.settings)
|
||||||
self.logMsg("Registration string is: %s "
|
self.logMsg("Registration string is: %s "
|
||||||
% self.client.getClientDetails(), 2)
|
% self.client.getClientDetails(), 1)
|
||||||
|
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
httpd = False
|
|
||||||
# Cache for quicker while loops
|
# Cache for quicker while loops
|
||||||
log = self.logMsg
|
log = self.logMsg
|
||||||
client = self.client
|
client = self.client
|
||||||
threadStopped = self.threadStopped
|
threadStopped = self.threadStopped
|
||||||
threadSuspended = self.threadSuspended
|
threadSuspended = self.threadSuspended
|
||||||
|
start_count = 0
|
||||||
|
|
||||||
# Start up instances
|
# Start up instances
|
||||||
requestMgr = httppersist.RequestMgr()
|
requestMgr = httppersist.RequestMgr()
|
||||||
|
@ -40,35 +40,33 @@ class PlexCompanion(threading.Thread):
|
||||||
subscriptionManager = subscribers.SubscriptionManager(
|
subscriptionManager = subscribers.SubscriptionManager(
|
||||||
jsonClass, requestMgr)
|
jsonClass, requestMgr)
|
||||||
|
|
||||||
if utils.settings('plexCompanion') == 'true':
|
# Start up httpd
|
||||||
self.logMsg('User activated Plex Companion', 0)
|
while True:
|
||||||
# Start up httpd
|
try:
|
||||||
start_count = 0
|
httpd = listener.ThreadedHTTPServer(
|
||||||
while True:
|
client,
|
||||||
try:
|
subscriptionManager,
|
||||||
httpd = listener.ThreadedHTTPServer(
|
jsonClass,
|
||||||
client,
|
self.settings,
|
||||||
subscriptionManager,
|
('', self.settings['myport']),
|
||||||
jsonClass,
|
listener.MyHandler)
|
||||||
self.settings,
|
httpd.timeout = 0.95
|
||||||
('', self.settings['myport']),
|
break
|
||||||
listener.MyHandler)
|
except:
|
||||||
httpd.timeout = 0.95
|
log("Unable to start PlexCompanion. Traceback:", -1)
|
||||||
break
|
log(traceback.print_exc(), -1)
|
||||||
except:
|
|
||||||
log("Unable to start PlexCompanion. Traceback:", -1)
|
|
||||||
log(traceback.print_exc(), -1)
|
|
||||||
|
|
||||||
xbmc.sleep(3000)
|
xbmc.sleep(3000)
|
||||||
|
|
||||||
if start_count == 3:
|
if start_count == 3:
|
||||||
log("Error: Unable to start web helper.", -1)
|
log("Error: Unable to start web helper.", -1)
|
||||||
httpd = False
|
httpd = False
|
||||||
break
|
break
|
||||||
|
|
||||||
start_count += 1
|
start_count += 1
|
||||||
else:
|
|
||||||
self.logMsg('User deactivated Plex Companion', 0)
|
if not httpd:
|
||||||
|
return
|
||||||
|
|
||||||
client.start_all()
|
client.start_all()
|
||||||
|
|
||||||
|
@ -82,18 +80,18 @@ class PlexCompanion(threading.Thread):
|
||||||
break
|
break
|
||||||
xbmc.sleep(1000)
|
xbmc.sleep(1000)
|
||||||
try:
|
try:
|
||||||
if httpd:
|
|
||||||
httpd.handle_request()
|
|
||||||
message_count += 1
|
|
||||||
|
|
||||||
if message_count > 100:
|
httpd.handle_request()
|
||||||
if client.check_client_registration():
|
message_count += 1
|
||||||
log("Client is still registered", 1)
|
|
||||||
else:
|
if message_count > 100:
|
||||||
log("Client is no longer registered", 1)
|
if client.check_client_registration():
|
||||||
log("Plex Companion still running on port %s"
|
log("Client is still registered", 1)
|
||||||
% self.settings['myport'], 1)
|
else:
|
||||||
message_count = 0
|
log("Client is no longer registered", 1)
|
||||||
|
log("Plex Companion still running on port %s"
|
||||||
|
% self.settings['myport'], 1)
|
||||||
|
message_count = 0
|
||||||
|
|
||||||
# Get and set servers
|
# Get and set servers
|
||||||
subscriptionManager.serverlist = client.getServerList()
|
subscriptionManager.serverlist = client.getServerList()
|
||||||
|
@ -101,16 +99,15 @@ class PlexCompanion(threading.Thread):
|
||||||
subscriptionManager.notify()
|
subscriptionManager.notify()
|
||||||
xbmc.sleep(50)
|
xbmc.sleep(50)
|
||||||
except:
|
except:
|
||||||
log("Error in loop, continuing anyway. Traceback:", 1)
|
log("Error in loop, continuing anyway", 0)
|
||||||
log(traceback.format_exc(), 1)
|
log(traceback.format_exc(), 1)
|
||||||
xbmc.sleep(50)
|
xbmc.sleep(50)
|
||||||
|
|
||||||
client.stop_all()
|
client.stop_all()
|
||||||
if httpd:
|
try:
|
||||||
try:
|
httpd.socket.shutdown(socket.SHUT_RDWR)
|
||||||
httpd.socket.shutdown(socket.SHUT_RDWR)
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
finally:
|
||||||
finally:
|
httpd.socket.close()
|
||||||
httpd.socket.close()
|
|
||||||
log("----===## Plex Companion stopped ##===----", 0)
|
log("----===## Plex Companion stopped ##===----", 0)
|
||||||
|
|
|
@ -36,6 +36,14 @@ class Player(xbmc.Player):
|
||||||
|
|
||||||
self.logMsg("Starting playback monitor.", 2)
|
self.logMsg("Starting playback monitor.", 2)
|
||||||
|
|
||||||
|
# Should we start notification or is this done by Plex Companion?
|
||||||
|
self.doNotify = False if (utils.settings('plexCompanion') == 'true') \
|
||||||
|
else True
|
||||||
|
if self.doNotify:
|
||||||
|
self.logMsg("PMS notifications not done by Plex Companion", 2)
|
||||||
|
else:
|
||||||
|
self.logMsg("PMS notifications done by Plex Companion", 2)
|
||||||
|
|
||||||
def GetPlayStats(self):
|
def GetPlayStats(self):
|
||||||
return self.playStats
|
return self.playStats
|
||||||
|
|
||||||
|
@ -66,8 +74,7 @@ class Player(xbmc.Player):
|
||||||
else:
|
else:
|
||||||
count += 1
|
count += 1
|
||||||
if not currentFile:
|
if not currentFile:
|
||||||
self.logMsg('Error getting a currently playing file; abort '
|
log('Error getting a currently playing file; abort reporting', -1)
|
||||||
'reporting', -1)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Save currentFile for cleanup later and for references
|
# Save currentFile for cleanup later and for references
|
||||||
|
@ -81,13 +88,12 @@ class Player(xbmc.Player):
|
||||||
itemId = window("emby_%s.itemid" % currentFile)
|
itemId = window("emby_%s.itemid" % currentFile)
|
||||||
# try 20 times or about 10 seconds
|
# try 20 times or about 10 seconds
|
||||||
if count == 20:
|
if count == 20:
|
||||||
self.logMsg("Could not find itemId, cancelling playback "
|
log("Could not find itemId, cancelling playback report...", -1)
|
||||||
"report!", -1)
|
|
||||||
return
|
return
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
self.logMsg("ONPLAYBACK_STARTED: %s itemid: %s"
|
log("ONPLAYBACK_STARTED: %s itemid: %s"
|
||||||
% (currentFile.decode('utf-8'), itemId), 0)
|
% (currentFile.decode('utf-8'), itemId), 0)
|
||||||
|
|
||||||
embyitem = "emby_%s" % currentFile
|
embyitem = "emby_%s" % currentFile
|
||||||
runtime = window("%s.runtime" % embyitem)
|
runtime = window("%s.runtime" % embyitem)
|
||||||
|
@ -96,16 +102,16 @@ class Player(xbmc.Player):
|
||||||
itemType = window("%s.type" % embyitem)
|
itemType = window("%s.type" % embyitem)
|
||||||
window('emby_skipWatched%s' % itemId, value="true")
|
window('emby_skipWatched%s' % itemId, value="true")
|
||||||
|
|
||||||
self.logMsg("Playing itemtype is: %s" % itemType, 1)
|
log("Playing itemtype is: %s" % itemType, 1)
|
||||||
|
|
||||||
customseek = window('emby_customPlaylist.seektime')
|
customseek = window('emby_customPlaylist.seektime')
|
||||||
if (window('emby_customPlaylist') == "true" and customseek):
|
if (window('emby_customPlaylist') == "true" and customseek):
|
||||||
# Start at, when using custom playlist (play to Kodi from webclient)
|
# Start at, when using custom playlist (play to Kodi from webclient)
|
||||||
self.logMsg("Seeking to: %s" % customseek, 1)
|
log("Seeking to: %s" % customseek, 1)
|
||||||
self.xbmcplayer.seekTime(int(customseek))
|
xbmcplayer.seekTime(int(customseek))
|
||||||
window('emby_customPlaylist.seektime', clear=True)
|
window('emby_customPlaylist.seektime', clear=True)
|
||||||
|
|
||||||
seekTime = self.xbmcplayer.getTime()
|
seekTime = xbmcplayer.getTime()
|
||||||
|
|
||||||
# Get playback volume
|
# Get playback volume
|
||||||
volume_query = {
|
volume_query = {
|
||||||
|
@ -185,8 +191,7 @@ class Player(xbmc.Player):
|
||||||
|
|
||||||
if mapping: # Set in playbackutils.py
|
if mapping: # Set in playbackutils.py
|
||||||
|
|
||||||
self.logMsg("Mapping for external subtitles index: %s"
|
log("Mapping for external subtitles index: %s" % mapping, 2)
|
||||||
% mapping, 2)
|
|
||||||
externalIndex = json.loads(mapping)
|
externalIndex = json.loads(mapping)
|
||||||
|
|
||||||
if externalIndex.get(str(indexSubs)):
|
if externalIndex.get(str(indexSubs)):
|
||||||
|
@ -252,8 +257,9 @@ class Player(xbmc.Player):
|
||||||
self.playStats[playMethod] = 1'''
|
self.playStats[playMethod] = 1'''
|
||||||
|
|
||||||
def reportPlayback(self):
|
def reportPlayback(self):
|
||||||
# Done by Plex Companion
|
# Don't use if Plex Companion is enabled
|
||||||
return
|
if not self.doNotify:
|
||||||
|
return
|
||||||
|
|
||||||
self.logMsg("reportPlayback Called", 2)
|
self.logMsg("reportPlayback Called", 2)
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ from xbmc import sleep
|
||||||
|
|
||||||
import downloadutils
|
import downloadutils
|
||||||
from PlexFunctions import PMSHttpsEnabled
|
from PlexFunctions import PMSHttpsEnabled
|
||||||
from utils import window, logging, settings
|
from utils import window, logging
|
||||||
|
|
||||||
|
|
||||||
@logging
|
@logging
|
||||||
|
@ -60,7 +60,7 @@ class plexgdm:
|
||||||
self.client_registered = False
|
self.client_registered = False
|
||||||
self.download = downloadutils.DownloadUtils().downloadUrl
|
self.download = downloadutils.DownloadUtils().downloadUrl
|
||||||
|
|
||||||
def clientDetails(self, options):
|
def clientDetails(self, settings):
|
||||||
self.client_data = (
|
self.client_data = (
|
||||||
"Content-Type: plex/media-player\r\n"
|
"Content-Type: plex/media-player\r\n"
|
||||||
"Resource-Identifier: %s\r\n"
|
"Resource-Identifier: %s\r\n"
|
||||||
|
@ -74,13 +74,13 @@ class plexgdm:
|
||||||
"mirror,playqueues\r\n"
|
"mirror,playqueues\r\n"
|
||||||
"Device-Class: HTPC"
|
"Device-Class: HTPC"
|
||||||
) % (
|
) % (
|
||||||
options['uuid'],
|
settings['uuid'],
|
||||||
options['client_name'],
|
settings['client_name'],
|
||||||
options['myport'],
|
settings['myport'],
|
||||||
options['addonName'],
|
settings['addonName'],
|
||||||
options['version']
|
settings['version']
|
||||||
)
|
)
|
||||||
self.client_id = options['uuid']
|
self.client_id = settings['uuid']
|
||||||
|
|
||||||
def getClientDetails(self):
|
def getClientDetails(self):
|
||||||
if not self.client_data:
|
if not self.client_data:
|
||||||
|
@ -388,5 +388,4 @@ class plexgdm:
|
||||||
|
|
||||||
def start_all(self, daemon=False):
|
def start_all(self, daemon=False):
|
||||||
self.start_discovery(daemon)
|
self.start_discovery(daemon)
|
||||||
if settings('plexCompanion') == 'true':
|
self.start_registration(daemon)
|
||||||
self.start_registration(daemon)
|
|
||||||
|
|
|
@ -63,6 +63,8 @@ class Service():
|
||||||
window('emby_kodiProfile', value=xbmc.translatePath("special://profile"))
|
window('emby_kodiProfile', value=xbmc.translatePath("special://profile"))
|
||||||
window('emby_pluginpath', value=utils.settings('useDirectPaths'))
|
window('emby_pluginpath', value=utils.settings('useDirectPaths'))
|
||||||
|
|
||||||
|
self.runPlexCompanion = utils.settings('plexCompanion')
|
||||||
|
|
||||||
# Initial logging
|
# Initial logging
|
||||||
log("======== START %s ========" % self.addonName, 0)
|
log("======== START %s ========" % self.addonName, 0)
|
||||||
log("Platform: %s" % (self.clientInfo.getPlatform()), 0)
|
log("Platform: %s" % (self.clientInfo.getPlatform()), 0)
|
||||||
|
@ -204,7 +206,8 @@ class Service():
|
||||||
self.library_running = True
|
self.library_running = True
|
||||||
library.start()
|
library.start()
|
||||||
# Start the Plex Companion thread
|
# Start the Plex Companion thread
|
||||||
if not self.plexCompanion_running:
|
if not self.plexCompanion_running and \
|
||||||
|
self.runPlexCompanion == "true":
|
||||||
self.plexCompanion_running = True
|
self.plexCompanion_running = True
|
||||||
plexCompanion = PlexCompanion.PlexCompanion()
|
plexCompanion = PlexCompanion.PlexCompanion()
|
||||||
plexCompanion.start()
|
plexCompanion.start()
|
||||||
|
|
Loading…
Reference in a new issue