self.base_url = base_url
self.log = log_fn
- def get_netflix_service_url (self):
- return 'http://localhost:' + str(self.kodi_helper.addon.getSetting('netflix_service_port'))
-
- def call_netflix_service (self, params):
- url_values = urllib.urlencode(params)
- url = self.get_netflix_service_url()
- full_url = url + '?' + url_values
- data = urllib2.urlopen(full_url).read()
- parsed_json = json.loads(data)
- return parsed_json.get('result', None)
-
@log
def router (self, paramstring):
"""Route to the requested subfolder & dispatch actions along the way
start_offset : :obj:`str`
Offset to resume playback from (in seconds)
"""
- # widevine esn
esn = self.call_netflix_service({'method': 'get_esn'})
return self.kodi_helper.play_item(esn=esn, video_id=video_id, start_offset=start_offset)
def show_profiles (self):
"""List the profiles for the active account"""
profiles = self.call_netflix_service({'method': 'list_profiles'})
+ if len(profiles) == 0:
+ return self.kodi_helper.show_login_failed_notification()
return self.kodi_helper.build_profiles_listing(profiles=profiles, action='video_lists', build_url=self.build_url)
@log
If we don't have an active session & the user couldn't be logged in
"""
is_logged_in = self.call_netflix_service({'method': 'is_logged_in'})
- return True if is_logged_in else self.call_netflix_service({'method': 'login'})
+ return True if is_logged_in else self.call_netflix_service({'method': 'login', 'email': account['email'], 'password': account['password']})
@log
def before_routing_action (self, params):
self.call_netflix_service({'method': 'switch_profile', 'profile_id': params['profile_id']})
# check login, in case of main menu
if 'action' not in params:
+ self.kodi_helper.log('ES Called - Zeile 428')
self.establish_session(account=credentials)
return options
if 'error' in response:
# check if we do not have a valid session, in case that happens: (re)login
if self._is_expired_session(response=response):
+ self.kodi_helper.log('ES Called - Zeile 499')
if self.establish_session(account=self.kodi_helper.get_credentials()):
return True
message = response['message'] if 'message' in response else ''
Url + querystring based on the param
"""
return self.base_url + '?' + urllib.urlencode(query)
+
+ def get_netflix_service_url (self):
+ """Returns URL & Port of the internal Netflix HTTP Proxy service
+
+ Returns
+ -------
+ str
+ Url + Port
+ """
+ return 'http://localhost:' + str(self.kodi_helper.addon.getSetting('netflix_service_port'))
+
+ def call_netflix_service (self, params):
+ """Makes a GET request to the internal Netflix HTTP proxy and returns the result
+
+ Parameters
+ ----------
+ params : :obj:`dict` of :obj:`str`
+ List of paramters to be url encoded
+
+ Returns
+ -------
+ :obj:`dict`
+ Netflix Service RPC result
+ """
+ url_values = urllib.urlencode(params)
+ url = self.get_netflix_service_url()
+ full_url = url + '?' + url_values
+ data = urllib2.urlopen(full_url).read()
+ parsed_json = json.loads(data)
+ return parsed_json.get('result', None)
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Module: NetflixHttpSubRessourceHandler
+# Created on: 07.03.2017
+
class NetflixHttpSubRessourceHandler:
def __init__ (self, kodi_helper, netflix_session):
self.kodi_helper = kodi_helper
self.netflix_session = netflix_session
- credentials = self.kodi_helper.get_credentials()
-
- if self.netflix_session.is_logged_in(account=credentials):
- self.netflix_session.refresh_session_data(account=credentials)
+ self.credentials = self.kodi_helper.get_credentials()
+
+ if self.credentials['email'] != '' and self.credentials['password'] != '':
+ if self.netflix_session.is_logged_in(account=self.credentials):
+ self.netflix_session.refresh_session_data(account=self.credentials)
+ else:
+ self.netflix_session.login(account=self.credentials)
+ self.profiles = self.netflix_session.profiles
else:
- self.netflix_session.login(account=credentials)
- self.profiles = self.netflix_session.profiles
+ self.profiles = []
def is_logged_in (self, params):
- credentials = self.kodi_helper.get_credentials()
- return self.netflix_session.is_logged_in(account=credentials)
+ if self.credentials['email'] == '' or self.credentials['password'] == '':
+ return False
+ return self.netflix_session.is_logged_in(account=self.credentials)
def logout (self, params):
+ self.profiles = []
+ self.credentials = {'email': '', 'password': ''}
return self.netflix_session.logout()
+ def login (self, params):
+ email = params.get('email', [''])[0]
+ password = params.get('password', [''])[0]
+ if email != '' and password != '':
+ self.credentials = {'email': email, 'password': password}
+ _ret = self.netflix_session.login(account=self.credentials)
+ self.profiles = self.netflix_session.profiles
+ return _ret
+ return None
+
def list_profiles (self, params):
return self.profiles
return self.netflix_session.fetch_metadata(id=video_id)
def switch_profile (self, params):
- credentials = self.kodi_helper.get_credentials()
profile_id = params.get('profile_id', [''])[0]
- return self.netflix_session.switch_profile(profile_id=profile_id, account=credentials)
+ return self.netflix_session.switch_profile(profile_id=profile_id, account=self.credentials)
def get_user_data (self, params):
return self.netflix_session.user_data