2 # -*- coding: utf-8 -*-
3 # Module: NetflixHttpRequestHandler
4 # Created on: 07.03.2017
8 from types import FunctionType
9 from urlparse import urlparse, parse_qs
10 from resources.lib.KodiHelper import KodiHelper
11 from resources.lib.NetflixSession import NetflixSession
12 from resources.lib.NetflixHttpSubRessourceHandler import NetflixHttpSubRessourceHandler
14 kodi_helper = KodiHelper()
16 netflix_session = NetflixSession(
17 cookie_path=kodi_helper.cookie_path,
18 data_path=kodi_helper.data_path,
19 verify_ssl=kodi_helper.get_ssl_verification_setting(),
20 log_fn=kodi_helper.log
23 # get list of methods & instance form the sub ressource handler
24 methods = [x for x, y in NetflixHttpSubRessourceHandler.__dict__.items() if type(y) == FunctionType]
25 sub_res_handler = NetflixHttpSubRessourceHandler(kodi_helper=kodi_helper, netflix_session=netflix_session)
27 class NetflixHttpRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
28 """ Represents the callable internal server that dispatches requests to Netflix"""
31 """GET request handler (we only need this, as we only do GET requests internally)"""
32 url = urlparse(self.path)
33 params = parse_qs(url.query)
34 method = params.get('method', [None])[0]
38 self.send_error(500, 'No method declared')
41 # no existing method given
42 if method not in methods:
43 self.send_error(404, 'Method "' + str(method) + '" not found. Available methods: ' + str(methods))
46 # call method & get the result
47 result = getattr(sub_res_handler, method)(params)
48 self.send_response(200)
49 self.send_header('Content-type', 'application/json')
51 self.wfile.write(json.dumps({'method': method, 'result': result}));
54 def log_message(self, format, *args):
55 """Disable the BaseHTTPServer Log"""