Exemplo n.º 1
0
    def get_images_from_vfspath(self, lib_path):
        '''get all images from the given vfs path'''
        result = []
        # safety check: check if no library windows are active to prevent any addons setting the view
        if (xbmc.getCondVisibility("Window.IsMedia")
                and "plugin" in lib_path) or self.exit:
            return result

        lib_path = get_content_path(lib_path)

        if "plugin.video.emby" in lib_path and "browsecontent" in lib_path and "filter" not in lib_path:
            lib_path = lib_path + "&filter=random"

        items = self.kodidb.get_json(
            "Files.GetDirectory",
            returntype="",
            optparam=("directory", lib_path),
            fields=["title", "art", "thumbnail", "fanart"],
            sort={
                "method": "random",
                "order": "descending"
            },
            limits=(0, self.prefetch_images))

        for media in items:
            image = {}
            if media['label'].lower() == "next page":
                continue
            if media.get('art'):
                if media['art'].get('fanart'):
                    image["fanart"] = get_clean_image(media['art']['fanart'])
                elif media['art'].get('tvshow.fanart'):
                    image["fanart"] = get_clean_image(
                        media['art']['tvshow.fanart'])
                elif media['art'].get('artist.fanart'):
                    image["fanart"] = get_clean_image(
                        media['art']['artist.fanart'])
                if media['art'].get('thumb'):
                    image["thumbnail"] = get_clean_image(media['art']['thumb'])
            if not image.get('fanart') and media.get("fanart"):
                image["fanart"] = get_clean_image(media['fanart'])
            if not image.get("thumbnail") and media.get("thumbnail"):
                image["thumbnail"] = get_clean_image(media["thumbnail"])

            # only append items which have a fanart image
            if image.get("fanart"):
                # also append other art to the dict
                image["title"] = media.get('title', '')
                if not image.get("title"):
                    image["title"] = media.get('label', '')
                image["landscape"] = get_clean_image(
                    media.get('art', {}).get('landscape', ''))
                image["poster"] = get_clean_image(
                    media.get('art', {}).get('poster', ''))
                image["clearlogo"] = get_clean_image(
                    media.get('art', {}).get('clearlogo', ''))
                result.append(image)
        random.shuffle(result)
        return result
 def emby_nodes(self):
     '''build smart shortcuts for the emby addon'''
     if not self.all_nodes.get("emby"):
         nodes = []
         if xbmc.getCondVisibility(
                 "System.HasAddon(plugin.video.emby) + Skin.HasSetting(SmartShortcuts.emby)"
         ):
             emby_property = self.bgupdater.win.getProperty(
                 "emby.nodes.total")
             if emby_property:
                 content_strings = [
                     "", ".recent", ".inprogress", ".unwatched",
                     ".recentepisodes", ".inprogressepisodes",
                     ".nextepisodes", "recommended"
                 ]
                 nodes = []
                 total_nodes = int(emby_property)
                 for count in range(total_nodes):
                     # stop if shutdown requested in the meanwhile
                     if self.exit:
                         return
                     for content_string in content_strings:
                         key = "emby.nodes.%s%s" % (count, content_string)
                         item_path = self.bgupdater.win.getProperty(
                             "emby.nodes.%s%s.path" %
                             (count, content_string)).decode("utf-8")
                         mainlabel = self.bgupdater.win.getProperty(
                             "emby.nodes.%s.title" %
                             (count)).decode("utf-8")
                         sublabel = self.bgupdater.win.getProperty(
                             "emby.nodes.%s%s.title" %
                             (count, content_string)).decode("utf-8")
                         label = u"%s: %s" % (mainlabel, sublabel)
                         if not content_string:
                             label = mainlabel
                         if item_path:
                             content = get_content_path(item_path)
                             nodes.append(
                                 ("%s.image" % key, content, label))
                             if content_string == "":
                                 if "emby.nodes.%s" % count not in self.toplevel_nodes:
                                     self.toplevel_nodes.append(
                                         "emby.nodes.%s" % count)
                                 self.create_smartshortcuts_submenu(
                                     "emby.nodes.%s" % count,
                                     "special://home/addons/plugin.video.emby/icon.png"
                                 )
             log_msg("Generated smart shortcuts for emby nodes: %s" % nodes)
             self.all_nodes["emby"] = nodes
    def plex_nodes(self):
        '''build smart shortcuts listing for the (legacy) plex addon'''
        if not self.all_nodes.get("plex"):
            nodes = []
            if xbmc.getCondVisibility(
                    "System.HasAddon(plugin.video.plexbmc) + Skin.HasSetting(SmartShortcuts.plex)"
            ):
                xbmc.executebuiltin(
                    'RunScript(plugin.video.plexbmc,amberskin)')
                # wait a few seconds for the initialization to be finished
                monitor = xbmc.Monitor()
                monitor.waitForAbort(5)
                del monitor

                # get the plex setting if there are subnodes
                plexaddon = xbmcaddon.Addon(id='plugin.video.plexbmc')
                secondary_menus = plexaddon.getSetting("secondary") == "true"
                del plexaddon

                content_strings = ["", ".ondeck", ".recent", ".unwatched"]
                total_nodes = 50
                for i in range(total_nodes):
                    if not self.bgupdater.win.getProperty(
                            "plexbmc.%s.title" % i) or self.exit:
                        break
                    for content_string in content_strings:
                        key = "plexbmc.%s%s" % (i, content_string)
                        label = self.bgupdater.win.getProperty(
                            "plexbmc.%s.title" % i).decode("utf-8")
                        media_type = self.bgupdater.win.getProperty(
                            "plexbmc.%s.type" % i).decode("utf-8")
                        if media_type == "movie":
                            media_type = "movies"
                        if secondary_menus:
                            item_path = self.bgupdater.win.getProperty(
                                "plexbmc.%s.all" % i).decode("utf-8")
                        else:
                            item_path = self.bgupdater.win.getProperty(
                                "plexbmc.%s.path" % i).decode("utf-8")
                        item_path = item_path.replace(
                            "VideoLibrary", "Videos")  # fix for krypton ?
                        alllink = item_path
                        alllink = alllink.replace("mode=1", "mode=0")
                        alllink = alllink.replace("mode=2", "mode=0")
                        if content_string == ".recent":
                            label += " - Recently Added"
                            if media_type == "show":
                                media_type = "episodes"
                            if secondary_menus:
                                item_path = self.bgupdater.win.getProperty(
                                    key).decode("utf-8")
                            else:
                                item_path = alllink.replace(
                                    "/all", "/recentlyAdded")
                        elif content_string == ".ondeck":
                            label += " - On deck"
                            if media_type == "show":
                                media_type = "episodes"
                            if secondary_menus:
                                item_path = self.bgupdater.win.getProperty(
                                    key).decode("utf-8")
                            else:
                                item_path = alllink.replace("/all", "/onDeck")
                        elif content_string == ".unwatched":
                            if media_type == "show":
                                media_type = "episodes"
                            label += " - Unwatched"
                            item_path = alllink.replace("/all", "/unwatched")
                        elif content_string == "":
                            if media_type == "show":
                                media_type = "tvshows"
                            if key not in self.toplevel_nodes:
                                self.toplevel_nodes.append(key)
                            self.create_smartshortcuts_submenu(
                                "plexbmc.%s" % i,
                                "special://home/addons/plugin.video.plexbmc/icon.png"
                            )

                        # append media_type to path
                        if "&" in item_path:
                            item_path = item_path + "&media_type=" + media_type
                        else:
                            item_path = item_path + "?media_type=" + media_type
                        content = get_content_path(item_path)
                        nodes.append(("%s.image" % key, content, label))

                        # set smart shortcuts window props
                        self.bgupdater.set_winprop("%s.label" % key, label)
                        self.bgupdater.set_winprop("%s.title" % key, 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)

                # add plex channels as entry
                # extract path from one of the nodes as a workaround because main plex
                # addon channels listing is in error
                if nodes:
                    item_path = self.bgupdater.win.getProperty(
                        "plexbmc.0.path").decode("utf-8")
                    if not item_path:
                        item_path = self.bgupdater.win.getProperty(
                            "plexbmc.0.all").decode("utf-8")
                    item_path = item_path.split("/library/")[0]
                    item_path = item_path + "/channels/all&mode=21"
                    item_path = item_path + ", return)"
                    key = "plexbmc.channels"
                    label = "Channels"
                    content = get_content_path(item_path)
                    nodes.append(("%s.image" % key, content, label))
                    self.bgupdater.set_winprop("%s.label" % key, label)
                    self.bgupdater.set_winprop("%s.title" % key, 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, "episodes")
                    if key not in self.toplevel_nodes:
                        self.toplevel_nodes.append(key)
                self.all_nodes["plex"] = nodes