def session_data(self, new_session_data): self._session_data = new_session_data self.session.headers.update( {'x-netflix.request.client.user.guid': new_session_data['active_profile']}) cookies.save(self.account_hash, self.session.cookies) _update_esn(self.session_data['esn'])
def update_session_data(self, old_esn=g.get_esn()): self.session.headers.update({ 'x-netflix.request.client.user.guid': g.LOCAL_DB.get_active_profile_guid() }) cookies.save(self.account_hash, self.session.cookies) _update_esn(old_esn)
def _activate_profile(self, guid): """Set the profile identified by guid as active""" common.debug('Switching to profile {}', guid) current_active_guid = g.LOCAL_DB.get_active_profile_guid() if self.is_profile_session_active and guid == current_active_guid: common.info( 'The profile session of guid {} is still active, activation not needed.', guid) return import time timestamp = time.time() common.info('Activating profile {}', guid) # 20/05/2020 - The method 1 not more working for switching PIN locked profiles # INIT Method 1 - HTTP mode # response = self._get('switch_profile', params={'tkn': guid}) # self.auth_url = self.website_extract_session_data(response)['auth_url'] # END Method 1 # INIT Method 2 - API mode self._get(endpoint='activate_profile', params={ 'switchProfileGuid': guid, '_': int(timestamp * 1000), 'authURL': self.auth_url }) # Retrieve browse page to update authURL response = self._get('browse') self.auth_url = website.extract_session_data(response)['auth_url'] # END Method 2 self.is_profile_session_active = True g.LOCAL_DB.switch_active_profile(guid) g.CACHE_MANAGEMENT.identifier_prefix = guid cookies.save(self.account_hash, self.session.cookies)
def _activate_profile(self, guid): """Set the profile identified by guid as active""" common.debug('Switching to profile {}', guid) current_active_guid = g.LOCAL_DB.get_active_profile_guid() if self.is_profile_session_active and guid == current_active_guid: common.info( 'The profile session of guid {} is still active, activation not needed.', guid) import time timestamp = time.time() common.info('Activating profile {}', guid) # 20/05/2020 - The method 1 not more working for switching PIN locked profiles # INIT Method 1 - HTTP mode # response = self._get('switch_profile', params={'tkn': guid}) # self.auth_url = self.website_extract_session_data(response)['auth_url'] # END Method 1 # INIT Method 2 - API mode self._get(endpoint='activate_profile', params={ 'switchProfileGuid': guid, '_': int(timestamp * 1000), 'authURL': self.auth_url }) # Retrieve browse page to update authURL response = self._get('browse') self.auth_url = website.extract_session_data(response)['auth_url'] # END Method 2 self.is_profile_session_active = True # Update the session profile cookie (only a test, see 'Profile idle timeout' in website.py) # expires = int(timestamp) + (g.LOCAL_DB.get_value('profile_gate_idle_timer', 30, TABLE_SESSION) * 60) # self.session.cookies.set('profilesNewSession', '0', domain='.netflix.com', path='/', expires=expires) g.LOCAL_DB.switch_active_profile(guid) g.CACHE_MANAGEMENT.identifier_prefix = guid cookies.save(self.account_hash, self.session.cookies)
def try_refresh_session_data(self, raise_exception=False): """Refresh session_data from the Netflix website""" from requests import exceptions try: self.auth_url = website.extract_session_data( self._get('browse'))['auth_url'] cookies.save(self.account_hash, self.session.cookies) common.debug('Successfully refreshed session data') return True except InvalidMembershipStatusError: raise except (WebsiteParsingError, InvalidMembershipStatusAnonymous, LoginValidateErrorIncorrectPassword) as exc: import traceback common.warn( 'Failed to refresh session data, login can be expired or the password has been changed ({})', type(exc).__name__) common.debug(g.py2_decode(traceback.format_exc(), 'latin-1')) self.session.cookies.clear() if isinstance(exc, (InvalidMembershipStatusAnonymous, LoginValidateErrorIncorrectPassword)): # This prevent the MSL error: No entity association record found for the user common.send_signal(signal=common.Signals.CLEAR_USER_ID_TOKENS) return self._login() except exceptions.RequestException: import traceback common.warn( 'Failed to refresh session data, request error (RequestException)' ) common.warn(g.py2_decode(traceback.format_exc(), 'latin-1')) if raise_exception: raise except Exception: # pylint: disable=broad-except import traceback common.warn( 'Failed to refresh session data, login expired (Exception)') common.debug(g.py2_decode(traceback.format_exc(), 'latin-1')) self.session.cookies.clear() if raise_exception: raise return False
def _login(self, modal_error_message=False): """Perform account login""" try: # First we get the authentication url without logging in, required for login API call react_context = website.extract_json(self._get('login'), 'reactContext') auth_url = website.extract_api_data(react_context)['auth_url'] common.debug('Logging in...') login_response = self._post('login', data=_login_payload( common.get_credentials(), auth_url)) try: website.extract_session_data(login_response, validate=True, update_profiles=True) common.info('Login successful') ui.show_notification(common.get_local_string(30109)) cookies.save(self.account_hash, self.session.cookies) return True except (LoginValidateError, LoginValidateErrorIncorrectPassword) as exc: self.session.cookies.clear() common.purge_credentials() if not modal_error_message: raise ui.show_ok_dialog(common.get_local_string(30008), unicode(exc)) except InvalidMembershipStatusError: ui.show_error_info(common.get_local_string(30008), common.get_local_string(30180), False, True) except Exception: # pylint: disable=broad-except import traceback common.error(g.py2_decode(traceback.format_exc(), 'latin-1')) self.session.cookies.clear() raise return False
def activate_profile(self, guid): """Set the profile identified by guid as active""" common.debug('Switching to profile {}', guid) current_active_guid = G.LOCAL_DB.get_active_profile_guid() if guid == current_active_guid: common.info( 'The profile guid {} is already set, activation not needed.', guid) return timestamp = time.time() common.info('Activating profile {}', guid) # 20/05/2020 - The method 1 not more working for switching PIN locked profiles # INIT Method 1 - HTTP mode # response = self._get('switch_profile', params={'tkn': guid}) # self.nfsession.auth_url = self.website_extract_session_data(response)['auth_url'] # END Method 1 # INIT Method 2 - API mode try: self.get_safe(endpoint='activate_profile', params={ 'switchProfileGuid': guid, '_': int(timestamp * 1000), 'authURL': self.auth_url }) except HttpError401: # Profile guid not more valid raise InvalidProfilesError( 'Unable to access to the selected profile.') # Retrieve browse page to update authURL response = self.get_safe('browse') self.auth_url = website.extract_session_data(response)['auth_url'] # END Method 2 G.LOCAL_DB.switch_active_profile(guid) G.CACHE_MANAGEMENT.identifier_prefix = guid cookies.save(self.account_hash, self.session.cookies)
def update_session_data(self, old_esn=None): old_esn = old_esn or g.get_esn() self.set_session_header_data() cookies.save(self.account_hash, self.session.cookies) _update_esn(old_esn)
def update_session_data(self, old_esn=None): self.set_session_header_data() cookies.save(self.account_hash, self.session.cookies) cookies.log_cookie(self.session.cookies) _update_esn(g.get_esn() if old_esn is None else old_esn)
def update_session_data(self): self.set_session_header_data() cookies.save(self.account_hash, self.session.cookies) cookies.log_cookie(self.session.cookies)