Пример #1
0
    def __init__(self, xml_file, xml_location, package_name):
        super(PackageConfiguration, self).__init__(xml_file, xml_location)
        self.providers = self.providers_class.known_providers

        self.manager = SettingsManager()
        self.providerCache = ProviderCache()

        self.package_name = package_name
        self.settings = []
        self.provider_list = None
        self.settings_list = None
    def _install_zip(self):
        install_progress = None
        # self._remove_root_directory_from_file_paths()
        meta = self._get_meta_json()
        meta = self._confirm_meta_file_contents(meta)

        author = meta["author"]
        version = meta["version"]
        pack_name = meta["name"]
        remote_meta = meta.get("remote_meta", "")
        services = "|".join(meta.get("services", []))

        if not self._install_confirmation(pack_name, author, version):
            return

        self.pre_update_collection = [
            i for i in self.get_providers() if i["package"] == pack_name
        ]
        meta_output_location = os.path.join(self.meta_path, pack_name)

        self._output_meta_file(meta_output_location)

        if not self.silent:
            install_progress = xbmcgui.DialogProgress()
            install_progress.create(
                g.ADDON_NAME,
                tools.create_multiline_message(
                    line1="{} - {}".format(pack_name,
                                           g.get_language_string(30073)),
                    line2=g.get_language_string(30074),
                ),
            )
            install_progress.update(-1)

        self._extract_package_folders(pack_name)
        self._destroy_created_temp_items()
        self._remove_legacy_meta_file(pack_name)

        if install_progress:
            install_progress.close()

        SettingsManager().create_settings(meta["name"],
                                          meta.get("settings", []))
        g.log("Refreshing provider database ")
        self.add_provider_package(pack_name, author, remote_meta, version,
                                  services)
        self._do_package_pre_config(meta["name"], meta.get("setup_extension"))

        if not self.silent:
            xbmcgui.Dialog().ok(
                g.ADDON_NAME, "{} - {}".format(g.get_language_string(30075),
                                               pack_name))
        xbmc.executebuiltin(
            'RunPlugin("plugin://plugin.video.{}/?action=refreshProviders")'.
            format(g.ADDON_NAME.lower()))

        ProvidersServiceManager().start_package_services(pack_name)
        return True
Пример #3
0
def get_setting(package_name, setting_id):
    """
    Retrieves a setting value for a provider package
    :param package_name: name of package
    :type package_name: str
    :param setting_id: ID of the setting to retrieve
    :type setting_id: str
    :return: Value of settings
    :rtype: object
    """
    return SettingsManager().get_setting(package_name, setting_id)
Пример #4
0
def set_setting(package_name, setting_id, value):
    """
    Sets the value of a setting for a provider package
    :param package_name: name of package
    :type package_name: str
    :param setting_id: ID of the setting to set
    :type setting_id: str
    :param value: New value for setting
    :rtype value: object
    :return: Value of settings
    :rtype: object
    """
    SettingsManager().set_setting(package_name, setting_id, value)
Пример #5
0
    def __init__(self):
        super(CustomProviders, self).__init__()
        self.deploy_init()
        self.providers_module = self._try_add_providers_path()
        self.pre_update_collection = []
        self.language = "en"
        self.known_packages = None
        self.known_providers = None

        self.providers_path = os.path.join(g.ADDON_USERDATA_PATH, "providers")
        self.modules_path = os.path.join(g.ADDON_USERDATA_PATH,
                                         "providerModules")
        self.meta_path = os.path.join(g.ADDON_USERDATA_PATH, "providerMeta")
        self.provider_types = ["torrent", "hosters", "adaptive"]
        with GlobalLock(self.__class__.__name__, provider_lock, True) as lock:
            if not lock.runned_once():
                self._init_providers()
        self.poll_database()
        self.provider_settings = SettingsManager()
Пример #6
0
class PackageConfiguration(BaseWindow):
    providers_class = ProviderInstallManager()

    def __init__(self, xml_file, xml_location, package_name):
        super(PackageConfiguration, self).__init__(xml_file, xml_location)
        self.providers = self.providers_class.known_providers

        self.manager = SettingsManager()
        self.providerCache = ProviderCache()

        self.package_name = package_name
        self.settings = []
        self.provider_list = None
        self.settings_list = None

    def onInit(self):
        self.settings_list = self.getControlList(1000)
        self.provider_list = self.getControlList(2000)

        self.update_settings()
        self.fill_providers()
        self.setProperty("package.name", self.package_name)
        self.setProperty("hassettings",
                         "true" if self.settings_list.size() > 0 else "false")

        self.set_default_focus(self.provider_list,
                               2999,
                               control_list_reset=True)
        super(PackageConfiguration, self).onInit()

    def refresh_data(self):
        self.providers_class.poll_database()
        self.providers = self.providers_class.known_providers
        self.update_settings()

    @staticmethod
    def _set_setting_item_properties(menu_item, setting):
        value = g.UNICODE(setting["value"])
        if setting["definition"].get("sensitive"):
            value = "*******"
        menu_item.setProperty("Label", setting["label"])
        menu_item.setProperty("value", value)

    def _populate_settings(self):
        def create_menu_item(setting):
            new_item = xbmcgui.ListItem(label="{}".format(setting["label"]))
            self._set_setting_item_properties(new_item, value)
            return new_item

        if len(self.settings) < self.settings_list.size():
            while len(self.settings) < self.settings_list.size():
                self.settings_list.removeItem(self.settings_list.size() - 1)

        for idx, value in enumerate(self.settings):
            try:
                menu_item = self.settings_list.getListItem(idx)
                self._set_setting_item_properties(menu_item, value)
            except RuntimeError:
                menu_item = create_menu_item(value)
                self.settings_list.addItem(menu_item)

    def fill_providers(self):
        self.refresh_data()
        self.provider_list.reset()

        provider_types = self.providers_class.provider_types
        for provider_type in provider_types:
            for i in [
                    provider for provider in self.providers
                    if provider["package"] == self.package_name
                    and provider["provider_type"] == provider_type
            ]:
                item = xbmcgui.ListItem(label=i["provider_name"])
                for info in i:
                    item.setProperty(info, i[info])

                self.provider_list.addItem(item)

    def update_settings(self):
        self.settings = [
            i for i in reversed(
                self.manager.get_all_visible_package_settings(
                    self.package_name))
        ]
        self._populate_settings()

    def flip_provider_status(self):
        provider_item = self.provider_list.getSelectedItem()
        new_status = self.providers_class.flip_provider_status(
            provider_item.getProperty("package"), provider_item.getLabel())

        provider_item.setProperty("status", new_status)
        self.providers = self.providerCache.get_providers()

    def flip_mutliple_providers(self, status, provider_type=None):
        g.show_busy_dialog()
        providers = [
            i for i in self.providers if i["package"] == self.package_name
        ]

        if provider_type:
            providers = [
                i for i in providers if i["provider_type"] == provider_type
            ]

        for i in providers:
            self.providers_class.flip_provider_status(i["package"],
                                                      i["provider_name"],
                                                      status)

        self.providers = self.providerCache.get_providers()
        self.fill_providers()

        self.set_default_focus(self.provider_list, 3000)
        g.close_busy_dialog()

    def handle_action(self, action, control_id=None):
        if action == 7:
            if control_id == 1000:
                position = self.settings_list.getSelectedPosition()
                self._edit_setting(self.settings[position])
            elif control_id == 2000:
                self.flip_provider_status()
            elif control_id == 2999:
                self.close()
            elif control_id in {3001, 3002, 3003, 3004, 3005, 3006}:
                options = {
                    3001: ("enabled", "hosters"),
                    3002: ("enabled", "torrent"),
                    3003: ("disabled", "hosters"),
                    3004: ("disabled", "torrent"),
                    3005: ("enabled", None),
                    3006: ("disabled", None),
                }

                option = options.get(control_id)
                self.flip_mutliple_providers(option[0],
                                             provider_type=option[1])

    def _edit_setting(self, setting):
        keyboard = xbmc.Keyboard("", setting.get("label"))
        keyboard.doModal()
        if keyboard.isConfirmed():
            try:
                self.manager.set_setting(
                    self.package_name,
                    setting["id"],
                    self.manager.settings_template[setting["type"]]["cast"](
                        keyboard.getText()),
                )
                self.update_settings()
            except TypeError:
                xbmcgui.Dialog().ok(g.ADDON_NAME,
                                    "The setting value was invalid")