def trailer(self, videoid): """Get the trailer list""" from json import dumps menu_data = { 'path': ['is_context_menu_item', 'is_context_menu_item'], # Menu item do not exists 'title': common.get_local_string(30179) } video_id_dict = videoid.to_dict() list_data, extra_data = common.make_call( 'get_video_list_supplemental', # pylint: disable=unused-variable { 'menu_data': menu_data, 'video_id_dict': video_id_dict, 'supplemental_type': SUPPLEMENTAL_TYPE_TRAILERS }) if list_data: url = common.build_url( ['supplemental'], params={ 'video_id_dict': dumps(video_id_dict), 'supplemental_type': SUPPLEMENTAL_TYPE_TRAILERS }, mode=g.MODE_DIRECTORY) common.container_update(url) else: ui.show_notification(common.get_local_string(30111))
def search_add(): """Perform actions to add and execute a new research""" # Ask to user the type of research search_types_desc = [SEARCH_TYPES_DESC.get(stype, 'Unknown') for stype in SEARCH_TYPES] type_index = ui.show_dlg_select(common.get_local_string(30401), search_types_desc) if type_index == -1: # Cancelled return False # If needed ask to user other info, then save the research to the database search_type = SEARCH_TYPES[type_index] row_id = None if search_type == 'text': search_term = ui.ask_for_search_term() if search_term and search_term.strip(): row_id = G.LOCAL_DB.insert_search_item(SEARCH_TYPES[type_index], search_term.strip()) elif search_type == 'audio_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_audio_languages()) elif search_type == 'subtitles_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_subtitles_languages()) elif search_type == 'genre_id': genre_id = ui.show_dlg_input_numeric(search_types_desc[type_index], mask_input=False) if genre_id: row_id = _search_add_bygenreid(SEARCH_TYPES[type_index], genre_id) else: raise NotImplementedError('Search type index {} not implemented'.format(type_index)) # Execute the research if row_id is None: return False # Redirect to "search" endpoint (otherwise causes problems with Container.Refresh used by context menus) end_of_directory(False) url = common.build_url(['search', 'search', row_id], mode=G.MODE_DIRECTORY) common.container_update(url, False) return True
def search_edit(row_id): """Edit a search item""" search_item = G.LOCAL_DB.get_search_item(row_id) search_type = search_item['Type'] ret = False if search_type == 'text': search_term = ui.ask_for_search_term(search_item['Value']) if search_term and search_term.strip(): G.LOCAL_DB.update_search_item_value(row_id, search_term.strip()) ret = True if not ret: return common.container_update(common.build_url(['search', 'search', row_id], mode=G.MODE_DIRECTORY))
def logout(self): """Logout of the current account and reset the session""" LOG.debug('Logging out of current account') # Perform the website logout self.get('logout') G.settings_monitor_suspend(True) # Disable and reset auto-update / auto-sync features G.ADDON.setSettingInt('lib_auto_upd_mode', 1) G.ADDON.setSettingBool('lib_sync_mylist', False) G.SHARED_DB.delete_key('sync_mylist_profile_guid') # Disable and reset the auto-select profile G.LOCAL_DB.set_value('autoselect_profile_guid', '') G.ADDON.setSetting('autoselect_profile_name', '') G.ADDON.setSettingBool('autoselect_profile_enabled', False) # Reset of selected profile guid for library playback G.LOCAL_DB.set_value('library_playback_profile_guid', '') G.ADDON.setSetting('library_playback_profile', '') G.settings_monitor_suspend(False) # Delete cookie and credentials self.session.cookies.clear() cookies.delete(self.account_hash) common.purge_credentials() # Reset the ESN obtained from website/generated G.LOCAL_DB.set_value('esn', '', TABLE_SESSION) # Reinitialize the MSL handler (delete msl data file, then reset everything) common.send_signal(signal=common.Signals.REINITIALIZE_MSL_HANDLER, data=True) G.CACHE.clear(clear_database=True) LOG.info('Logout successful') ui.show_notification(common.get_local_string(30113)) self._init_session() common.container_update('path', True) # Go to a fake page to clear screen # Open root page common.container_update(G.BASE_URL, True)
def reset_esn(self, pathitems=None): # pylint: disable=unused-argument """Reset the ESN stored (retrieved from website and manual)""" from resources.lib.database.db_utils import (TABLE_SESSION, TABLE_SETTINGS_MONITOR) if not ui.ask_for_confirmation(common.get_local_string(30217), common.get_local_string(30218)): return # Reset the ESN obtained from website/generated g.LOCAL_DB.set_value('esn', '', TABLE_SESSION) # Reset the custom ESN (manual ESN from settings) g.settings_monitor_suspend(at_first_change=True) g.ADDON.setSetting('esn', '') # Reset the custom ESN (backup of manual ESN from settings, used in settings_monitor.py) g.LOCAL_DB.set_value('custom_esn', '', TABLE_SETTINGS_MONITOR) # Perform a new login to get/generate a new ESN api.login(ask_credentials=False) # Warning after login netflix switch to the main profile! so return to the main screen # Open root page common.container_update(g.BASE_URL, True)
def search_add(): """Perform actions to add and execute a new research""" # Ask to user the type of research search_types_desc = [ SEARCH_TYPES_DESC.get(stype, 'Unknown') for stype in SEARCH_TYPES ] type_index = ui.show_dlg_select(common.get_local_string(30401), search_types_desc) if type_index == -1: # Cancelled return False # If needed ask to user other info, then save the research to the database search_type = SEARCH_TYPES[type_index] row_id = None if search_type == 'text': search_term = ui.ask_for_search_term() if search_term and search_term.strip(): row_id = G.LOCAL_DB.insert_search_item(SEARCH_TYPES[type_index], search_term.strip()) elif search_type == 'audio_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_audio_languages()) elif search_type == 'subtitles_lang': row_id = _search_add_bylang(SEARCH_TYPES[type_index], api.get_available_subtitles_languages()) elif search_type == 'genre_id': genre_id = ui.show_dlg_input_numeric(search_types_desc[type_index], mask_input=False) if genre_id: row_id = _search_add_bygenreid(SEARCH_TYPES[type_index], genre_id) else: raise NotImplementedError( 'Search type index {} not implemented'.format(type_index)) # Redirect to "search" endpoint (otherwise no results in JSON-RPC) # Rewrite path history using dir_update_listing + container_update # (otherwise will retrigger input dialog on Back or Container.Refresh) if row_id is not None and search_query(row_id, 0, False): url = common.build_url(['search', 'search', row_id], mode=G.MODE_DIRECTORY, params={'dir_update_listing': True}) common.container_update(url, False) return True return False
def reset_esn(self, pathitems=None): # pylint: disable=unused-argument """Reset the ESN stored (retrieved from website and manual)""" if not ui.ask_for_confirmation(common.get_local_string(30217), common.get_local_string(30218)): return # Generate a new ESN generated_esn = self._get_new_esn() # Reset the ESN obtained from website/generated G.LOCAL_DB.set_value('esn', '', TABLE_SESSION) # Reset the custom ESN (manual ESN from settings) G.settings_monitor_suspend(at_first_change=True) G.ADDON.setSetting('esn', '') # Reset the custom ESN (backup of manual ESN from settings, used in settings_monitor.py) G.LOCAL_DB.set_value('custom_esn', '', TABLE_SETTINGS_MONITOR) # Save the new ESN G.LOCAL_DB.set_value('esn', generated_esn, TABLE_SESSION) # Reinitialize the MSL handler (delete msl data file, then reset everything) common.send_signal(signal=common.Signals.REINITIALIZE_MSL_HANDLER, data=True) # Show login notification ui.show_notification(common.get_local_string(30109)) # Open root page common.container_update(G.BASE_URL, True)
def logout(self): """Logout of the current account and reset the session""" LOG.debug('Logging out of current account') # Perform the website logout self.get('logout') with G.SETTINGS_MONITOR.ignore_events(2): # Disable and reset auto-update / auto-sync features G.ADDON.setSettingInt('lib_auto_upd_mode', 1) G.ADDON.setSettingBool('lib_sync_mylist', False) G.SHARED_DB.delete_key('sync_mylist_profile_guid') # Disable and reset the profile guid of profile auto-selection G.LOCAL_DB.set_value('autoselect_profile_guid', '') # Disable and reset the selected profile guid for library playback G.LOCAL_DB.set_value('library_playback_profile_guid', '') # Delete cookie and credentials self.session.cookies.clear() cookies.delete() common.purge_credentials() # Reinitialize the MSL handler (delete msl data file, then reset everything) common.send_signal(common.Signals.REINITIALIZE_MSL_HANDLER, {'delete_msl_file': True}) G.CACHE.clear(clear_database=True) LOG.info('Logout successful') ui.show_notification(common.get_local_string(30113)) self._init_session() common.container_update('path', True) # Go to a fake page to clear screen # Open root page common.container_update(G.BASE_URL, True)
def _on_change(self): common.reset_log_level_global_var() common.debug( 'SettingsMonitor: settings have been changed, started checks') reboot_addon = False clean_cache = False use_mysql = g.ADDON.getSettingBool('use_mysql') use_mysql_old = g.LOCAL_DB.get_value('use_mysql', False, TABLE_SETTINGS_MONITOR) use_mysql_turned_on = use_mysql and not use_mysql_old common.debug( 'SettingsMonitor: Reinitialization of service global settings') g.init_globals(sys.argv, use_mysql != use_mysql_old) # Check the MySQL connection status after reinitialization of service global settings use_mysql_after = g.ADDON.getSettingBool('use_mysql') if use_mysql_turned_on and use_mysql_after: g.LOCAL_DB.set_value('use_mysql', True, TABLE_SETTINGS_MONITOR) ui.show_notification(g.ADDON.getLocalizedString(30202)) if not use_mysql_after and use_mysql_old: g.LOCAL_DB.set_value('use_mysql', False, TABLE_SETTINGS_MONITOR) _esn_checks() # Check menu settings changes for menu_id, menu_data in iteritems(g.MAIN_MENU_ITEMS): # Check settings changes in show/hide menu if menu_data.get('has_show_setting', True): show_menu_new_setting = bool( g.ADDON.getSettingBool('_'.join(('show_menu', menu_id)))) show_menu_old_setting = g.LOCAL_DB.get_value( 'menu_{}_show'.format(menu_id), True, TABLE_SETTINGS_MONITOR) if show_menu_new_setting != show_menu_old_setting: g.LOCAL_DB.set_value('menu_{}_show'.format(menu_id), show_menu_new_setting, TABLE_SETTINGS_MONITOR) reboot_addon = True # Check settings changes in sort order of menu if menu_data.get('has_sort_setting'): menu_sortorder_new_setting = int( g.ADDON.getSettingInt('menu_sortorder_' + menu_data['path'][1])) menu_sortorder_old_setting = g.LOCAL_DB.get_value( 'menu_{}_sortorder'.format(menu_id), 0, TABLE_SETTINGS_MONITOR) if menu_sortorder_new_setting != menu_sortorder_old_setting: g.LOCAL_DB.set_value('menu_{}_sortorder'.format(menu_id), menu_sortorder_new_setting, TABLE_SETTINGS_MONITOR) # We remove the cache to allow get the new results in the chosen order g.CACHE.clear([CACHE_COMMON, CACHE_MYLIST, CACHE_SEARCH]) # Check changes on content profiles # This is necessary because it is possible that some manifests # could be cached using the previous settings (see msl_handler - load_manifest) menu_keys = [ 'enable_dolby_sound', 'enable_vp9_profiles', 'enable_hevc_profiles', 'enable_hdr_profiles', 'enable_dolbyvision_profiles', 'enable_force_hdcp', 'disable_webvtt_subtitle' ] collect_int = '' for menu_key in menu_keys: collect_int += unicode(int(g.ADDON.getSettingBool(menu_key))) collect_int_old = g.LOCAL_DB.get_value('content_profiles_int', '', TABLE_SETTINGS_MONITOR) if collect_int != collect_int_old: g.LOCAL_DB.set_value('content_profiles_int', collect_int, TABLE_SETTINGS_MONITOR) g.CACHE.clear([CACHE_MANIFESTS]) # Check if Progress Manager settings is changed progress_manager_enabled = g.ADDON.getSettingBool( 'ProgressManager_enabled') progress_manager_enabled_old = g.LOCAL_DB.get_value( 'progress_manager_enabled', False, TABLE_SETTINGS_MONITOR) if progress_manager_enabled != progress_manager_enabled_old: g.LOCAL_DB.set_value('progress_manager_enabled', progress_manager_enabled, TABLE_SETTINGS_MONITOR) common.send_signal(signal=common.Signals.SWITCH_EVENTS_HANDLER, data=progress_manager_enabled) # Avoid perform these operations when the add-on is installed from scratch and there are no credentials if (clean_cache or reboot_addon) and not common.check_credentials(): reboot_addon = False if reboot_addon: common.debug('SettingsMonitor: addon will be rebooted') # Open root page common.container_update( common.build_url(['root'], mode=g.MODE_DIRECTORY))
def _on_change(self): # Reinitialize the log settings LOG.initialize(G.ADDON_ID, G.PLUGIN_HANDLE, G.ADDON.getSettingBool('enable_debug'), G.ADDON.getSettingBool('enable_timing')) LOG.debug( 'SettingsMonitor: settings have been changed, started checks') reboot_addon = False clean_buckets = [] use_mysql = G.ADDON.getSettingBool('use_mysql') use_mysql_old = G.LOCAL_DB.get_value('use_mysql', False, TABLE_SETTINGS_MONITOR) use_mysql_turned_on = use_mysql and not use_mysql_old # Update global settings G.IPC_OVER_HTTP = G.ADDON.getSettingBool('enable_ipc_over_http') if use_mysql != use_mysql_old: G.init_database() clean_buckets.append( CACHE_COMMON ) # Need to be cleaned to reload the Exported menu content G.CACHE_MANAGEMENT.load_ttl_values() # Verify the MySQL connection status after execute init_database() use_mysql_after = G.ADDON.getSettingBool('use_mysql') if use_mysql_turned_on and use_mysql_after: G.LOCAL_DB.set_value('use_mysql', True, TABLE_SETTINGS_MONITOR) ui.show_notification(G.ADDON.getLocalizedString(30202)) if not use_mysql_after and use_mysql_old: G.LOCAL_DB.set_value('use_mysql', False, TABLE_SETTINGS_MONITOR) # Check menu settings changes for menu_id, menu_data in G.MAIN_MENU_ITEMS.items(): # Check settings changes in show/hide menu if menu_data.get('has_show_setting', True): show_menu_new_setting = bool( G.ADDON.getSettingBool('_'.join(('show_menu', menu_id)))) show_menu_old_setting = G.LOCAL_DB.get_value( 'menu_{}_show'.format(menu_id), True, TABLE_SETTINGS_MONITOR) if show_menu_new_setting != show_menu_old_setting: G.LOCAL_DB.set_value('menu_{}_show'.format(menu_id), show_menu_new_setting, TABLE_SETTINGS_MONITOR) reboot_addon = True # Check settings changes in sort order of menu if menu_data.get('has_sort_setting'): menu_sortorder_new_setting = int( G.ADDON.getSettingInt('menu_sortorder_' + menu_data['path'][1])) menu_sortorder_old_setting = G.LOCAL_DB.get_value( 'menu_{}_sortorder'.format(menu_id), 0, TABLE_SETTINGS_MONITOR) if menu_sortorder_new_setting != menu_sortorder_old_setting: G.LOCAL_DB.set_value('menu_{}_sortorder'.format(menu_id), menu_sortorder_new_setting, TABLE_SETTINGS_MONITOR) clean_buckets += [CACHE_COMMON, CACHE_MYLIST, CACHE_SEARCH] # Checks for settings changes that require cache invalidation page_results = G.ADDON.getSettingInt('page_results') page_results_old = G.LOCAL_DB.get_value('page_results', 90, TABLE_SETTINGS_MONITOR) if page_results != page_results_old: G.LOCAL_DB.set_value('page_results', page_results, TABLE_SETTINGS_MONITOR) clean_buckets += [CACHE_COMMON, CACHE_MYLIST, CACHE_SEARCH] _check_msl_profiles(clean_buckets) _check_watched_status_sync() # Clean cache buckets if needed (to get new results and so on...) if clean_buckets: G.CACHE.clear([ dict(t) for t in {tuple(d.items()) for d in clean_buckets} ]) # Remove duplicates # Avoid perform these operations when the add-on is installed from scratch and there are no credentials if reboot_addon and not common.check_credentials(): reboot_addon = False if reboot_addon: LOG.debug('SettingsMonitor: addon will be rebooted') # Open root page common.container_update( common.build_url(['root'], mode=G.MODE_DIRECTORY))
def _on_change(self): LOG.debug('SettingsMonitor: settings have been changed, started checks') reboot_addon = False clean_cache = False use_mysql = G.ADDON.getSettingBool('use_mysql') use_mysql_old = G.LOCAL_DB.get_value('use_mysql', False, TABLE_SETTINGS_MONITOR) use_mysql_turned_on = use_mysql and not use_mysql_old LOG.debug('SettingsMonitor: Reloading global settings') G.init_globals(sys.argv, reinitialize_database=use_mysql != use_mysql_old, reload_settings=True) # Check the MySQL connection status after reinitialization of service global settings use_mysql_after = G.ADDON.getSettingBool('use_mysql') if use_mysql_turned_on and use_mysql_after: G.LOCAL_DB.set_value('use_mysql', True, TABLE_SETTINGS_MONITOR) ui.show_notification(G.ADDON.getLocalizedString(30202)) if not use_mysql_after and use_mysql_old: G.LOCAL_DB.set_value('use_mysql', False, TABLE_SETTINGS_MONITOR) _check_esn() # Check menu settings changes for menu_id, menu_data in iteritems(G.MAIN_MENU_ITEMS): # Check settings changes in show/hide menu if menu_data.get('has_show_setting', True): show_menu_new_setting = bool(G.ADDON.getSettingBool('_'.join(('show_menu', menu_id)))) show_menu_old_setting = G.LOCAL_DB.get_value('menu_{}_show'.format(menu_id), True, TABLE_SETTINGS_MONITOR) if show_menu_new_setting != show_menu_old_setting: G.LOCAL_DB.set_value('menu_{}_show'.format(menu_id), show_menu_new_setting, TABLE_SETTINGS_MONITOR) reboot_addon = True # Check settings changes in sort order of menu if menu_data.get('has_sort_setting'): menu_sortorder_new_setting = int(G.ADDON.getSettingInt('menu_sortorder_' + menu_data['path'][1])) menu_sortorder_old_setting = G.LOCAL_DB.get_value('menu_{}_sortorder'.format(menu_id), 0, TABLE_SETTINGS_MONITOR) if menu_sortorder_new_setting != menu_sortorder_old_setting: G.LOCAL_DB.set_value('menu_{}_sortorder'.format(menu_id), menu_sortorder_new_setting, TABLE_SETTINGS_MONITOR) clean_cache = True # Checks for settings changes that require cache invalidation if not clean_cache: page_results = G.ADDON.getSettingInt('page_results') page_results_old = G.LOCAL_DB.get_value('page_results', 90, TABLE_SETTINGS_MONITOR) if page_results != page_results_old: G.LOCAL_DB.set_value('page_results', page_results, TABLE_SETTINGS_MONITOR) clean_cache = True _check_msl_profiles() _check_watched_status_sync() if clean_cache: # We remove the cache to allow get the new results with the new settings G.CACHE.clear([CACHE_COMMON, CACHE_MYLIST, CACHE_SEARCH]) # Avoid perform these operations when the add-on is installed from scratch and there are no credentials if reboot_addon and not common.check_credentials(): reboot_addon = False if reboot_addon: LOG.debug('SettingsMonitor: addon will be rebooted') # Open root page common.container_update(common.build_url(['root'], mode=G.MODE_DIRECTORY))