Example #1
0
def _copy_path(path_def):
    group_id = add_group(path_def["target"], path_def["label"])
    if not group_id:
        return

    progress = xbmcgui.DialogProgressBG()
    progress.create("AutoWidget", utils.get_string(30143))
    progress.update(1, "AutoWidget", utils.get_string(30144))

    group_def = manage.get_group_by_id(group_id)
    files, hash = refresh.get_files_list(path_def["file"]["file"], background=False)
    if not files:
        progress.close()
        return
    done = 0
    for file in files:
        done += 1
        if file["type"] in ["movie", "episode", "musicvideo", "song"]:
            continue
        progress.update(
            int(done / float(len(files)) * 100),
            heading=utils.get_string(30143),
            message=file.get("label"),
        )

        labels = build_labels("json", file, path_def["target"])
        _add_path(group_def, labels, over=True)
    progress.close()
    del progress
    dialog = xbmcgui.Dialog()
    dialog.notification(
        "AutoWidget", utils.get_string(30105).format(len(files), group_def["label"])
    )
    del dialog
def _copy_path(path_def):
    group_id = add_group(path_def['target'], path_def['label'])
    if not group_id:
        return
        
    group_def = manage.get_group_by_id(group_id)
    files = refresh.get_files_list(path_def['file']['file'])
    if not files:
        return
    
    for file in files:
        if file.get('type') in ['movie', 'episode', 'musicvideo', 'song']:
            continue
            
        labels = build_labels('json', file, path_def['target'])
        _add_path(group_def, labels, over=True)
    dialog.notification('AutoWidget', utils.get_string(32131)
                                      .format(len(files), group_def['label']))
Example #3
0
def _copy_path(path_def):
    group_id = add_group(path_def["target"], path_def["label"])
    if not group_id:
        return

    group_def = manage.get_group_by_id(group_id)
    files = refresh.get_files_list(path_def["file"]["file"])
    if not files:
        return

    for file in files:
        if file.get("type") in ["movie", "episode", "musicvideo", "song"]:
            continue

        labels = build_labels("json", file, path_def["target"])
        _add_path(group_def, labels, over=True)
    dialog.notification(
        "AutoWidget",
        utils.get_string(32131).format(len(files), group_def["label"]))
Example #4
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
Example #5
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
Example #6
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 show_path(
    group_id,
    path_label,
    widget_id,
    widget_path,
    idx=0,
    titles=None,
    num=1,
    merged=False,
):
    hide_watched = settings.get_setting_bool("widgets.hide_watched")
    show_next = settings.get_setting_int("widgets.show_next")
    paged_widgets = settings.get_setting_bool("widgets.paged")
    default_color = settings.get_setting_string("ui.color")

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

    content = widget_path.get("content")
    action = widget_def.get("action", "")
    if not titles:
        titles = []

    stack = widget_def.get("stack", [])
    path = widget_path["file"]["file"] if not stack else stack[-1]

    files, hash = refresh.get_files_list(path, widget_id)
    # if not files:
    #     properties = {
    #         "autoLabel": path_label,
    #         "autoID": widget_id,
    #         "autoAction": action,
    #         "autoCache": hash,
    #     }
    #     if files is None:
    #         show_error(path_label, properties)
    #     elif files == []:
    #         show_empty(path_label, properties)
    #     return titles if titles else True, path_label, content

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

    color = widget_path.get("color", default_color)

    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,
            "autoAction": action,
            "autoCache": hash,
        }
        next_item = False
        prev_item = False
        is_folder = file["filetype"] == "directory"

        if pos == len(files) - 1 and is_folder:
            next_item = _is_page_item(file.get("label", ""))
        elif pos == 0 and is_folder:
            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:
            filetype = file.get("type", "")
            title = {
                "type": filetype,
                "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

            filepath = ""
            info_type = directory.info_types.get(filetype, "video")
            if (path.startswith("library://{}/".format(info_type))
                    or path.startswith("{}db://".format(info_type) or
                                       path.endswith(".xsp"))) and is_folder:
                filepath = directory.make_library_path(info_type, filetype,
                                                       file.get("id", -1))

            directory.add_menu_item(
                title=file["label"],
                path=file["file"] if not filepath else filepath,
                info=file,
                isFolder=is_folder,
                props=properties,
            )

            titles.append(title)

    return titles, path_label, content