3 from types import FunctionType
4 from urlparse import urlparse, parse_qs
5 from resources.lib.KodiHelper import KodiHelper
6 from resources.lib.NetflixSession import NetflixSession
7 from resources.lib.NetflixHttpSubRessourceHandler import NetflixHttpSubRessourceHandler
9 kodi_helper = KodiHelper()
11 netflix_session = NetflixSession(
12 cookie_path=kodi_helper.cookie_path,
13 data_path=kodi_helper.data_path,
14 verify_ssl=kodi_helper.get_ssl_verification_setting(),
15 log_fn=kodi_helper.log
18 # get list of methods & instance form the sub ressource handler
19 methods = [x for x, y in NetflixHttpSubRessourceHandler.__dict__.items() if type(y) == FunctionType]
20 sub_res_handler = NetflixHttpSubRessourceHandler(kodi_helper=kodi_helper, netflix_session=netflix_session)
22 class NetflixHttpRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
25 url = urlparse(self.path)
26 params = parse_qs(url.query)
27 method = params.get('method', [None])[0]
31 self.send_error(500, 'No method declared')
34 # no existing method given
35 if method not in methods:
36 self.send_error(404, 'Method "' + str(method) + '" not found. Available methods: ' + str(methods))
39 # call method & get the result
40 result = getattr(sub_res_handler, method)(params)
41 self.send_response(200)
42 self.send_header('Content-type', 'application/json')
44 self.wfile.write(json.dumps({'method': method, 'result': result}));
47 def log_message(self, format, *args):
48 """Disable the BaseHTTPServer Log"""