예제 #1
0
def set_color(setting=False):
    dialog = xbmcgui.Dialog()
    color = settings.get_setting_string("ui.color")

    choice = dialog.yesno(
        "AutoWidget",
        get_string(30107),
        yeslabel=get_string(30108),
        nolabel=get_string(30109),
    )

    if choice:
        value = dialog.input(get_string(30110)).lower()
    else:
        value = dialog.select(
            get_string(30111),
            ["[COLOR {0}]{0}[/COLOR]".format(i) for i in colors],
            preselect=colors.index(color) if color in colors else -1,
        )
        if value > -1:
            value = colors[value]

    if value != -1:
        if value not in colors:
            if len(value) < 6:
                dialog.notification("AutoWidget", get_string(30112))
                del dialog
                return
            elif len(value) == 6 and not value.startswith("#"):
                value = "#{}".format(value)
        if setting:
            settings.set_setting_string("ui.color", value)

    del dialog
    return value
예제 #2
0
def get_art(filename, color=None):
    art = {}
    if not color:
        color = settings.get_setting_string("ui.color")

    themed_path = os.path.join(_addon_data, color)
    if not os.path.exists(themed_path):
        os.makedirs(themed_path)

    for i in art_types:
        _i = i
        if i == "thumb":
            _i = "icon"
        path = os.path.join(_art_path, _i, "{}.png".format(filename))
        new_path = ""

        if os.path.exists(path):
            if color.lower() not in ["white", "#ffffff"]:
                new_path = os.path.join(themed_path,
                                        "{}-{}.png".format(filename, _i))
                if not os.path.exists(new_path):
                    icon = Image.open(path).convert("RGBA")
                    overlay = Image.new("RGBA", icon.size, color)
                    Image.composite(overlay, icon, icon).save(new_path)
            art[i] = clean_artwork_url(
                new_path if os.path.exists(new_path) else path)

    return art
예제 #3
0
def build_labels(source, path_def=None, target=""):
    if source == "context" and not path_def and not target:
        content = utils.get_infolabel("Container.Content")
        labels = {
            "label": utils.get_infolabel("ListItem.Label"),
            "content": content if content else "videos",
        }

        path_def = {
            "file":
            utils.get_infolabel("ListItem.FolderPath"),
            "filetype":
            "directory"
            if utils.get_condition("Container.ListItem.IsFolder") else "file",
            "art": {},
        }  # would be fun to set some "placeholder" art here

        for i in utils.get_info_keys():
            info = utils.get_infolabel("ListItem.{}".format(i.capitalize()))
            if info and not info.startswith("ListItem"):
                path_def[i] = info

        for i in utils.art_types:
            art = utils.get_infolabel("ListItem.Art({})".format(i))
            if art:
                path_def["art"][i] = utils.clean_artwork_url(art)
        for i in ["icon", "thumb"]:
            art = utils.clean_artwork_url(
                utils.get_infolabel("ListItem.{}".format(i)))
            if art:
                path_def["art"][i] = art
    elif source == "json" and path_def and target:
        labels = {
            "label": path_def["label"],
            "content": "videos",
            "target": target
        }

    labels["file"] = (path_def if path_def else {
        key: path_def[key]
        for key in path_def if path_def[key]
    })
    path = labels["file"]["file"]

    if path != "addons://user/":
        path = path.replace("addons://user/", "plugin://")
    if "plugin://plugin.video.themoviedb.helper" in path and not "&widget=True" in path:
        path += "&widget=True"
    labels["file"]["file"] = path

    labels["color"] = settings.get_setting_string("ui.color")

    for _key in utils.windows:
        if any(i in path for i in utils.windows[_key]):
            labels["window"] = _key

    return labels
예제 #4
0
def wipe(folder=_addon_data):
    dialog = xbmcgui.Dialog()
    choice = dialog.yesno("AutoWidget", get_string(30044))
    del dialog

    if choice:
        for root, dirs, files in os.walk(folder):
            backup_location = translate_path(
                settings.get_setting_string("backup.location"))
            for name in files:
                file = os.path.join(root, name)
                if backup_location not in file:
                    os.remove(file)
            for name in dirs:
                dir = os.path.join(root, name)
                if backup_location[:-1] not in dir:
                    os.rmdir(dir)
예제 #5
0
import xbmcgui

import os
import zipfile

import six

from resources.lib.common import settings
from resources.lib.common import utils

_addon_data = utils.translate_path(settings.get_addon_info("profile"))
_backup_location = utils.translate_path(settings.get_setting_string("backup.location"))


def location():
    dialog = xbmcgui.Dialog()
    folder = dialog.browse(
        0, utils.get_string(30068), "files", defaultt=_backup_location
    )
    del dialog

    if folder:
        settings.set_setting_string("backup.location", folder)


def backup():
    dialog = xbmcgui.Dialog()
    choice = dialog.yesno("AutoWidget", utils.get_string(30071))

    if choice:
        filename = dialog.input(utils.get_string(30072))
예제 #6
0
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