Prettify
This commit is contained in:
parent
1dc576965a
commit
5d79bcf1c2
1 changed files with 80 additions and 44 deletions
|
@ -38,18 +38,20 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
def do_OPTIONS(self):
|
def do_OPTIONS(self):
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header('Content-Length', '0')
|
self.send_header('Content-Length', '0')
|
||||||
self.send_header('X-Plex-Client-Identifier', self.server.settings['uuid'])
|
self.send_header('X-Plex-Client-Identifier',
|
||||||
|
self.server.settings['uuid'])
|
||||||
self.send_header('Content-Type', 'text/plain')
|
self.send_header('Content-Type', 'text/plain')
|
||||||
self.send_header('Connection', 'close')
|
self.send_header('Connection', 'close')
|
||||||
self.send_header('Access-Control-Max-Age', '1209600')
|
self.send_header('Access-Control-Max-Age', '1209600')
|
||||||
self.send_header('Access-Control-Allow-Origin', '*')
|
self.send_header('Access-Control-Allow-Origin', '*')
|
||||||
self.send_header('Access-Control-Allow-Methods',
|
self.send_header('Access-Control-Allow-Methods',
|
||||||
'POST, GET, OPTIONS, DELETE, PUT, HEAD')
|
'POST, GET, OPTIONS, DELETE, PUT, HEAD')
|
||||||
self.send_header('Access-Control-Allow-Headers',
|
self.send_header(
|
||||||
'x-plex-version, x-plex-platform-version, '
|
'Access-Control-Allow-Headers',
|
||||||
'x-plex-username, x-plex-client-identifier, '
|
'x-plex-version, x-plex-platform-version, x-plex-username, '
|
||||||
'x-plex-target-client-identifier, x-plex-device-name, '
|
'x-plex-client-identifier, x-plex-target-client-identifier, '
|
||||||
'x-plex-platform, x-plex-product, accept, x-plex-device')
|
'x-plex-device-name, x-plex-platform, x-plex-product, accept, '
|
||||||
|
'x-plex-device')
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.close()
|
self.wfile.close()
|
||||||
|
|
||||||
|
@ -85,27 +87,37 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
params[key] = paramarrays[key][0]
|
params[key] = paramarrays[key][0]
|
||||||
self.logMsg("remote request_path: %s" % request_path, 2)
|
self.logMsg("remote request_path: %s" % request_path, 2)
|
||||||
self.logMsg("params received from remote: %s" % params, 2)
|
self.logMsg("params received from remote: %s" % params, 2)
|
||||||
self.subMgr.updateCommandID(self.headers.get('X-Plex-Client-Identifier', self.client_address[0]), params.get('commandID', False))
|
self.subMgr.updateCommandID(self.headers.get(
|
||||||
|
'X-Plex-Client-Identifier',
|
||||||
|
self.client_address[0]),
|
||||||
|
params.get('commandID', False))
|
||||||
if request_path == "version":
|
if request_path == "version":
|
||||||
self.response("PlexKodiConnect Plex Companion: Running\r\nVersion: %s" % self.settings['version'])
|
self.response(
|
||||||
|
"PlexKodiConnect Plex Companion: Running\r\nVersion: %s"
|
||||||
|
% self.settings['version'])
|
||||||
elif request_path == "verify":
|
elif request_path == "verify":
|
||||||
result=self.js.jsonrpc("ping")
|
self.response("XBMC JSON connection test:\r\n" +
|
||||||
self.response("XBMC JSON connection test:\r\n"+result)
|
self.js.jsonrpc("ping"))
|
||||||
elif "resources" == request_path:
|
elif "resources" == request_path:
|
||||||
resp = getXMLHeader()
|
resp = ('%s'
|
||||||
resp += "<MediaContainer>"
|
'<MediaContainer>'
|
||||||
resp += "<Player"
|
'<Player'
|
||||||
resp += ' title="%s"' % self.settings['client_name']
|
' title="%s"'
|
||||||
resp += ' protocol="plex"'
|
' protocol="plex"'
|
||||||
resp += ' protocolVersion="1"'
|
' protocolVersion="1"'
|
||||||
resp += ' protocolCapabilities="navigation,playback,timeline"'
|
' protocolCapabilities="navigation,playback,timeline"'
|
||||||
resp += ' machineIdentifier="%s"' % self.settings['uuid']
|
' machineIdentifier="%s"'
|
||||||
resp += ' product="PlexKodiConnect"'
|
' product="PlexKodiConnect"'
|
||||||
resp += ' platform="%s"' % self.settings['platform']
|
' platform="%s"'
|
||||||
resp += ' platformVersion="%s"' % self.settings['plexbmc_version']
|
' platformVersion="%s"'
|
||||||
resp += ' deviceClass="pc"'
|
' deviceClass="pc"'
|
||||||
resp += "/>"
|
'/>'
|
||||||
resp += "</MediaContainer>"
|
'</MediaContainer>'
|
||||||
|
% (getXMLHeader(),
|
||||||
|
self.settings['client_name'],
|
||||||
|
self.settings['uuid'],
|
||||||
|
self.settings['platform'],
|
||||||
|
self.settings['plexbmc_version']))
|
||||||
self.logMsg("crafted resources response: %s" % resp, 2)
|
self.logMsg("crafted resources response: %s" % resp, 2)
|
||||||
self.response(resp, self.js.getPlexHeaders())
|
self.response(resp, self.js.getPlexHeaders())
|
||||||
elif "/subscribe" in request_path:
|
elif "/subscribe" in request_path:
|
||||||
|
@ -115,27 +127,38 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
port = params.get('port', False)
|
port = params.get('port', False)
|
||||||
uuid = self.headers.get('X-Plex-Client-Identifier', "")
|
uuid = self.headers.get('X-Plex-Client-Identifier', "")
|
||||||
commandID = params.get('commandID', 0)
|
commandID = params.get('commandID', 0)
|
||||||
self.subMgr.addSubscriber(protocol, host, port, uuid, commandID)
|
self.subMgr.addSubscriber(protocol,
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
uuid,
|
||||||
|
commandID)
|
||||||
elif "/poll" in request_path:
|
elif "/poll" in request_path:
|
||||||
if params.get('wait', False) == '1':
|
if params.get('wait', False) == '1':
|
||||||
sleep(950)
|
sleep(950)
|
||||||
commandID = params.get('commandID', 0)
|
commandID = params.get('commandID', 0)
|
||||||
self.response(re.sub(r"INSERTCOMMANDID", str(commandID), self.subMgr.msg(self.js.getPlayers())), {
|
self.response(
|
||||||
|
re.sub(r"INSERTCOMMANDID",
|
||||||
|
str(commandID),
|
||||||
|
self.subMgr.msg(self.js.getPlayers())),
|
||||||
|
{
|
||||||
'X-Plex-Client-Identifier': self.settings['uuid'],
|
'X-Plex-Client-Identifier': self.settings['uuid'],
|
||||||
'Access-Control-Expose-Headers': 'X-Plex-Client-Identifier',
|
'Access-Control-Expose-Headers':
|
||||||
|
'X-Plex-Client-Identifier',
|
||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
'Content-Type': 'text/xml'
|
'Content-Type': 'text/xml'
|
||||||
})
|
})
|
||||||
elif "/unsubscribe" in request_path:
|
elif "/unsubscribe" in request_path:
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
uuid = self.headers.get('X-Plex-Client-Identifier', False) or self.client_address[0]
|
uuid = self.headers.get('X-Plex-Client-Identifier', False) \
|
||||||
|
or self.client_address[0]
|
||||||
self.subMgr.removeSubscriber(uuid)
|
self.subMgr.removeSubscriber(uuid)
|
||||||
elif request_path == "player/playback/setParameters":
|
elif request_path == "player/playback/setParameters":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
if 'volume' in params:
|
if 'volume' in params:
|
||||||
volume = int(params['volume'])
|
volume = int(params['volume'])
|
||||||
self.logMsg("adjusting the volume to %s%%" % volume, 2)
|
self.logMsg("adjusting the volume to %s%%" % volume, 2)
|
||||||
self.js.jsonrpc("Application.SetVolume", {"volume": volume})
|
self.js.jsonrpc("Application.SetVolume",
|
||||||
|
{"volume": volume})
|
||||||
elif "/playMedia" in request_path:
|
elif "/playMedia" in request_path:
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
offset = params.get('viewOffset', params.get('offset', "0"))
|
offset = params.get('viewOffset', params.get('offset', "0"))
|
||||||
|
@ -163,11 +186,13 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
elif request_path == "player/playback/play":
|
elif request_path == "player/playback/play":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
for playerid in self.js.getPlayerIds():
|
for playerid in self.js.getPlayerIds():
|
||||||
self.js.jsonrpc("Player.PlayPause", {"playerid" : playerid, "play": True})
|
self.js.jsonrpc("Player.PlayPause",
|
||||||
|
{"playerid": playerid, "play": True})
|
||||||
elif request_path == "player/playback/pause":
|
elif request_path == "player/playback/pause":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
for playerid in self.js.getPlayerIds():
|
for playerid in self.js.getPlayerIds():
|
||||||
self.js.jsonrpc("Player.PlayPause", {"playerid" : playerid, "play": False})
|
self.js.jsonrpc("Player.PlayPause",
|
||||||
|
{"playerid": playerid, "play": False})
|
||||||
elif request_path == "player/playback/stop":
|
elif request_path == "player/playback/stop":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
for playerid in self.js.getPlayerIds():
|
for playerid in self.js.getPlayerIds():
|
||||||
|
@ -175,27 +200,38 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
elif request_path == "player/playback/seekTo":
|
elif request_path == "player/playback/seekTo":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
for playerid in self.js.getPlayerIds():
|
for playerid in self.js.getPlayerIds():
|
||||||
self.js.jsonrpc("Player.Seek", {"playerid":playerid, "value":millisToTime(params.get('offset', 0))})
|
self.js.jsonrpc("Player.Seek",
|
||||||
|
{"playerid": playerid,
|
||||||
|
"value": millisToTime(
|
||||||
|
params.get('offset', 0))})
|
||||||
self.subMgr.notify()
|
self.subMgr.notify()
|
||||||
elif request_path == "player/playback/stepForward":
|
elif request_path == "player/playback/stepForward":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
for playerid in self.js.getPlayerIds():
|
for playerid in self.js.getPlayerIds():
|
||||||
self.js.jsonrpc("Player.Seek", {"playerid":playerid, "value":"smallforward"})
|
self.js.jsonrpc("Player.Seek",
|
||||||
|
{"playerid": playerid,
|
||||||
|
"value": "smallforward"})
|
||||||
self.subMgr.notify()
|
self.subMgr.notify()
|
||||||
elif request_path == "player/playback/stepBack":
|
elif request_path == "player/playback/stepBack":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
for playerid in self.js.getPlayerIds():
|
for playerid in self.js.getPlayerIds():
|
||||||
self.js.jsonrpc("Player.Seek", {"playerid":playerid, "value":"smallbackward"})
|
self.js.jsonrpc("Player.Seek",
|
||||||
|
{"playerid": playerid,
|
||||||
|
"value": "smallbackward"})
|
||||||
self.subMgr.notify()
|
self.subMgr.notify()
|
||||||
elif request_path == "player/playback/skipNext":
|
elif request_path == "player/playback/skipNext":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
for playerid in self.js.getPlayerIds():
|
for playerid in self.js.getPlayerIds():
|
||||||
self.js.jsonrpc("Player.GoTo", {"playerid":playerid, "to":"next"})
|
self.js.jsonrpc("Player.GoTo",
|
||||||
|
{"playerid": playerid,
|
||||||
|
"to": "next"})
|
||||||
self.subMgr.notify()
|
self.subMgr.notify()
|
||||||
elif request_path == "player/playback/skipPrevious":
|
elif request_path == "player/playback/skipPrevious":
|
||||||
self.response(getOKMsg(), self.js.getPlexHeaders())
|
self.response(getOKMsg(), self.js.getPlexHeaders())
|
||||||
for playerid in self.js.getPlayerIds():
|
for playerid in self.js.getPlayerIds():
|
||||||
self.js.jsonrpc("Player.GoTo", {"playerid":playerid, "to":"previous"})
|
self.js.jsonrpc("Player.GoTo",
|
||||||
|
{"playerid": playerid,
|
||||||
|
"to": "previous"})
|
||||||
self.subMgr.notify()
|
self.subMgr.notify()
|
||||||
elif request_path == "player/playback/skipTo":
|
elif request_path == "player/playback/skipTo":
|
||||||
self.js.skipTo(params.get('key').rsplit('/', 1)[1],
|
self.js.skipTo(params.get('key').rsplit('/', 1)[1],
|
||||||
|
|
Loading…
Reference in a new issue