예제 #1
0
RESOURCE = xbmc.translatePath(os.path.join(CWD, 'resources',
                                           'lib')).decode("utf-8")
DATAPATH = os.path.join(
    xbmc.translatePath("special://profile/").decode('utf-8'), "addon_data",
    ADDONID)
MASTERPATH = os.path.join(
    xbmc.translatePath("special://masterprofile/").decode('utf-8'),
    "addon_data", ADDONID)

sys.path.append(RESOURCE)

import xmlfunctions, datafunctions, library, nodefunctions
XML = xmlfunctions.XMLFunctions()
DATA = datafunctions.DataFunctions()
LIBRARY = library.LibraryFunctions()
NODE = nodefunctions.NodeFunctions()

hashlist = []


def log(txt):
    if ADDON.getSetting("enable_logging") == "true":
        if isinstance(txt, str):
            txt = txt.decode('utf-8')
        message = u'%s: %s' % (ADDONID, txt)
        xbmc.log(msg=message.encode('utf-8'), level=xbmc.LOGDEBUG)


class Main:
    # MAIN ENTRY POINT
    def __init__(self):
예제 #2
0
    def __init__(self):
        self._parse_argv()
        self.WINDOW = xbmcgui.Window(10000)

        # Create data and master paths if not exists
        if not xbmcvfs.exists(__datapath__):
            xbmcvfs.mkdir(__datapath__)
        if not xbmcvfs.exists(__masterpath__):
            xbmcvfs.mkdir(__masterpath__)

        # Perform action specified by user
        if not self.TYPE:
            line1 = "This addon is for skin developers, and requires skin support"
            xbmcgui.Dialog().ok(__addonname__, line1)

        if self.TYPE == "buildxml":
            XML.buildMenu(self.MENUID, self.GROUP, self.LEVELS, self.MODE,
                          self.OPTIONS)

        if self.TYPE == "launch":
            xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]),
                                      succeeded=False,
                                      listitem=xbmcgui.ListItem())
            self._launch_shortcut(self.PATH)
        if self.TYPE == "launchpvr":
            xbmc.executeJSONRPC(
                '{ "jsonrpc": "2.0", "id": 0, "method": "Player.Open", "params": { "item": {"channelid": '
                + self.CHANNEL + '} } }')
        if self.TYPE == "manage":
            self._manage_shortcuts(self.GROUP, self.DEFAULTGROUP,
                                   self.NOLABELS, self.GROUPNAME)

        if self.TYPE == "hidesubmenu":
            self._hidesubmenu(self.MENUID)
        if self.TYPE == "resetlist":
            self._resetlist(self.MENUID, self.NEXTACTION)

        if self.TYPE == "shortcuts":
            # We're just going to choose a shortcut, and save its details to the given
            # skin labels

            if self.GROUPING is not None:
                selectedShortcut = LIBRARY.selectShortcut(
                    "",
                    grouping=self.GROUPING,
                    custom=self.CUSTOM,
                    showNone=self.NONE)
            else:
                selectedShortcut = LIBRARY.selectShortcut("",
                                                          custom=self.CUSTOM,
                                                          showNone=self.NONE)

            # Now set the skin strings
            if selectedShortcut is not None and selectedShortcut.getProperty(
                    "Path"):
                path = urllib.unquote(selectedShortcut.getProperty("Path"))
                if selectedShortcut.getProperty("chosenPath"):
                    path = urllib.unquote(
                        selectedShortcut.getProperty("chosenPath"))

                if path.startswith("pvr-channel://"):
                    path = "RunScript(script.skinshortcuts,type=launchpvr&channel=" + path.replace(
                        "pvr-channel://", "") + ")"
                if self.LABEL is not None and selectedShortcut.getLabel(
                ) != "":
                    xbmc.executebuiltin("Skin.SetString(" + self.LABEL + "," +
                                        selectedShortcut.getLabel() + ")")
                if self.ACTION is not None:
                    xbmc.executebuiltin("Skin.SetString(" + self.ACTION + "," +
                                        path + " )")
                if self.SHORTCUTTYPE is not None:
                    xbmc.executebuiltin("Skin.SetString(" + self.SHORTCUTTYPE +
                                        "," + selectedShortcut.getLabel2() +
                                        ")")
                if self.THUMBNAIL is not None and selectedShortcut.getProperty(
                        "icon"):
                    xbmc.executebuiltin("Skin.SetString(" + self.THUMBNAIL +
                                        "," +
                                        selectedShortcut.getProperty("icon") +
                                        ")")
                if self.THUMBNAIL is not None and selectedShortcut.getProperty(
                        "thumbnail"):
                    xbmc.executebuiltin(
                        "Skin.SetString(" + self.THUMBNAIL + "," +
                        selectedShortcut.getProperty("thumbnail") + ")")
                if self.LIST is not None:
                    xbmc.executebuiltin("Skin.SetString(" + self.LIST + "," +
                                        DATA.getListProperty(path) + ")")
            elif selectedShortcut is not None and selectedShortcut.getLabel(
            ) == "::NONE::":
                # Clear the skin strings
                if self.LABEL is not None:
                    xbmc.executebuiltin("Skin.Reset(" + self.LABEL + ")")
                if self.ACTION is not None:
                    xbmc.executebuiltin("Skin.Reset(" + self.ACTION + " )")
                if self.SHORTCUTTYPE is not None:
                    xbmc.executebuiltin("Skin.Reset(" + self.SHORTCUTTYPE +
                                        ")")
                if self.THUMBNAIL is not None:
                    xbmc.executebuiltin("Skin.Reset(" + self.THUMBNAIL + ")")
                if self.THUMBNAIL is not None:
                    xbmc.executebuiltin("Skin.Reset(" + self.THUMBNAIL + ")")
                if self.LIST is not None:
                    xbmc.executebuiltin("Skin.Reset(" + self.LIST + ")")

        if self.TYPE == "addNode":
            # We've been sent a node from plugin.program.video.node.editor
            targetDir = "library://video" + self.OPTIONS[0]

            icon = "DefaultShortcut.png"
            if self.OPTIONS[2] != "None":
                icon = self.OPTIONS[2].decode("utf-8")

            result = nodefunctions.NodeFunctions().addNodeToMenu(
                targetDir,
                urllib.unquote(self.OPTIONS[1]).decode("utf-8"), icon, DATA)

            if result == False:
                # The item failed to add to the menu
                xbmcgui.dialog().ok(__addon__.getAddonInfo("name"),
                                    __language__(32091))

        if self.TYPE == "resetall":
            # Tell XBMC not to try playing any media
            try:
                xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]),
                                          succeeded=False,
                                          listitem=xbmcgui.ListItem())
            except:
                log("Not launched from a list item")
            self._reset_all_shortcuts()