Example #1
0
def plugin_widgetlisting(pluginpath, sublevel=""):
    '''get all nodes in a plugin listing'''
    widgets = []
    if sublevel:
        media_array = kodi_json('Files.GetDirectory', {
            "directory": pluginpath,
            "media": "files"
        })
    else:
        if not xbmc.getCondVisibility("System.HasAddon(%s)" % pluginpath):
            return []
        media_array = kodi_json('Files.GetDirectory', {
            "directory": "plugin://%s" % pluginpath,
            "media": "files"
        })
    for item in media_array:
        log_msg("skinshortcuts widgets processing: %s" % (item["file"]))
        content = item["file"]
        label = item["label"]
        # extendedinfo has some login-required widgets, skip those
        if ("script.extendedinfo" in pluginpath and not EXTINFO_CREDS
                and ("info=starred" in content or "info=rated" in content
                     or "info=account" in content)):
            continue
        if item.get("filetype", "") == "file":
            continue
        media_type = detect_plugin_content(item["file"])
        if media_type == "empty":
            continue
        if media_type == "folder":
            content = "plugin://script.skin.helper.service?action=widgets&path=%s&sublevel=%s" % (
                urlencode(item["file"]), label)
        # add reload param for skinhelper and libraryprovider widgets
        if "reload=" not in content and ("script.skin.helper" in pluginpath
                                         or pluginpath
                                         == "service.library.data.provider"):
            if "albums" in content or "songs" in content or "artists" in content:
                reloadstr = "&reload=$INFO[Window(Home).Property(widgetreloadmusic)]"
            elif ("pvr" in content or "media" in content
                  or "favourite" in content) and "progress" not in content:
                reloadstr = "&reload=$INFO[Window(Home).Property(widgetreload)]"\
                    "$INFO[Window(Home).Property(widgetreload2)]"
            else:
                reloadstr = "&reload=$INFO[Window(Home).Property(widgetreload)]"
            content = content + reloadstr
        content = content.replace("&limit=100", "&limit=25")
        widgets.append([label, content, media_type])
        if pluginpath == "script.extendedinfo" and not sublevel:
            # some additional entrypoints for extendedinfo...
            widgets += extendedinfo_youtube_widgets()
    return widgets
 def favourites_nodes(self):
     '''build smart shortcuts for favourites'''
     if xbmc.getCondVisibility("Skin.HasSetting(SmartShortcuts.favorites)"):
         # build node listing
         nodes = []
         favs = KodiDb().favourites()
         for count, fav in enumerate(favs):
             if fav["type"] == "window":
                 content = fav["windowparameter"]
                 # check if this is a valid path with content
                 if ("script://" not in content.lower()
                         and "mode=9" not in content.lower()
                         and "search" not in content.lower()
                         and "play" not in content.lower()):
                     item_path = "ActivateWindow(%s,%s,return)" % (
                         fav["window"], content)
                     if "&" in content and "?" in content and "=" in content and not content.endswith(
                             "/"):
                         content += "&widget=true"
                     media_type = detect_plugin_content(content)
                     if media_type:
                         key = "favorite.%s" % count
                         self.bgupdater.set_winprop("%s.label" % key,
                                                    fav["label"])
                         self.bgupdater.set_winprop("%s.title" % key,
                                                    fav["label"])
                         self.bgupdater.set_winprop("%s.action" % key,
                                                    item_path)
                         self.bgupdater.set_winprop("%s.path" % key,
                                                    item_path)
                         self.bgupdater.set_winprop("%s.content" % key,
                                                    content)
                         self.bgupdater.set_winprop("%s.type" % key,
                                                    media_type)
                         if key not in self.toplevel_nodes:
                             self.toplevel_nodes.append(key)
                         nodes.append(
                             ("%s.image" % key, content, fav["label"]))
         self.all_nodes["favourites"] = nodes
Example #3
0
def playlists_widgets():
    '''skin provided playlists'''
    widgets = []
    import xml.etree.ElementTree as xmltree
    for playlist_path in [
            "special://skin/playlists/",
            "special://skin/extras/widgetplaylists/",
            "special://skin/extras/playlists/"
    ]:
        if xbmcvfs.exists(playlist_path):
            log_msg("skinshortcuts widgets processing: %s" % playlist_path)
            media_array = kodi_json('Files.GetDirectory', {
                "directory": playlist_path,
                "media": "files"
            })
            for item in media_array:
                if item["file"].endswith(".xsp"):
                    playlist = item["file"]
                    contents = xbmcvfs.File(item["file"], 'r')
                    contents_data = contents.read().decode('utf-8')
                    contents.close()
                    xmldata = xmltree.fromstring(contents_data.encode('utf-8'))
                    media_type = ""
                    label = item["label"]
                    for line in xmldata.getiterator():
                        if line.tag == "smartplaylist":
                            media_type = line.attrib['type']
                        if line.tag == "name":
                            label = line.text
                    try:
                        languageid = int(label)
                        label = xbmc.getLocalizedString(languageid)
                    except Exception:
                        pass
                    if not media_type:
                        media_type = detect_plugin_content(playlist)
                    widgets.append([label, playlist, media_type])
    return widgets
Example #4
0
def favourites_widgets():
    '''widgets from favourites'''
    favourites = kodi_json(
        'Favourites.GetFavourites', {
            "type": None,
            "properties": ["path", "thumbnail", "window", "windowparameter"]
        })
    widgets = []
    if favourites:
        for fav in favourites:
            if "windowparameter" in fav:
                content = fav["windowparameter"]
                # check if this is a valid path with content
                if ("script://" not in content.lower()
                        and "mode=9" not in content.lower()
                        and "search" not in content.lower()
                        and "play" not in content.lower()):
                    label = fav["title"]
                    log_msg("skinshortcuts widgets processing favourite: %s" %
                            label)
                    mediatype = detect_plugin_content(content)
                    if mediatype and mediatype != "empty":
                        widgets.append([label, content, mediatype])
    return widgets