def parse_profiles(data): """Parse profile information from Netflix response""" profiles_list = jgraph_get_list('profilesList', data) try: if not profiles_list: raise InvalidProfilesError('It has not been possible to obtain the list of profiles.') sort_order = 0 current_guids = [] for index, profile_data in iteritems(profiles_list): # pylint: disable=unused-variable summary = jgraph_get('summary', profile_data) guid = summary['guid'] current_guids.append(guid) LOG.debug('Parsing profile {}', summary['guid']) avatar_url = _get_avatar(profile_data, data, guid) is_active = summary.pop('isActive') G.LOCAL_DB.set_profile(guid, is_active, sort_order) G.SHARED_DB.set_profile(guid, sort_order) # Add profile language description translated from locale summary['language_desc'] = G.py2_decode(xbmc.convertLanguage(summary['language'][:2], xbmc.ENGLISH_NAME)) if LOG.level == LOG.LEVEL_VERBOSE: for key, value in iteritems(summary): if key in PROFILE_DEBUG_INFO: LOG.debug('Profile info {}', {key: value}) # Translate the profile name, is coded as HTML summary['profileName'] = parse_html(summary['profileName']) summary['avatar'] = avatar_url G.LOCAL_DB.insert_profile_configs(summary, guid) sort_order += 1 _delete_non_existing_profiles(current_guids) except Exception as exc: # pylint: disable=broad-except import traceback LOG.error(G.py2_decode(traceback.format_exc(), 'latin-1')) LOG.error('Profile list data: {}', profiles_list) raise_from(InvalidProfilesError, exc)
def activate_profile(self, guid): """Set the profile identified by guid as active""" LOG.debug('Switching to profile {}', guid) current_active_guid = G.LOCAL_DB.get_active_profile_guid() if guid == current_active_guid: LOG.info('The profile guid {} is already set, activation not needed.', guid) return if xbmc.Player().isPlayingVideo(): # Change the current profile while a video is playing can cause problems with outgoing HTTP requests # (MSL/NFSession) causing a failure in the HTTP request or sending data on the wrong profile raise Warning('It is not possible select a profile while a video is playing.') timestamp = time.time() LOG.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 as exc: # Profile guid not more valid raise InvalidProfilesError('Unable to access to the selected profile.') from exc # 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.session.cookies)
def activate_profile(self, guid): """Set the profile identified by guid as active""" LOG.debug('Switching to profile {}', guid) current_active_guid = G.LOCAL_DB.get_active_profile_guid() if guid == current_active_guid: LOG.info( 'The profile guid {} is already set, activation not needed.', guid) return timestamp = time.time() LOG.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 as exc: # Profile guid not more valid raise_from( InvalidProfilesError( 'Unable to access to the selected profile.'), exc) # 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.session.cookies)