def my_groups_menu():
    groups = manage.find_defined_groups()
    if len(groups) > 0:
        for group in groups:
            _id = uuid.uuid4()
            group_name = group['label']
            group_id = group['id']
            group_type = group['type']

            cm = [(utils.get_string(32061),
                   ('RunPlugin('
                    'plugin://plugin.program.autowidget/'
                    '?mode=manage'
                    '&action=edit'
                    '&group={})').format(group_id))]

            directory.add_menu_item(
                title=group_name,
                params={
                    'mode': 'group',
                    'group': group_id,
                    'target': group_type,
                    'id': six.text_type(_id)
                },
                info=group.get('info'),
                art=group.get('art') or
                (folder_shortcut if group_type == 'shortcut' else folder_sync),
                cm=cm,
                isFolder=True)
    else:
        directory.add_menu_item(title=32068, art=alert, isFolder=False)
    return True, utils.get_string(32007)
def next_path(group_id):
    _window = utils.get_active_window()

    if _window not in ['home', 'media'] and not label_warning_shown:
        _warn()

    group = manage.get_group_by_id(group_id)
    if not group:
        utils.log(
            '\"{}\" is missing, please repoint the widget to fix it.'.format(
                group_id),
            level=xbmc.LOGERROR)
        return False, 'AutoWidget'

    group_name = group.get('label', '')
    paths = manage.find_defined_paths(group_id)

    if len(paths) > 0:
        if _window == 'media':
            call_path(group_id, paths[0]['id'])
            return False, group_name
        else:
            directory.add_menu_item(title=32013,
                                    params={'mode': 'force'},
                                    art=unpack,
                                    info={'plot': utils.get_string(32014)},
                                    isFolder=False)
            return True, group_name
    else:
        directory.add_menu_item(title=32032, art=alert, isFolder=False)
        return False, group_name
def tools_menu():
    directory.add_menu_item(
        title=30006,
        params={"mode": "force"},
        art=utils.get_art("refresh"),
        isFolder=False,
    )
    directory.add_menu_item(
        title=30103,
        params={"mode": "clean"},
        art=utils.get_art("spray-bottle"),
        isFolder=False,
    )
    directory.add_menu_item(
        title=30043,
        params={"mode": "wipe"},
        art=utils.get_art("remove"),
        isFolder=False,
    )
    directory.add_menu_item(
        title=30101,
        params={"mode": "skindebug"},
        art=utils.get_art("bug-outline"),
        isFolder=False,
    )
    directory.add_menu_item(
        title=30117,
        params={"mode": "clear_cache"},
        art=utils.get_art("cache"),
        isFolder=False,
    )

    return True, utils.get_string(30008), None
Beispiel #4
0
def my_groups_menu():
    groups = manage.find_defined_groups()
    if len(groups) > 0:
        for group in groups:
            group_name = group['label']
            group_id = group['id']
            group_type = group['type']

            cm = [(utils.get_string(32061),
                   ('RunPlugin('
                    'plugin://plugin.program.autowidget/'
                    '?mode=manage'
                    '&action=edit'
                    '&group={})').format(group_id))]

            directory.add_menu_item(
                title=six.text_type(group_name),
                params={
                    'mode': 'group',
                    'group': group_id
                },
                info=group.get('info', {}),
                art=group.get('art')
                or (utils.get_art('folder-shortcut') if group_type
                    == 'shortcut' else utils.get_art('folder-sync')),
                cm=cm,
                isFolder=True)
    else:
        directory.add_menu_item(title=32068,
                                art=utils.get_art('alert'),
                                isFolder=False,
                                props={'specialsort': 'bottom'})

    return True, utils.get_string(32007)
def show_empty(id, props=None):
    directory.add_menu_item(
        title=settings.get_localized_string(30140).format(id),
        art=info,
        props=props,
        isFolder=False,
    )

    return True, id, None
def show_error(id, props=None):
    directory.add_menu_item(
        title=settings.get_localized_string(30139).format(id),
        art=utils.get_art("alert"),
        props=props,
        isFolder=False,
    )

    return True, id, None
def group_menu(group_id):
    _window = utils.get_active_window()
    _id = uuid.uuid4()

    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        utils.log(
            '"{}" is missing, please repoint the widget to fix it.'.format(
                group_id),
            "error",
        )
        return False, "AutoWidget", None

    group_name = group_def["label"]
    group_type = group_def["type"]
    paths = group_def["paths"]
    content = group_def.get("content")

    if len(paths) > 0:
        utils.log(
            u"Showing {} group: {}".format(group_type,
                                           six.text_type(group_name)),
            "debug",
        )
        cm = []
        art = folder_shortcut if group_type == "shortcut" else folder_sync

        for idx, path_def in enumerate(paths):
            if _window == "media":
                cm = _create_path_context_items(group_id, path_def["id"], idx,
                                                len(paths), group_type)

            directory.add_menu_item(
                title=path_def["label"],
                params={
                    "mode": "path",
                    "group": group_id,
                    "path_id": path_def["id"]
                },
                info=path_def["file"],
                art=path_def["file"].get("art", art),
                cm=cm,
                isFolder=False,
            )

        if _window != "home":
            _create_action_items(group_def, _id)
    else:
        directory.add_menu_item(
            title=30019,
            art=utils.get_art("alert"),
            isFolder=False,
            props={"specialsort": "bottom"},
        )

    return True, group_name, content
def tools_menu():
    directory.add_menu_item(title=32006,
                            params={'mode': 'force'},
                            art=refresh,
                            info={'plot': utils.get_string(32020)},
                            isFolder=False)
    directory.add_menu_item(title=32064,
                            params={'mode': 'wipe'},
                            art=remove,
                            isFolder=False)
    return True, utils.get_string(32008)
def merged_path(group_id, widget_id):
    _window = utils.get_active_window()

    group_def = manage.get_group_by_id(group_id)
    group_name = group_def.get("label", "")
    paths = group_def.get("paths", [])
    if len(paths) == 0:
        directory.add_menu_item(title=30019,
                                art=utils.get_art("alert"),
                                isFolder=False)
        return True, group_name, None

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if widget_def and _window != "dialog":
        paths = widget_def["path"]
    elif not widget_def:
        idxs = manage.choose_paths(utils.get_string(30089), paths, 5)

        if idxs is not None:
            if len(idxs) > 0:
                widget_def = manage.initialize(group_def,
                                               "merged",
                                               widget_id,
                                               keep=idxs)
                paths = widget_def["path"]

    if widget_def:
        titles = []
        for idx, path in enumerate(paths):
            # simple compatibility with pre-3.3.0 widgets
            if isinstance(path, dict):
                path = path.get("id", "")
                paths[idx] = path
                widget_def["path"] = paths
                manage.save_path_details(widget_def)

            path_def = manage.get_path_by_id(path, group_id)
            titles, cat, type = show_path(
                group_id,
                path_def["label"],
                widget_id,
                path_def,
                idx=idx,
                titles=titles,
                num=len(paths),
                merged=True,
            )

        return titles, cat, type
    else:
        directory.add_menu_item(title=30045, art=info, isFolder=True)
        return True, group_name, None
Beispiel #10
0
def merged_path(group_id, widget_id):
    _window = utils.get_active_window()

    group_def = manage.get_group_by_id(group_id)
    group_name = group_def.get("label", "")
    paths = group_def.get("paths", [])
    if len(paths) == 0:
        directory.add_menu_item(title=32032,
                                art=utils.get_art("alert"),
                                isFolder=False)
        return True, group_name

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if widget_def and _window != "dialog":
        paths = widget_def["path"]
    elif not widget_def:
        dialog = xbmcgui.Dialog()
        idxs = dialog.multiselect(
            utils.get_string(32115),
            [i["label"] for i in paths],
            preselect=list(range(len(paths))) if len(paths) <= 5 else [],
        )

        if idxs is not None:
            if len(idxs) > 0:
                widget_def = manage.initialize(group_def,
                                               "merged",
                                               widget_id,
                                               keep=idxs)
                paths = widget_def["path"]

    if widget_def:
        titles = []
        for idx, path_def in enumerate(paths):
            titles, cat = show_path(
                group_id,
                path_def["label"],
                widget_id,
                path_def["file"]["file"],
                idx=idx,
                titles=titles,
                num=len(paths),
                merged=True,
            )

        return titles, cat
    else:
        directory.add_menu_item(title=32067,
                                art=utils.get_art("information_outline"),
                                isFolder=True)
        return True, group_name
Beispiel #11
0
def tools_menu():
    directory.add_menu_item(
        title=32006,
        params={"mode": "force"},
        art=utils.get_art("refresh"),
        info={"plot": utils.get_string(32020)},
        isFolder=False,
    )
    directory.add_menu_item(
        title=32129,
        params={"mode": "clean"},
        art=utils.get_art("spray-bottle"),
        isFolder=False,
    )
    directory.add_menu_item(
        title=32064,
        params={"mode": "wipe"},
        art=utils.get_art("remove"),
        isFolder=False,
    )
    directory.add_menu_item(
        title=32127,
        params={"mode": "skindebug"},
        art=utils.get_art("bug-outline"),
        isFolder=False,
    )

    return True, utils.get_string(32008)
Beispiel #12
0
def group_menu(group_id):
    _window = utils.get_active_window()
    _id = uuid.uuid4()

    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        utils.log(
            '\"{}\" is missing, please repoint the widget to fix it.'.format(
                group_id), 'error')
        return False, 'AutoWidget'

    group_name = group_def['label']
    group_type = group_def['type']
    paths = group_def['paths']

    if len(paths) > 0:
        utils.log(
            u'Showing {} group: {}'.format(group_type,
                                           six.text_type(group_name)), 'debug')
        cm = []
        art = folder_shortcut if group_type == 'shortcut' else folder_sync

        for idx, path_def in enumerate(paths):
            if _window == 'media':
                cm = _create_context_items(group_id, path_def['id'], idx,
                                           len(paths), group_type)

            directory.add_menu_item(title=path_def['label'],
                                    params={
                                        'mode': 'path',
                                        'group': group_id,
                                        'path_id': path_def['id']
                                    },
                                    info=path_def['file'],
                                    art=path_def['file']['art'] or art,
                                    cm=cm,
                                    isFolder=False)

        if _window != 'home':
            _create_action_items(group_def, _id)
    else:
        directory.add_menu_item(title=32032,
                                art=utils.get_art('alert'),
                                isFolder=False,
                                props={'specialsort': 'bottom'})

    return True, group_name
Beispiel #13
0
def merged_path(group_id, widget_id):
    _window = utils.get_active_window()

    group_def = manage.get_group_by_id(group_id)
    group_name = group_def.get('label', '')
    paths = group_def.get('paths', [])
    if len(paths) == 0:
        directory.add_menu_item(title=32032,
                                art=utils.get_art('alert'),
                                isFolder=False)
        return True, group_name

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if widget_def and _window != 'dialog':
        paths = widget_def['path']
    elif not widget_def:
        dialog = xbmcgui.Dialog()
        idxs = dialog.multiselect(
            utils.get_string(32115), [i['label'] for i in paths],
            preselect=list(range(len(paths))) if len(paths) <= 5 else [])

        if idxs is not None:
            if len(idxs) > 0:
                widget_def = manage.initialize(group_def,
                                               'merged',
                                               widget_id,
                                               keep=idxs)
                paths = widget_def['path']

    if widget_def:
        titles = []
        for idx, path_def in enumerate(paths):
            titles, cat = show_path(group_id,
                                    path_def['label'],
                                    widget_id,
                                    path_def['file']['file'],
                                    idx=idx,
                                    num=len(paths),
                                    merged=True)

        return titles, cat
    else:
        directory.add_menu_item(title=32067,
                                art=utils.get_art('information_outline'),
                                isFolder=True)
        return True, group_name
def my_groups_menu():
    groups = manage.find_defined_groups()
    if len(groups) > 0:
        for group in groups:
            group_name = group["label"]
            group_id = group["id"]
            group_type = group["type"]

            cm = _create_group_context_items(group_id, group_type)

            directory.add_menu_item(
                title=six.text_type(group_name),
                params={
                    "mode": "group",
                    "group": group_id
                },
                info=group.get("info", {}),
                art=group.get("art")
                or (utils.get_art("folder-shortcut") if group_type
                    == "shortcut" else utils.get_art("folder-sync")),
                cm=cm,
                isFolder=True,
            )
    else:
        directory.add_menu_item(
            title=30046,
            art=utils.get_art("alert"),
            isFolder=False,
            props={"specialsort": "bottom"},
        )
    directory.add_menu_item(
        title=30011,
        params={
            "mode": "manage",
            "action": "add_group",
            "target": "shortcut"
        },
        art=utils.get_art("folder-shortcut"),
        props={"specialsort": "bottom"},
    )
    directory.add_menu_item(
        title=30010,
        params={
            "mode": "manage",
            "action": "add_group",
            "target": "widget"
        },
        art=utils.get_art("folder-sync"),
        props={"specialsort": "bottom"},
    )

    return True, utils.get_string(30007), None
Beispiel #15
0
def my_groups_menu():
    groups = manage.find_defined_groups()
    if len(groups) > 0:
        for group in groups:
            group_name = group["label"]
            group_id = group["id"]
            group_type = group["type"]

            cm = [(
                utils.get_string(32061),
                ("RunPlugin("
                 "plugin://plugin.program.autowidget/"
                 "?mode=manage"
                 "&action=edit"
                 "&group={})").format(group_id),
            )]

            directory.add_menu_item(
                title=six.text_type(group_name),
                params={
                    "mode": "group",
                    "group": group_id
                },
                info=group.get("info", {}),
                art=group.get("art")
                or (utils.get_art("folder-shortcut") if group_type
                    == "shortcut" else utils.get_art("folder-sync")),
                cm=cm,
                isFolder=True,
            )
    else:
        directory.add_menu_item(
            title=32068,
            art=utils.get_art("alert"),
            isFolder=False,
            props={"specialsort": "bottom"},
        )

    return True, utils.get_string(32007)
Beispiel #16
0
def tools_menu():
    directory.add_menu_item(title=32006,
                            params={'mode': 'force'},
                            art=utils.get_art('refresh'),
                            info={'plot': utils.get_string(32020)},
                            isFolder=False)
    directory.add_menu_item(title=32129,
                            params={'mode': 'clean'},
                            art=utils.get_art('spray-bottle'),
                            isFolder=False)
    directory.add_menu_item(title=32064,
                            params={'mode': 'wipe'},
                            art=utils.get_art('remove'),
                            isFolder=False)
    directory.add_menu_item(title=32127,
                            params={'mode': 'skindebug'},
                            art=utils.get_art('bug-outline'),
                            isFolder=False)

    return True, utils.get_string(32008)
def root_menu():
    directory.add_menu_item(title=32007,
                            params={'mode': 'group'},
                            art=folder,
                            isFolder=True)
    directory.add_menu_item(title=32074,
                            params={'mode': 'widget'},
                            art=folder,
                            isFolder=True)
    directory.add_menu_item(title=32008,
                            params={'mode': 'tools'},
                            art=tools,
                            isFolder=True)
    return True, 'AutoWidget'
Beispiel #18
0
def _create_action_items(group_def, _id):
    refresh = "$INFO[Window(10000).Property(autowidget-{}-refresh)]".format(
        _id)
    props = {"specialsort": "bottom"}

    group_id = group_def["id"]
    group_name = group_def["label"]
    group_type = group_def["type"]

    if group_type == "widget":
        directory.add_separator(title=32010, char="/", sort="bottom")
        directory.add_menu_item(
            title=utils.get_string(32076).format(six.text_type(group_name)),
            params={
                "mode": "path",
                "action": "static",
                "group": group_id,
                "id": six.text_type(_id),
                "refresh": refresh,
            },
            art=utils.get_art("folder"),
            isFolder=True,
            props=props,
        )
        directory.add_menu_item(
            title=utils.get_string(32028).format(six.text_type(group_name)),
            params={
                "mode": "path",
                "action": "cycling",
                "group": group_id,
                "id": six.text_type(_id),
                "refresh": refresh,
            },
            art=utils.get_art("shuffle"),
            isFolder=True,
            props=props,
        )
        directory.add_menu_item(
            title=utils.get_string(32089).format(six.text_type(group_name)),
            params={
                "mode": "path",
                "action": "merged",
                "group": group_id,
                "id": six.text_type(_id),
            },
            art=utils.get_art("merge"),
            isFolder=True,
            props=props,
        )
Beispiel #19
0
def _create_action_items(group_def, _id):
    refresh = '$INFO[Window(10000).Property(autowidget-{}-refresh)]'.format(
        _id)
    props = {'specialsort': 'bottom'}

    group_id = group_def['id']
    group_name = group_def['label']
    group_type = group_def['type']

    if group_type == 'widget':
        directory.add_separator(title=32010, char='/', sort='bottom')
        directory.add_menu_item(title=utils.get_string(32076).format(
            six.text_type(group_name)),
                                params={
                                    'mode': 'path',
                                    'action': 'static',
                                    'group': group_id,
                                    'id': six.text_type(_id),
                                    'refresh': refresh
                                },
                                art=utils.get_art('folder'),
                                isFolder=True,
                                props=props)
        directory.add_menu_item(title=utils.get_string(32028).format(
            six.text_type(group_name)),
                                params={
                                    'mode': 'path',
                                    'action': 'cycling',
                                    'group': group_id,
                                    'id': six.text_type(_id),
                                    'refresh': refresh
                                },
                                art=utils.get_art('shuffle'),
                                isFolder=True,
                                props=props)
        directory.add_menu_item(title=utils.get_string(32089).format(
            six.text_type(group_name)),
                                params={
                                    'mode': 'path',
                                    'action': 'merged',
                                    'group': group_id,
                                    'id': six.text_type(_id)
                                },
                                art=utils.get_art('merge'),
                                isFolder=True,
                                props=props)
Beispiel #20
0
def root_menu():
    directory.add_menu_item(
        title=30007,
        params={"mode": "group"},
        art=utils.get_art("folder"),
        isFolder=True,
    )
    directory.add_menu_item(
        title=30052,
        params={"mode": "widget"},
        art=utils.get_art("folder"),
        isFolder=True,
    )
    directory.add_menu_item(
        title=30008, params={"mode": "tools"}, art=utils.get_art("tools"), isFolder=True
    )

    return True, "AutoWidget", None
def group_menu(group_id, target, _id):
    _window = utils.get_active_window()

    group = manage.get_group_by_id(group_id)
    if not group:
        utils.log(
            '\"{}\" is missing, please repoint the widget to fix it.'.format(
                group_id),
            level=xbmc.LOGERROR)
        return False, 'AutoWidget'

    group_name = group['label']

    paths = manage.find_defined_paths(group_id)
    if len(paths) > 0:
        cm = []
        art = folder_shortcut if target == 'shortcut' else folder_sync

        for idx, path in enumerate(paths):
            if _window == 'media':
                cm = _create_context_items(group_id, path['id'], idx,
                                           len(paths))

            directory.add_menu_item(title=path['label'],
                                    params={
                                        'mode': 'path',
                                        'action': 'call',
                                        'group': group_id,
                                        'path': path['id']
                                    },
                                    info=path.get('info'),
                                    art=path.get('art') or art,
                                    cm=cm,
                                    isFolder=False)
        if target == 'widget' and _window != 'home':
            directory.add_separator(title=32010, char='/')

            directory.add_menu_item(title=utils.get_string(32028).format(
                group_name, _id),
                                    params={
                                        'mode': 'path',
                                        'action': 'random',
                                        'group': group_id,
                                        'id': six.text_type(_id)
                                    },
                                    art=folder_sync,
                                    isFolder=True)
            directory.add_menu_item(title=utils.get_string(32076).format(
                group_name, _id),
                                    params={
                                        'mode': 'path',
                                        'action': 'next',
                                        'group': group_id,
                                        'id': six.text_type(_id)
                                    },
                                    art=folder_next,
                                    isFolder=True)
    else:
        directory.add_menu_item(title=32032, art=alert, isFolder=False)

    return True, group_name
Beispiel #22
0
def show_path(group_id,
              path_label,
              widget_id,
              path,
              idx=0,
              titles=None,
              num=1,
              merged=False):
    hide_watched = utils.get_setting_bool("widgets.hide_watched")
    show_next = utils.get_setting_int("widgets.show_next")
    paged_widgets = utils.get_setting_bool("widgets.paged")
    default_color = utils.get_setting("ui.color")

    widget_def = manage.get_widget_by_id(widget_id)
    if not widget_def:
        return True, "AutoWidget"

    if not titles:
        titles = []

    files = refresh.get_files_list(path, widget_id)
    if not files:
        return titles, path_label

    utils.log("Loading items from {}".format(path), "debug")

    if isinstance(widget_def["path"], list):
        color = widget_def["path"][idx].get("color", default_color)
    elif isinstance(widget_def["path"], six.text_type):
        color = widget_def["stack"][0].get("color", default_color)
    else:
        color = widget_def["path"].get("color", default_color)

    stack = widget_def.get("stack", [])
    if stack:
        title = _previous
        # title = utils.get_string(30085).format(len(stack))
        directory.add_menu_item(
            title=title,
            params={
                "mode": "path",
                "action": "update",
                "id": widget_id,
                "path": "",
                "target": "back",
            },
            art=utils.get_art("back", color),
            isFolder=num > 1,
            props={
                "specialsort": "top",
                "autoLabel": path_label
            },
        )

    for pos, file in enumerate(files):
        properties = {"autoLabel": path_label, "autoID": widget_id}
        next_item = False
        prev_item = False

        if "customproperties" in file:
            for prop in file["customproperties"]:
                properties[prop] = file["customproperties"][prop]

        if pos == len(files) - 1:
            next_item = _is_page_item(file.get("label", ""))
        elif pos == 0:
            prev_item = _is_page_item(file.get("label", ""), next=False)

        if (prev_item and stack) or (next_item and show_next == 0):
            continue
        elif next_item and show_next > 0:
            label = _next_page
            properties["specialsort"] = "bottom"

            if num > 1:
                if show_next == 1:
                    continue

                label = "{} - {}".format(label, path_label)

            update_params = {
                "mode": "path",
                "action": "update",
                "id": widget_id,
                "path": file["file"],
                "target": "next",
            }

            directory.add_menu_item(
                title=label,
                params=update_params if paged_widgets and not merged else None,
                path=file["file"] if not paged_widgets or merged else None,
                art=utils.get_art("next_page", color),
                info=file,
                isFolder=not paged_widgets or merged,
                props=properties,
            )
        else:
            title = {
                "type": file.get("type"),
                "label": file.get("label"),
                "imdbnumber": file.get("imdbnumber"),
                "showtitle": file.get("showtitle"),
            }
            dupe = refresh.is_duplicate(title, titles)

            if (hide_watched and file.get("playcount", 0) > 0) or dupe:
                continue

            art = file.get("art", {})
            if not art.get("landscape") and art.get("thumb"):
                art["landscape"] = art["thumb"]

            directory.add_menu_item(
                title=file["label"],
                path=file["file"],
                art=art,
                info=file,
                isFolder=file["filetype"] == "directory",
                props=properties,
            )

            titles.append(title)

    return titles, path_label
def path_menu(group_id, action, widget_id):
    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        directory.add_menu_item(
            title=30051,
            info={"plot": utils.get_string(30053)},
            art=utils.get_art("alert"),
            isFolder=True,
        )
        return True, "AutoWidget", None

    group_name = group_def.get("label", "")
    paths = group_def.get("paths", [])
    if len(paths) == 0:
        directory.add_menu_item(title=30019,
                                art=utils.get_art("alert"),
                                isFolder=True)
        return True, group_name, None

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if not widget_def:
        dialog = xbmcgui.Dialog()
        if action == "static":
            idx = manage.choose_paths(utils.get_string(30088),
                                      paths,
                                      indices=True,
                                      single=True)
            if idx == -1:
                return True, "AutoWidget", None

            widget_def = manage.initialize(group_def,
                                           action,
                                           widget_id,
                                           keep=idx)
        elif action == "cycling":
            idx = dialog.select(
                utils.get_string(30059),
                [utils.get_string(30057),
                 utils.get_string(30058)],
            )
            if idx == -1:
                del dialog
                return True, "AutoWidget", None

            _action = "random" if idx == 0 else "next"

            cycle_paths = manage.choose_paths(utils.get_string(30123),
                                              paths,
                                              threshold=-1,
                                              indices=True)

            widget_def = manage.initialize(group_def,
                                           _action,
                                           widget_id,
                                           keep=cycle_paths)
        del dialog

    if widget_def:
        widget_path = widget_def.get("path", "")

        # simple compatibility with pre-3.3.0 widgets
        if isinstance(widget_path, dict):
            widget_path = widget_def.get("path", {}).get("id", "")
            widget_def["path"] = widget_path
            manage.save_path_details(widget_def)

        widget_path = manage.get_path_by_id(widget_path, group_id)

        _label = ""
        if isinstance(widget_path, dict):
            _label = widget_path.get("label", "")

        utils.log("Showing widget {}".format(widget_id), "debug")
        titles, cat, type = show_path(group_id, _label, widget_id, widget_path)
        return titles, cat, type
    else:
        directory.add_menu_item(title=30045, art=info, isFolder=True)
        return True, group_name, None
Beispiel #24
0
def show_path(group_id,
              path_label,
              widget_id,
              path,
              idx=0,
              titles=None,
              num=1,
              merged=False):
    hide_watched = utils.get_setting_bool('widgets.hide_watched')
    show_next = utils.get_setting_int('widgets.show_next')
    paged_widgets = utils.get_setting_bool('widgets.paged')
    default_color = utils.get_setting('ui.color')

    widget_def = manage.get_widget_by_id(widget_id)
    if not widget_def:
        return True, 'AutoWidget'

    if not titles:
        titles = []

    files = refresh.get_files_list(path, titles, widget_id)
    if not files:
        return titles, path_label

    utils.log('Loading items from {}'.format(path), 'debug')

    if isinstance(widget_def['path'], list):
        color = widget_def['path'][idx].get('color', default_color)
    elif isinstance(widget_def['path'], six.text_type):
        color = widget_def['stack'][0].get('color', default_color)
    else:
        color = widget_def['path'].get('color', default_color)

    stack = widget_def.get('stack', [])
    if stack:
        title = utils.get_string(32110).format(len(stack))
        directory.add_menu_item(title=title,
                                params={
                                    'mode': 'path',
                                    'action': 'update',
                                    'id': widget_id,
                                    'path': '',
                                    'target': 'back'
                                },
                                art=utils.get_art('back', color),
                                isFolder=num > 1,
                                props={
                                    'specialsort': 'top',
                                    'autoLabel': path_label
                                })

    for file in files:
        properties = {'autoLabel': path_label, 'autoID': widget_id}
        if 'customproperties' in file:
            for prop in file['customproperties']:
                properties[prop] = file['customproperties'][prop]

        clean_pattern = '[^\w \xC0-\xFF]'
        tag_pattern = '(\[[^\]]*\])'

        next_pattern = (
            '(?:^(?:next)?\s*(?:(?:>>)|(?:\.*)$)?)\s*'
            '(?:page\s*(?:(?:\d+\D*\d?$)|(?:(?:>>)|(?:\.*)$)|(?:\(\d+|.*\)$))?)?$'
        )
        prev_pattern = '^(?:previous(?: page)?)$|^(?:back)$'

        cleaned_title = re.sub(tag_pattern, '',
                               file.get('label', '').lower()).strip()
        next_item = re.search(next_pattern, cleaned_title)
        prev_item = re.search(prev_pattern, cleaned_title)

        if (prev_item and stack) or (next_item and show_next == 0):
            continue
        elif next_item and show_next > 0:
            label = utils.get_string(32111)
            properties['specialsort'] = 'bottom'

            if num > 1:
                if show_next == 1:
                    continue

                label = '{} - {}'.format(label, path_label)

            update_params = {
                'mode': 'path',
                'action': 'update',
                'id': widget_id,
                'path': file['file'],
                'target': 'next'
            }

            directory.add_menu_item(
                title=label,
                params=update_params if paged_widgets and not merged else None,
                path=file['file'] if not paged_widgets or merged else None,
                art=utils.get_art('next_page', color),
                info=file,
                isFolder=not paged_widgets or merged,
                props=properties)
        else:
            dupe = False
            title = (file['label'], file.get('imdbnumber'))
            for t in titles:
                if t == title:
                    dupe = True

            if (hide_watched and file.get('playcount', 0) > 0) or dupe:
                continue

            directory.add_menu_item(title=title[0],
                                    path=file['file'],
                                    art=file['art'],
                                    info=file,
                                    isFolder=file['filetype'] == 'directory',
                                    props=properties)

            titles.append(title)

    return titles, path_label
Beispiel #25
0
def path_menu(group_id, action, widget_id):
    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        directory.add_menu_item(title=32073,
                                info={'plot': utils.get_string(32075)},
                                art=utils.get_art('alert'),
                                isFolder=True)
        return True, 'AutoWidget'

    group_name = group_def.get('label', '')
    paths = group_def.get('paths', [])
    if len(paths) == 0:
        directory.add_menu_item(title=32032,
                                art=utils.get_art('alert'),
                                isFolder=True)
        return True, group_name

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if not widget_def:
        dialog = xbmcgui.Dialog()
        if action == 'static':
            idx = dialog.select(utils.get_string(32114),
                                [i['label'] for i in paths])
            if idx == -1:
                return True, 'AutoWidget'

            widget_def = manage.initialize(group_def,
                                           action,
                                           widget_id,
                                           keep=idx)
        elif action == 'cycling':
            idx = dialog.select(
                utils.get_string(32081),
                [utils.get_string(32079),
                 utils.get_string(32080)])
            if idx == -1:
                return True, 'AutoWidget'

            _action = 'random' if idx == 0 else 'next'
            widget_def = manage.initialize(group_def, _action, widget_id)

    if widget_def:
        widget_path = widget_def.get('path', {})

        if isinstance(widget_path, dict):
            _label = widget_path['label']
            widget_path = widget_path['file']['file']
        else:
            stack = widget_def.get('stack', [])
            if stack:
                _label = stack[0]['label']
            else:
                _label = widget_def.get('label', '')
        utils.log('Showing widget {}'.format(widget_id), 'debug')
        titles, cat = show_path(group_id, _label, widget_id, widget_path)
        return titles, cat
    else:
        directory.add_menu_item(title=32067,
                                art=utils.get_art('information_outline'),
                                isFolder=True)
        return True, group_name
def active_widgets_menu():
    widgets = manage.find_defined_widgets()

    if len(widgets) > 0:
        for widget_def in widgets:
            _id = widget_def.get('id', '')
            action = widget_def.get('action', '')
            group = widget_def.get('group', '')
            path = widget_def.get('path', '')
            updated = widget_def.get('updated', '')

            path_def = manage.get_path_by_id(path, group)
            group_def = manage.get_group_by_id(group)

            title = ''
            if path_def and group_def:
                try:
                    path_def['label'] = path_def['label'].encode('utf-8')
                    group_def['label'] = group_def['label'].encode('utf-8')
                except:
                    pass

                title = '{} - {}'.format(path_def['label'], group_def['label'])
            elif group_def:
                title = group_def.get('label')

            art = {}
            params = {}
            if not action:
                art = folder_shortcut
                params = {
                    'mode': 'group',
                    'group': group,
                    'target': 'shortcut',
                    'id': six.text_type(_id)
                }
                title = utils.get_string(32030).format(title)
            elif action in ['random', 'next']:
                art = folder_sync if action == 'random' else folder_next
                params = {
                    'mode': 'group',
                    'group': group,
                    'target': 'widget',
                    'id': six.text_type(_id)
                }

            cm = [(utils.get_string(32069),
                   ('RunPlugin('
                    'plugin://plugin.program.autowidget/'
                    '?mode=refresh'
                    '&target={})').format(_id)),
                  (utils.get_string(32070),
                   ('RunPlugin('
                    'plugin://plugin.program.autowidget/'
                    '?mode=manage'
                    '&action=edit_widget'
                    '&target={})').format(_id))]

            if not group_def:
                title = '{} - [COLOR firebrick]{}[/COLOR]'.format(
                    _id, utils.get_string(32071))

            directory.add_menu_item(title=title,
                                    art=art,
                                    params=params,
                                    cm=cm[1:] if not action else cm,
                                    isFolder=True)
    else:
        directory.add_menu_item(title=32072, art=alert, isFolder=False)

    return True, utils.get_string(32074)
Beispiel #27
0
def active_widgets_menu():
    manage.clean()
    widgets = sorted(manage.find_defined_widgets(),
                     key=lambda x: x.get('updated'),
                     reverse=True)

    if len(widgets) > 0:
        for widget_def in widgets:
            widget_id = widget_def.get('id', '')
            action = widget_def.get('action', '')
            group = widget_def.get('group', '')
            path_def = widget_def.get('path', {})

            group_def = manage.get_group_by_id(group)

            title = ''
            if path_def and group_def:
                try:
                    if action != 'merged':
                        if isinstance(path_def, dict):
                            label = path_def['label'].encode('utf-8')
                        else:
                            label = widget_def['stack'][0]['label'].encode(
                                'utf-8')
                        group_def['label'] = group_def['label'].encode('utf-8')
                    else:
                        label = utils.get_string(32128).format(len(path_def))
                except:
                    pass

                title = '{} - {}'.format(label, group_def['label'])
            elif group_def:
                title = group_def.get('label')

            art = {}
            params = {}
            cm = []
            if not action:
                art = folder_shortcut
                title = utils.get_string(32030).format(title)
            else:
                if action in ['random', 'next']:
                    art = shuffle
                    cm.append((utils.get_string(32069),
                               ('RunPlugin('
                                'plugin://plugin.program.autowidget/'
                                '?mode=refresh'
                                '&id={})').format(widget_id)))
                elif action == 'merged':
                    art = merge
                elif action == 'static':
                    art = utils.get_art('folder')

            cm.append((utils.get_string(32070),
                       ('RunPlugin('
                        'plugin://plugin.program.autowidget/'
                        '?mode=manage'
                        '&action=edit_widget'
                        '&id={})').format(widget_id)))

            if not group_def:
                title = '{} - [COLOR firebrick]{}[/COLOR]'.format(
                    widget_id, utils.get_string(32071))

            directory.add_menu_item(title=title,
                                    art=art,
                                    params={
                                        'mode': 'group',
                                        'group': group
                                    },
                                    cm=cm[1:] if not action else cm,
                                    isFolder=True)
    else:
        directory.add_menu_item(title=32072,
                                art=utils.get_art('alert'),
                                isFolder=False,
                                props={'specialsort': 'bottom'})

    return True, utils.get_string(32074)
Beispiel #28
0
def active_widgets_menu():
    widgets = sorted(manage.clean(all=True),
                     key=lambda x: x.get("updated", 0),
                     reverse=True)

    if len(widgets) > 0:
        for widget_def in widgets:
            widget_id = widget_def.get("id", "")
            action = widget_def.get("action", "")
            group = widget_def.get("group", "")
            path_def = widget_def.get("path", {})

            group_def = manage.get_group_by_id(group)

            title = ""
            if path_def and group_def:
                try:
                    if action != "merged":
                        if isinstance(path_def, dict):
                            label = path_def["label"].encode("utf-8")
                        else:
                            label = widget_def["stack"][0]["label"].encode(
                                "utf-8")
                        group_def["label"] = group_def["label"].encode("utf-8")
                    else:
                        label = utils.get_string(32128).format(len(path_def))
                except:
                    pass

                title = "{} - {}".format(six.ensure_text(label),
                                         six.ensure_text(group_def["label"]))
            elif group_def:
                title = group_def.get("label")

            art = {}
            params = {}
            cm = []
            if not action:
                art = folder_shortcut
                title = utils.get_string(32030).format(title)
            else:
                if action in ['random', 'next', 'randomized']:
                    art = shuffle
                    cm.append((
                        utils.get_string(32069),
                        ("RunPlugin("
                         "plugin://plugin.program.autowidget/"
                         "?mode=refresh"
                         "&id={})").format(widget_id),
                    ))
                elif action == "merged":
                    art = merge
                elif action == "static":
                    art = utils.get_art("folder")

            cm.append((
                utils.get_string(32070),
                ("RunPlugin("
                 "plugin://plugin.program.autowidget/"
                 "?mode=manage"
                 "&action=edit_widget"
                 "&id={})").format(widget_id),
            ))

            if not group_def:
                title = "{} - [COLOR firebrick]{}[/COLOR]".format(
                    widget_id, utils.get_string(32071))

            directory.add_menu_item(
                title=title,
                art=art,
                params={
                    "mode": "group",
                    "group": group
                },
                cm=cm[1:] if not action else cm,
                isFolder=True,
            )
    else:
        directory.add_menu_item(
            title=32072,
            art=utils.get_art("alert"),
            isFolder=False,
            props={"specialsort": "bottom"},
        )

    return True, utils.get_string(32074)
Beispiel #29
0
def show_path(group_id,
              path_label,
              widget_id,
              path,
              idx=0,
              titles=None,
              num=1,
              merged=False):
    hide_watched = utils.get_setting_bool("widgets.hide_watched")
    show_next = utils.get_setting_int("widgets.show_next")
    paged_widgets = utils.get_setting_bool("widgets.paged")
    default_color = utils.get_setting("ui.color")

    widget_def = manage.get_widget_by_id(widget_id)
    if not widget_def:
        return True, "AutoWidget"

    if not titles:
        titles = []

    files = refresh.get_files_list(path, widget_id)
    if not files:
        return titles, path_label

    utils.log("Loading items from {}".format(path), "debug")

    if isinstance(widget_def["path"], list):
        color = widget_def["path"][idx].get("color", default_color)
    elif isinstance(widget_def["path"], six.text_type):
        color = widget_def["stack"][0].get("color", default_color)
    else:
        color = widget_def["path"].get("color", default_color)

    stack = widget_def.get("stack", [])
    if stack:
        title = utils.get_string(32110).format(len(stack))
        directory.add_menu_item(
            title=title,
            params={
                "mode": "path",
                "action": "update",
                "id": widget_id,
                "path": "",
                "target": "back",
            },
            art=utils.get_art("back", color),
            isFolder=num > 1,
            props={
                "specialsort": "top",
                "autoLabel": path_label
            },
        )

    for file in files:
        properties = {"autoLabel": path_label, "autoID": widget_id}
        if "customproperties" in file:
            for prop in file["customproperties"]:
                properties[prop] = file["customproperties"][prop]

        clean_pattern = "[^\w \xC0-\xFF]"
        tag_pattern = "(\[[^\]]*\])"

        next_pattern = (
            "(?:^(?:next)?\s*(?:(?:>>)|(?:\.*)$)?)\s*"
            "(?:page\s*(?:(?:\d+\D*\d?$)|(?:(?:>>)|(?:\.*)$)|(?:\(\d+|.*\)$))?)?$"
        )
        prev_pattern = "^(?:previous(?: page)?)$|^(?:back)$"

        cleaned_title = re.sub(tag_pattern, "",
                               file.get("label", "").lower()).strip()
        next_item = re.search(next_pattern, cleaned_title)
        prev_item = re.search(prev_pattern, cleaned_title)

        if (prev_item and stack) or (next_item and show_next == 0):
            continue
        elif next_item and show_next > 0:
            label = utils.get_string(32111)
            properties["specialsort"] = "bottom"

            if num > 1:
                if show_next == 1:
                    continue

                label = "{} - {}".format(label, path_label)

            update_params = {
                "mode": "path",
                "action": "update",
                "id": widget_id,
                "path": file["file"],
                "target": "next",
            }

            directory.add_menu_item(
                title=label,
                params=update_params if paged_widgets and not merged else None,
                path=file["file"] if not paged_widgets or merged else None,
                art=utils.get_art("next_page", color),
                info=file,
                isFolder=not paged_widgets or merged,
                props=properties,
            )
        else:
            title = {
                "type": file.get("type"),
                "label": file.get("label"),
                "imdbnumber": file.get("imdbnumber"),
                "showtitle": file.get("showtitle"),
            }
            dupe = refresh.is_duplicate(title, titles)

            if (hide_watched and file.get("playcount", 0) > 0) or dupe:
                continue

            art = file.get("art", {})
            if not art.get("landscape") and art.get("thumb"):
                art["landscape"] = art["thumb"]

            directory.add_menu_item(
                title=file["label"],
                path=file["file"],
                art=art,
                info=file,
                isFolder=file["filetype"] == "directory",
                props=properties,
            )

            titles.append(title)

    return titles, path_label
Beispiel #30
0
def path_menu(group_id, action, widget_id):
    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        directory.add_menu_item(
            title=32073,
            info={"plot": utils.get_string(32075)},
            art=utils.get_art("alert"),
            isFolder=True,
        )
        return True, "AutoWidget"

    group_name = group_def.get("label", "")
    paths = group_def.get("paths", [])
    if len(paths) == 0:
        directory.add_menu_item(title=32032,
                                art=utils.get_art("alert"),
                                isFolder=True)
        return True, group_name

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if not widget_def:
        dialog = xbmcgui.Dialog()
        if action == "static":
            idx = dialog.select(utils.get_string(32114),
                                [i["label"] for i in paths])
            if idx == -1:
                return True, "AutoWidget"

            widget_def = manage.initialize(group_def,
                                           action,
                                           widget_id,
                                           keep=idx)
        elif action == 'cycling':
            idx = dialog.select(utils.get_string(32081), [
                utils.get_string(32079),
                utils.get_string(32080),
                utils.get_string(32242)
            ])
            if idx == -1:
                return True, 'AutoWidget'
            elif idx == 0:
                _action = 'random'
            elif idx == 1:
                _action = 'next'
            else:
                _action = 'randomized'

            widget_def = manage.initialize(group_def, _action, widget_id)

    if widget_def:
        widget_path = widget_def.get("path", {})

        if isinstance(widget_path, dict):
            _label = widget_path["label"]
            widget_path = widget_path["file"]["file"]
        else:
            stack = widget_def.get("stack", [])
            if stack:
                _label = stack[0]["label"]
            else:
                _label = widget_def.get("label", "")
        utils.log("Showing widget {}".format(widget_id), "debug")
        titles, cat = show_path(group_id, _label, widget_id, widget_path)
        return titles, cat
    else:
        directory.add_menu_item(title=32067,
                                art=utils.get_art("information_outline"),
                                isFolder=True)
        return True, group_name