Improvements to Plex Companion daemon
- Still need improvements to tell the PMS and Plex Companion devices that we STOPPED playing something.
This commit is contained in:
parent
a248580f24
commit
caba11c43f
3 changed files with 21 additions and 10 deletions
|
@ -3,6 +3,7 @@ import threading
|
||||||
import traceback
|
import traceback
|
||||||
import socket
|
import socket
|
||||||
import Queue
|
import Queue
|
||||||
|
import threading
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
|
|
||||||
|
@ -164,6 +165,9 @@ class PlexCompanion(threading.Thread):
|
||||||
client.start_all()
|
client.start_all()
|
||||||
|
|
||||||
message_count = 0
|
message_count = 0
|
||||||
|
if httpd:
|
||||||
|
t = threading.Thread(target=httpd.handle_request)
|
||||||
|
|
||||||
while not threadStopped():
|
while not threadStopped():
|
||||||
# If we are not authorized, sleep
|
# If we are not authorized, sleep
|
||||||
# Otherwise, we trigger a download which leads to a
|
# Otherwise, we trigger a download which leads to a
|
||||||
|
@ -173,23 +177,27 @@ class PlexCompanion(threading.Thread):
|
||||||
break
|
break
|
||||||
xbmc.sleep(1000)
|
xbmc.sleep(1000)
|
||||||
try:
|
try:
|
||||||
|
message_count += 1
|
||||||
if httpd:
|
if httpd:
|
||||||
httpd.handle_request()
|
if not t.isAlive():
|
||||||
message_count += 1
|
t = threading.Thread(target=httpd.handle_request)
|
||||||
|
t.start()
|
||||||
|
|
||||||
if message_count > 100:
|
if message_count == 3000:
|
||||||
|
message_count = 0
|
||||||
if client.check_client_registration():
|
if client.check_client_registration():
|
||||||
log("Client is still registered", 1)
|
log("Client is still registered", 1)
|
||||||
else:
|
else:
|
||||||
log("Client is no longer registered", 1)
|
log("Client is no longer registered", 1)
|
||||||
log("Plex Companion still running on port %s"
|
log("Plex Companion still running on port %s"
|
||||||
% self.settings['myport'], 1)
|
% self.settings['myport'], 1)
|
||||||
message_count = 0
|
|
||||||
|
|
||||||
# Get and set servers
|
# Get and set servers
|
||||||
subscriptionManager.serverlist = client.getServerList()
|
if message_count % 30 == 0:
|
||||||
|
subscriptionManager.serverlist = client.getServerList()
|
||||||
subscriptionManager.notify()
|
subscriptionManager.notify()
|
||||||
|
if not httpd:
|
||||||
|
message_count = 0
|
||||||
except:
|
except:
|
||||||
log("Error in loop, continuing anyway. Traceback:", 1)
|
log("Error in loop, continuing anyway. Traceback:", 1)
|
||||||
log(traceback.format_exc(), 1)
|
log(traceback.format_exc(), 1)
|
||||||
|
@ -202,7 +210,9 @@ class PlexCompanion(threading.Thread):
|
||||||
# Got instructions, process them
|
# Got instructions, process them
|
||||||
self.processTasks(task)
|
self.processTasks(task)
|
||||||
queue.task_done()
|
queue.task_done()
|
||||||
xbmc.sleep(10)
|
# Don't sleep
|
||||||
|
continue
|
||||||
|
xbmc.sleep(20)
|
||||||
|
|
||||||
client.stop_all()
|
client.stop_all()
|
||||||
if httpd:
|
if httpd:
|
||||||
|
|
|
@ -192,15 +192,18 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
for playerid in js.getPlayerIds():
|
for playerid in js.getPlayerIds():
|
||||||
js.jsonrpc("Player.PlayPause",
|
js.jsonrpc("Player.PlayPause",
|
||||||
{"playerid": playerid, "play": True})
|
{"playerid": playerid, "play": True})
|
||||||
|
subMgr.notify()
|
||||||
elif request_path == "player/playback/pause":
|
elif request_path == "player/playback/pause":
|
||||||
self.response(getOKMsg(), js.getPlexHeaders())
|
self.response(getOKMsg(), js.getPlexHeaders())
|
||||||
for playerid in js.getPlayerIds():
|
for playerid in js.getPlayerIds():
|
||||||
js.jsonrpc("Player.PlayPause",
|
js.jsonrpc("Player.PlayPause",
|
||||||
{"playerid": playerid, "play": False})
|
{"playerid": playerid, "play": False})
|
||||||
|
subMgr.notify()
|
||||||
elif request_path == "player/playback/stop":
|
elif request_path == "player/playback/stop":
|
||||||
self.response(getOKMsg(), js.getPlexHeaders())
|
self.response(getOKMsg(), js.getPlexHeaders())
|
||||||
for playerid in js.getPlayerIds():
|
for playerid in js.getPlayerIds():
|
||||||
js.jsonrpc("Player.Stop", {"playerid": playerid})
|
js.jsonrpc("Player.Stop", {"playerid": playerid})
|
||||||
|
subMgr.notify()
|
||||||
elif request_path == "player/playback/seekTo":
|
elif request_path == "player/playback/seekTo":
|
||||||
self.response(getOKMsg(), js.getPlexHeaders())
|
self.response(getOKMsg(), js.getPlexHeaders())
|
||||||
for playerid in js.getPlayerIds():
|
for playerid in js.getPlayerIds():
|
||||||
|
|
|
@ -150,8 +150,6 @@ class SubscriptionManager:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def notifyServer(self, players):
|
def notifyServer(self, players):
|
||||||
if not players:
|
|
||||||
return True
|
|
||||||
for p in players.values():
|
for p in players.values():
|
||||||
info = self.playerprops[p.get('playerid')]
|
info = self.playerprops[p.get('playerid')]
|
||||||
params = {'state': 'stopped'}
|
params = {'state': 'stopped'}
|
||||||
|
|
Loading…
Reference in a new issue