Beispiel #1
0
def _check_valid_credentials():
    """Check that credentials are valid otherwise request user credentials"""
    if not check_credentials():
        try:
            from resources.lib.utils.api_requests import login
            if not login():
                # Wrong login try again
                return _check_valid_credentials()
        except MissingCredentialsError:
            # Aborted from user or left an empty field
            return False
    return True
def check_valid_credentials():
    """Check that credentials are valid otherwise request user credentials"""
    # This function check only if credentials exist, instead lazy_login
    # only works in conjunction with nfsession and also performs other checks
    if not common.check_credentials():
        try:
            if not api.login():
                # Wrong login try again
                return check_valid_credentials()
        except MissingCredentialsError:
            # Aborted from user or left an empty field
            return False
    return True
def _check_valid_credentials():
    """Check that credentials are valid otherwise request user credentials"""
    # This function check only if credentials exist, instead lazy_login
    # only works in conjunction with nfsession and also performs other checks
    if not check_credentials():
        from resources.lib.api.exceptions import MissingCredentialsError
        try:
            from resources.lib.api.api_requests import login
            if not login():
                # Wrong login try again
                return _check_valid_credentials()
        except MissingCredentialsError:
            # Aborted from user or left an empty field
            return False
    return True
 def lazy_login_wrapper(*args, **kwargs):
     from resources.lib.api.exceptions import (NotLoggedInError, MissingCredentialsError)
     try:
         return func(*args, **kwargs)
     except NotLoggedInError:
         debug('Tried to perform an action without being logged in')
         try:
             from resources.lib.api.shakti import login
             if not login(ask_credentials=not check_credentials()):
                 _handle_endofdirectory()
                 raise MissingCredentialsError
             debug('Now that we\'re logged in, let\'s try again')
             return func(*args, **kwargs)
         except MissingCredentialsError:
             # Aborted from user or left an empty field
             _handle_endofdirectory()
             raise
 def lazy_login_wrapper(*args, **kwargs):
     if _check_valid_credentials():
         try:
             return func(*args, **kwargs)
         except (NotLoggedInError, LoginValidateError):
             # Exceptions raised by nfsession: "login" / "assert_logged_in" / "website_extract_session_data"
             LOG.debug('Tried to perform an action without being logged in')
             try:
                 from resources.lib.utils.api_requests import login
                 if login(ask_credentials=not check_credentials()):
                     LOG.debug('Account logged in, try executing again {}',
                               func.__name__)
                     return func(*args, **kwargs)
             except MissingCredentialsError:
                 # Cancelled from user or left an empty field
                 pass
     return False
Beispiel #6
0
 def lazy_login_wrapper(*args, **kwargs):
     if _check_valid_credentials():
         try:
             return func(*args, **kwargs)
         except NotLoggedInError:
             # Exception raised by nfsession: "login" / "assert_logged_in" / "website_extract_session_data"
             LOG.debug('Tried to perform an action without being logged in')
             try:
                 from resources.lib.utils.api_requests import login
                 if login(ask_credentials=not check_credentials()):
                     LOG.debug('Account logged in, try executing again {}', func.__name__)
                     return func(*args, **kwargs)
             except MissingCredentialsError:
                 # Cancelled from user or left an empty field
                 pass
             except LoginError as exc:
                 # Login not valid
                 from resources.lib.kodi.ui import show_ok_dialog
                 show_ok_dialog(get_local_string(30008), str(exc))
     return False
    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))
Beispiel #8
0
 def show_esn_widevine_options(self, pathitems=None):  # pylint: disable=unused-argument
     # Deny opening of the dialog when the user is not logged
     if not common.check_credentials():
         ui.show_notification(common.get_local_string(30112))
         return
     ui.show_esn_widevine_dialog()
    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))
Beispiel #10
0
    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)

        # Check if the custom esn is changed
        custom_esn = g.ADDON.getSetting('esn')
        custom_esn_old = g.LOCAL_DB.get_value('custom_esn', '',
                                              TABLE_SETTINGS_MONITOR)
        if custom_esn != custom_esn_old:
            g.LOCAL_DB.set_value('custom_esn', custom_esn,
                                 TABLE_SETTINGS_MONITOR)
            common.send_signal(signal=common.Signals.ESN_CHANGED,
                               data=g.get_esn())

        # Check menu settings changes
        for menu_id, menu_data in iteritems(g.MAIN_MENU_ITEMS):
            # Check settings changes in show menu
            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('request_context_name'):
                menu_sortorder_new_setting = int(
                    g.ADDON.getSettingInt('_'.join(
                        ('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
                    clean_cache = True

        # 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)
            clean_cache = True

        # 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():
            clean_cache = False
            reboot_addon = False

        if clean_cache:
            common.run_plugin(
                'plugin://plugin.video.netflix/action/purge_cache/'
                '?on_disk=True&no_notification=True')

        if reboot_addon:
            common.debug('SettingsMonitor: addon will be rebooted')
            url = 'plugin://plugin.video.netflix/directory/root'
            # Open root page
            xbmc.executebuiltin(
                'Container.Update({})'.format(url))  # replace=reset history
    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))