Ejemplo n.º 1
0
def Adult_Toggle(adult_list=[], disable=True, update_status=0):
    """
Remove/Enable a list of add-ons, these are put into a containment area until enabled again.

CODE: Adult_Toggle(adult_list, [disable, update_status])

AVAILABLE PARAMS:
            
    (*) adult_list  -  A list containing all the add-ons you want to be disabled.

    disable  -  By default this is set to true so any add-ons in the list sent
    through will be disabled. Set to False if you want to enable the hidden add-ons.

    update_status  - When running this function it needs to disable the
    auto-update of add-ons by Kodi otherwise it risks crashing. This
    update_status paramater is the state you want Kodi to revert back to
    once the toggle of add-ons has completed. By default this is set to 0
    which is auto-update. You can also choose 1 (notify of updates) or 2
    (disable auto updates).

~"""
    from filetools import End_Path, Move_Tree, Physical_Path

    adult_store  = Physical_Path("special://profile/addon_data/script.module.python.koding.aio/adult_store")
    disable_list = []
    if not xbmcvfs.exists(adult_store):
        xbmcvfs.mkdirs(adult_store)
    my_addons = Installed_Addons()
    if disable:
        for item in my_addons:
            if item != None:
                item = item["addonid"]
                if item in adult_list:
                    disable_list.append(item)

        Toggle_Addons(addon=disable_list, enable=False, safe_mode=True, refresh=True, update_status=update_status)
        for item in disable_list:
            try:
                addon_path = xbmcaddon.Addon(id=item).getAddonInfo("path")
            except:
                addon_path = Physical_Path(os.path.join(ADDONS,item))
            path_id = End_Path(addon_path)
            if os.path.exists(addon_path):
                Move_Tree(addon_path,os.path.join(adult_store,path_id))
    else:
        KODI_VER    = int(float(xbmc.getInfoLabel("System.BuildVersion")[:2]))
        addon_vault = []
        if os.path.exists(adult_store):
            for item in os.listdir(adult_store):
                store_dir = os.path.join(adult_store,item)
                addon_dir = os.path.join(ADDONS, item)
                if os.path.exists(store_dir):
                    Move_Tree(store_dir,addon_dir)
                    addon_vault.append(item)

        if KODI_VER >= 16:
            Toggle_Addons(addon=addon_vault, safe_mode=True, refresh=True, update_status=update_status)
        else:
            Refresh(['addons','repos'])
Ejemplo n.º 2
0
def Adult_Toggle(adult_list=[], disable=True):
    """
Remove/Enable a list of add-ons, these are put into a containment area until enabled again.

CODE: Adult_Toggle(adult_list, [disable])

AVAILABLE PARAMS:
            
    (*) adult_list  -  A list containing all the add-ons you want to be disabled.

    disable  -  By default this is set to true so any add-ons in the list sent
    through will be disabled. Set to False if you want to enable the hidden add-ons.
~"""
    from filetools import Move_Tree
    from systemtools import End_Path

    adult_store = xbmc.translatePath(
        "special://profile/addon_data/script.module.python.koding.aio/adult_store"
    )
    if not os.path.exists(adult_store):
        os.makedirs(adult_store)
    my_addons = Installed_Addons()
    if disable:
        for item in my_addons:
            if item != None:
                item = item["addonid"]
                if item in adult_list:
                    try:
                        addon_path = xbmcaddon.Addon(
                            id=item).getAddonInfo("path")
                    except:
                        addon_path = os.path.join(ADDONS, item)
                    Toggle_Addons(addon=item,
                                  enable=False,
                                  safe_mode=False,
                                  refresh=True)
                    path_id = End_Path(addon_path)
                    if os.path.exists(addon_path):
                        Move_Tree(addon_path,
                                  os.path.join(adult_store, path_id))
    else:
        KODI_VER = int(float(xbmc.getInfoLabel("System.BuildVersion")[:2]))
        addon_vault = []
        if os.path.exists(adult_store):
            for item in os.listdir(adult_store):
                store_dir = os.path.join(adult_store, item)
                addon_dir = os.path.join(ADDONS, item)
                if os.path.isdir(store_dir):
                    Move_Tree(store_dir, addon_dir)
                    addon_vault.append(item)
        if KODI_VER >= 16:
            Toggle_Addons(addon=addon_vault, safe_mode=True, refresh=True)
        else:
            Refresh(['addons', 'repos'])
Ejemplo n.º 3
0
def Toggle_Addons(addon='all', enable=True, safe_mode=True, exclude_list=[], new_only=True, refresh=True, update_status=0):
    """
Send through either a list of add-on ids or one single add-on id.
The add-ons sent through will then be added to the addons*.db
and enabled or disabled (depending on state sent through).

WARNING: If safe_mode is set to False this directly edits the
addons*.db rather than using JSON-RPC. Although directly amending
the db is a lot quicker there is no guarantee it won't cause
severe problems in later versions of Kodi (this was created for v17).
DO NOT set safe_mode to False unless you 100% understand the consequences!

CODE:  Toggle_Addons([addon, enable, safe_mode, exclude_list, new_only, refresh])

AVAILABLE PARAMS:
    (*) addon  -  This can be a list of addon ids, one single id or
    'all' to enable/disable all. If enabling all you can still use
    the exclude_list for any you want excluded from this function.
    enable  -  By default this is set to True, if you want to disable
    the add-on(s) then set this to False.
    
    safe_mode  -  By default this is set to True which means the add-ons
    are enabled/disabled via JSON-RPC which is the method recommended by
    the XBMC foundation. Setting this to False will result in a much
    quicker function BUT there is no guarantee this will work on future
    versions of Kodi and it may even cause corruption in future versions.
    Setting to False is NOT recommended and you should ONLY use this if
    you 100% understand the risks that you could break multiple setups.
    
    exclude_list  -  Send through a list of any add-on id's you do not
    want to be included in this command.
    
    new_only  -  By default this is set to True so only newly extracted
    add-on folders will be enabled/disabled. This means that any existing
    add-ons which have deliberately been disabled by the end user are
    not affected.
    
    refresh  - By default this is set to True, it will refresh the
    current container and also force a local update on your add-ons db.

    update_status  - When running this function it needs to disable the
    auto-update of add-ons by Kodi otherwise it risks crashing. This
    update_status paramater is the state you want Kodi to revert back to
    once the toggle of add-ons has completed. By default this is set to 0
    which is auto-update. You can also choose 1 (notify of updates) or 2
    (disable auto updates).

EXAMPLE CODE:
from systemtools import Refresh
xbmc.executebuiltin('ActivateWindow(Videos, addons://sources/video/)')
xbmc.sleep(2000)
dialog.ok('DISABLE YOUTUBE','We will now disable YouTube (if installed)')
koding.Toggle_Addons(addon='plugin.video.youtube', enable=False, safe_mode=True, exclude_list=[], new_only=False)
koding.Refresh('container')
xbmc.sleep(2000)
dialog.ok('ENABLE YOUTUBE','When you click OK we will enable YouTube (if installed)')
koding.Toggle_Addons(addon='plugin.video.youtube', enable=True, safe_mode=True, exclude_list=[], new_only=False)
koding.Refresh('container')
~"""
    from __init__       import dolog
    from filetools      import DB_Path_Check, Get_Contents
    from database       import DB_Query
    from systemtools    import Data_Type, Last_Error, Refresh, Set_Setting, Sleep_If_Function_Active, Timestamp

    Set_Setting('general.addonupdates', 'kodi_setting', '2')
    dolog('disabled auto updates for add-ons')
    kodi_ver        = int(float(xbmc.getInfoLabel("System.BuildVersion")[:2]))
    addons_db       = DB_Path_Check('addons')
    data_type       = Data_Type(addon)
    state           = int(bool(enable))
    enabled_list    = []
    disabled_list   = []
    if kodi_ver >= 17:
        on_system   = DB_Query(addons_db,'SELECT addonID, enabled from installed')
# Create a list of enabled and disabled add-ons already on system
        enabled_list  = Addon_List(enabled=True)
        disabled_list = Addon_List(enabled=False)

# If addon has been sent through as a string we add into a list
    if data_type == 'unicode':
        addon = addon.encode('utf8')
        data_type = Data_Type(addon)

    if data_type == 'str' and addon!= 'all':
        addon = [addon]

# Grab all the add-on ids from addons folder
    if addon == 'all':
        addon     = []
        ADDONS    = xbmc.translatePath('special://home/addons')
        my_addons = Get_Contents(path=ADDONS, exclude_list=['packages','temp'])
        for item in my_addons:
            addon_id = Get_Addon_ID(item)
            addon.append(addon_id)

# Find out what is and isn't enabled in the addons*.db
    temp_list = []
    for addon_id in addon:
        if not addon_id in exclude_list and addon_id != '':
            dolog('CHECKING: %s'%addon_id)
            if addon_id in disabled_list and not new_only and enable:
                temp_list.append(addon_id)
            elif addon_id not in disabled_list and addon_id not in enabled_list:
                temp_list.append(addon_id)
            elif addon_id in enabled_list and not enable:
                temp_list.append(addon_id)
            elif addon_id in disabled_list and enable:
                temp_list.append(addon_id)
    addon = temp_list

# If you want to bypass the JSON-RPC mode and directly modify the db (READ WARNING ABOVE!!!)
    if not safe_mode and kodi_ver >= 17:
        installedtime   = Timestamp('date_time')
        insert_query    = 'INSERT or IGNORE into installed (addonID , enabled, installDate) VALUES (?,?,?)'
        update_query    = 'UPDATE installed SET enabled = ? WHERE addonID = ? '
        insert_values   = [addon, state, installedtime]
        try:
            for item in addon:
                DB_Query(addons_db, insert_query, [item, state, installedtime])
                DB_Query(addons_db, update_query, [state, item])
        except:
            dolog(Last_Error())
        if refresh:
            Refresh()

# Using the safe_mode (JSON-RPC)
    else:
        mydeps        = []
        final_enabled = []
        if state:
            my_value      = 'true'
            log_value     = 'ENABLED'
            final_addons  = []
        else:
            my_value      = 'false'
            log_value     = 'DISABLED'
            final_addons  = addon

        for my_addon in addon:

        # If enabling the add-on then we also check for dependencies and enable them first
            if state:
                dolog('Checking dependencies for : %s'%my_addon)
                dependencies = Dependency_Check(addon_id=my_addon, recursive=True)
                mydeps.append(dependencies)

    # if enable selected we traverse through the dependencies enabling addons with lowest amount of deps to highest
        if state:
            mydeps = sorted(mydeps, key=len)
            for dep in mydeps:
                counter = 0
                for item in dep:
                    enable_dep = True
                    if counter == 0:
                        final_addons.append(item)
                        enable_dep = False
                    elif item in final_enabled:
                        enable_dep = False
                    else:
                        enable_dep = True
                    if enable_dep:
                        if not item in exclude_list and not item in final_enabled and not item in enabled_list:
                            dolog('Attempting to enable: %s'%item)
                            if Set_Setting(setting_type='addon_enable', setting=item, value = 'true'):
                                dolog('%s now %s' % (item, log_value))
                                final_enabled.append(item)
                    counter += 1

    # Now the dependencies are enabled we need to enable the actual main add-ons
        for my_addon in final_addons:
            if not my_addon in final_enabled:
                dolog('Attempting to enable: %s'%my_addon)
                if Set_Setting(setting_type='addon_enable', setting=my_addon, value = my_value):
                    dolog('%s now %s' % (my_addon, log_value))
                    final_enabled.append(addon)
            else:
                dolog('Already enabled, skipping: %s'%my_addon)
    if refresh:
        Refresh(['addons','container'])
    Set_Setting('general.addonupdates', 'kodi_setting', '%s'%update_status)
#----------------------------------------------------------------
Ejemplo n.º 4
0
def Toggle_Addons(addon='all',
                  enable=True,
                  safe_mode=True,
                  exclude_list=[],
                  new_only=True,
                  refresh=True):
    """
Send through either a list of add-on ids or one single add-on id.
The add-ons sent through will then be added to the addons*.db
and enabled or disabled (depending on state sent through).
WARNING: If safe_mode is set to False this directly edits the
addons*.db rather than using JSON-RPC. Although directly amending
the db is a lot quicker there is no guarantee it won't cause
severe problems in later versions of Kodi (this was created for v17).
DO NOT set safe_mode to False unless you 100% understand the consequences!
CODE:  Toggle_Addons([addon, enable, safe_mode, exclude_list, new_only, refresh])
AVAILABLE PARAMS:
    (*) addon  -  This can be a list of addon ids, one single id or
    'all' to enable/disable all. If enabling all you can still use
    the exclude_list for any you want excluded from this function.
    enable  -  By default this is set to True, if you want to disable
    the add-on(s) then set this to False.
    safe_mode  -  By default this is set to True which means the add-ons
    are enabled/disabled via JSON-RPC which is the method recommended by
    the XBMC foundation. Setting this to False will result in a much
    quicker function BUT there is no guarantee this will work on future
    versions of Kodi and it may even cause corruption in future versions.
    Setting to False is NOT recommended and you should ONLY use this if
    you 100% understand the risks that you could break multiple setups.
    exclude_list  -  Send through a list of any add-on id's you do not
    want to be included in this command.
    new_only  -  By default this is set to True so only newly extracted
    add-on folders will be enabled/disabled. This means that any existing
    add-ons which have deliberately been disabled by the end user are
    not affected.
    refresh  - By default this is set to True, it will refresh the
    current container and also force a local update on your add-ons db.
EXAMPLE CODE:
from systemtools import Refresh
xbmc.executebuiltin('ActivateWindow(Videos, addons://sources/video/)')
xbmc.sleep(2000)
dialog.ok('DISABLE YOUTUBE','We will now disable YouTube (if installed)')
koding.Toggle_Addons(addon='plugin.video.youtube', enable=False, safe_mode=True, exclude_list=[], new_only=False)
koding.Refresh('container')
xbmc.sleep(2000)
dialog.ok('ENABLE YOUTUBE','When you click OK we will enable YouTube (if installed)')
koding.Toggle_Addons(addon='plugin.video.youtube', enable=True, safe_mode=True, exclude_list=[], new_only=False)
koding.Refresh('container')
~"""
    from __init__ import dolog
    from filetools import DB_Path_Check, Get_Contents
    from database import DB_Query
    from systemtools import Data_Type, Last_Error, Refresh, Set_Setting, Timestamp

    kodi_ver = int(float(xbmc.getInfoLabel("System.BuildVersion")[:2]))
    addons_db = DB_Path_Check('addons')
    data_type = Data_Type(addon)
    state = int(bool(enable))
    enabled_list = []
    disabled_list = []
    if kodi_ver >= 17:
        on_system = DB_Query(addons_db,
                             'SELECT addonID, enabled from installed')
        # Create a list of enabled and disabled add-ons already on system
        enabled_list = Addon_List(enabled=True)
        disabled_list = Addon_List(enabled=False)

# If addon has been sent through as a string we add into a list
    if data_type == 'unicode':
        addon = addon.encode('utf8')
        data_type = Data_Type(addon)

    if data_type == 'str' and addon != 'all':
        addon = [addon, '']

# Grab all the add-on ids from addons folder
    if addon == 'all':
        addon = []
        ADDONS = xbmc.translatePath('special://home/addons')
        my_addons = Get_Contents(path=ADDONS,
                                 exclude_list=['packages', 'temp'])
        for item in my_addons:
            addon_id = Get_Addon_ID(item)
            addon.append(addon_id)

# Find out what is and isn't enabled in the addons*.db
    temp_list = []
    for addon_id in addon:
        if not addon_id in exclude_list and addon_id != '':
            dolog('CHECKING: %s' % addon_id)
            if addon_id in disabled_list and not new_only and enable:
                temp_list.append(addon_id)
            elif addon_id not in disabled_list and addon_id not in enabled_list:
                temp_list.append(addon_id)
            elif addon_id in enabled_list and not enable:
                temp_list.append(addon_id)
            elif addon_id in disabled_list and enable:
                temp_list.append(addon_id)
    addon = temp_list

    # If you want to bypass the JSON-RPC mode and directly modify the db (READ WARNING ABOVE!!!)
    if not safe_mode and kodi_ver >= 17:
        installedtime = Timestamp('date_time')
        insert_query = 'INSERT or IGNORE into installed (addonID , enabled, installDate) VALUES (?,?,?)'
        update_query = 'UPDATE installed SET enabled = ? WHERE addonID = ? '
        insert_values = [addon, state, installedtime]
        try:
            for item in addon:
                DB_Query(addons_db, insert_query, [item, state, installedtime])
                DB_Query(addons_db, update_query, [state, item])
        except:
            dolog(Last_Error())
        if refresh:
            Refresh()

# Using the safe_mode (JSON-RPC)
    else:
        final_enabled = []
        if state:
            my_value = 'true'
            log_value = 'ENABLED'
        else:
            my_value = 'false'
            log_value = 'DISABLED'

        for my_addon in addon:

            # If enabling the add-on then we also check for dependencies and enable them first
            if state:
                dolog('Checking dependencies for : %s' % my_addon)
                dependencies = Dependency_Check(addon_id=my_addon,
                                                recursive=True)

                # traverse through the dependencies in reverse order attempting to enable
                for item in reversed(dependencies):
                    if not item in exclude_list and not item in final_enabled and not item in enabled_list:
                        dolog('Attempting to enable: %s' % item)
                        addon_set = Set_Setting(setting_type='addon_enable',
                                                setting=item,
                                                value='true')

                        # If we've successfully enabled then we add to list so we can skip any other instances
                        if addon_set:
                            dolog('%s now %s' % (my_addon, log_value))
                            final_enabled.append(item)

# Now the dependencies are enabled we need to enable the actual main add-on
            if not my_addon in final_enabled:
                addon_set = Set_Setting(setting_type='addon_enable',
                                        setting=my_addon,
                                        value=my_value)
            try:
                if addon_set:
                    dolog('%s now %s' % (my_addon, log_value))
                    final_enabled.append(addon)
            except:
                pass
    if refresh:
        Refresh(['addons', 'container'])


# NEW CODE NOT WORKING
#     from __init__       import dolog
#     from filetools      import DB_Path_Check, Get_Contents
#     from database       import DB_Query
#     from systemtools    import Data_Type, Last_Error, Refresh, Set_Setting, Timestamp
#     from web            import Validate_Link

#     addons_db       = DB_Path_Check('addons')
#     data_type       = Data_Type(addon)
#     state           = int(bool(enable))
#     enabled_list    = []
#     disabled_list   = []
#     if kodi_ver >= 17:
#         on_system   = DB_Query(addons_db,'SELECT addonID, enabled from installed')
# # Create a list of enabled and disabled add-ons already on system
#         enabled_list  = Addon_List(enabled=True)
#         disabled_list = Addon_List(enabled=False)

# # If addon has been sent through as a string we add into a list
#     if data_type == 'unicode':
#         addon = addon.encode('utf8')
#         data_type = Data_Type(addon)

#     if data_type == 'str' and addon!= 'all':
#         addon = [addon,'']

# # Grab all the add-on ids from addons folder
#     if addon == 'all':
#         addon     = []
#         my_addons = Get_Contents(path=ADDONS, exclude_list=['packages','temp'])
#         for item in my_addons:
#             addon_id = Get_Addon_ID(item)
#             addon.append(addon_id)

# # Find out what is and isn't enabled in the addons*.db
#     temp_list = []
#     for addon_id in addon:
#         if not addon_id in exclude_list and addon_id != '':
#             dolog('CHECKING: %s'%addon_id)

# # Check ALL addons and not just newly extracted not yet in db
#             if addon_id in disabled_list and not new_only and enable:
#                 dolog('[1] Adding to temp list: %s'%addon_id)
#                 temp_list.append(addon_id)

# # Check addons not in our disabled list and also aren't in the enabled list
#             elif addon_id not in disabled_list and addon_id not in enabled_list:
#                 dolog('[2] Adding to temp list: %s'%addon_id)
#                 temp_list.append(addon_id)

# # Check addons that are already enabled, get ready to disable
#             elif addon_id in enabled_list and not enable:
#                 dolog('[3] Adding to temp list: %s'%addon_id)
#                 temp_list.append(addon_id)

# # Check addons which are disabled get ready to enable (same as first if function??)
#             elif addon_id in disabled_list and enable:
#                 dolog('[4] Adding to temp list: %s'%addon_id)
#                 temp_list.append(addon_id)
#     addon = temp_list

# # If you want to bypass the JSON-RPC mode and directly modify the db (READ WARNING ABOVE!!!)
#     if not safe_mode and kodi_ver >= 17:
#         installedtime   = Timestamp('date_time')
#         insert_query    = 'INSERT or IGNORE into installed (addonID , enabled, installDate) VALUES (?,?,?)'
#         update_query    = 'UPDATE installed SET enabled = ? WHERE addonID = ? '
#         insert_values   = [addon, state, installedtime]
#         try:
#             for item in addon:
#                 DB_Query(addons_db, insert_query, [item, state, installedtime])
#                 DB_Query(addons_db, update_query, [state, item])
#         except:
#             dolog(Last_Error())
#         if refresh:
#             Refresh()

# # Using the safe_mode (JSON-RPC)
#     else:
#         Refresh('addons')
#         xbmc.sleep(1000)
#         final_enabled = []
#         if state:
#             my_value = 'true'
#             log_value = 'ENABLED'
#         else:
#             my_value = 'false'
#             log_value = 'DISABLED'

#         for my_addon in addon:

# # If enabling the add-on then we also check for dependencies and enable them first
#             if state:
#                 dolog('Checking dependencies for : %s'%my_addon)
#                 dependencies = Dependency_Check(addon_id=my_addon, recursive=True)
#                 dolog('Dependencies: %s'%dependencies)

# # traverse through the dependencies in reverse order attempting to enable
#                 for item in reversed(dependencies):
#                     if not item in exclude_list and not item in final_enabled and not item in enabled_list:
#                         dolog('Attempting to enable: %s'%item)
#                         addon_set = Set_Setting(setting_type='addon_enable', setting=item, value = 'true')

# # If we've successfully enabled then we add to list so we can skip any other instances
#                         if addon_set:
#                             dolog('%s now %s' % (my_addon, log_value))
#                             final_enabled.append(item)

# # Now the dependencies are enabled we need to enable the actual main add-on
#         bad_repo = []
#         for my_addon in addon:
#             if not my_addon in final_enabled:
#                 ok = True
#                 addon_set = True
#                 if 'repo' in my_addon:
#                     ok = Check_Repo(my_addon)
#                     if not ok:
#                         dolog('BAD REPO: %s IS NOT RESOLVING SO WE ARE NOT INSTALLING'%my_addon)
#                         addon_set = False
#                 if addon_set:
#                     addon_set = Set_Setting(setting_type='addon_enable', setting=my_addon, value = my_value)
#                 if addon_set:
#                     dolog('%s now %s' % (my_addon, log_value))
#                     final_enabled.append(addon)
#                 else:
#                     bad_repo.append(my_addon)
#         if len(bad_repo) > 0:
#             final_list = 'The following repostitories are not resolving so have not been installed: '
#             for item in bad_repo:
#                 final_list += item+','
#             final_list = final_list[:-1]
#             dialog.ok('[COLOR=gold]BAD REPOSITORIES FOUND[/COLOR]',final_list)
#     if refresh:
#         Refresh('container')
# ----------------------------------------------------------------