diff --git a/resources/lib/plexbmchelper/listener.py b/resources/lib/plexbmchelper/listener.py index f92069fe..4621e0dc 100644 --- a/resources/lib/plexbmchelper/listener.py +++ b/resources/lib/plexbmchelper/listener.py @@ -27,118 +27,120 @@ class MyHandler(BaseHTTPRequestHandler): return server return {} - def do_HEAD(s): - s.logMsg("Serving HEAD request...", 2) - s.answer_request(0) + def do_HEAD(self): + self.logMsg("Serving HEAD request...", 2) + self.answer_request(0) - def do_GET(s): - s.logMsg("Serving GET request...", 2) - s.answer_request(1) + def do_GET(self): + self.logMsg("Serving GET request...", 2) + self.answer_request(1) - def do_OPTIONS(s): - s.send_response(200) - s.send_header('Content-Length', '0') - s.send_header('X-Plex-Client-Identifier', s.server.settings['uuid']) - s.send_header('Content-Type', 'text/plain') - s.send_header('Connection', 'close') - s.send_header('Access-Control-Max-Age', '1209600') - s.send_header('Access-Control-Allow-Origin', '*') - s.send_header('Access-Control-Allow-Methods', + def do_OPTIONS(self): + self.send_response(200) + self.send_header('Content-Length', '0') + self.send_header('X-Plex-Client-Identifier', self.server.settings['uuid']) + self.send_header('Content-Type', 'text/plain') + self.send_header('Connection', 'close') + self.send_header('Access-Control-Max-Age', '1209600') + self.send_header('Access-Control-Allow-Origin', '*') + self.send_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT, HEAD') - s.send_header('Access-Control-Allow-Headers', + self.send_header('Access-Control-Allow-Headers', 'x-plex-version, x-plex-platform-version, ' 'x-plex-username, x-plex-client-identifier, ' 'x-plex-target-client-identifier, x-plex-device-name, ' 'x-plex-platform, x-plex-product, accept, x-plex-device') - s.end_headers() - s.wfile.close() + self.end_headers() + self.wfile.close() - def response(s, body, headers={}, code=200): + def sendOK(self): + self.send_response(200) + + def response(self, body, headers={}, code=200): try: - s.send_response(code) + self.send_response(code) for key in headers: - s.send_header(key, headers[key]) - s.send_header('Content-Length', len(body)) - s.send_header('Connection', "close") - s.end_headers() - s.wfile.write(body) - s.wfile.close() + self.send_header(key, headers[key]) + self.send_header('Content-Length', len(body)) + self.send_header('Connection', "close") + self.end_headers() + self.wfile.write(body) + self.wfile.close() except: pass - def answer_request(s, sendData): - s.serverlist = s.server.client.getServerList() - s.subMgr = s.server.subscriptionManager - s.js = s.server.jsonClass - s.settings = s.server.settings + def answer_request(self, sendData): + self.serverlist = self.server.client.getServerList() + self.subMgr = self.server.subscriptionManager + self.js = self.server.jsonClass + self.settings = self.server.settings try: - request_path = s.path[1:] + request_path = self.path[1:] request_path = re.sub(r"\?.*", "", request_path) - url = urlparse(s.path) + url = urlparse(self.path) paramarrays = parse_qs(url.query) params = {} for key in paramarrays: params[key] = paramarrays[key][0] - s.logMsg("request path is: [%s]" % (request_path,), 2) - s.logMsg("params are: %s" % params, 2) - s.subMgr.updateCommandID(s.headers.get('X-Plex-Client-Identifier', s.client_address[0]), params.get('commandID', False)) + 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)) if request_path=="version": - s.response("PleXBMC Helper Remote Redirector: Running\r\nVersion: %s" % s.settings['version']) + self.response("PleXBMC Helper Remote Redirector: Running\r\nVersion: %s" % self.settings['version']) elif request_path=="verify": - result=s.js.jsonrpc("ping") - s.response("XBMC JSON connection test:\r\n"+result) + result=self.js.jsonrpc("ping") + self.response("XBMC JSON connection test:\r\n"+result) elif "resources" == request_path: resp = getXMLHeader() resp += "" resp += "