Exemplo n.º 1
0
 def genrebackground(self):
     '''helper to display images for a specific genre in multiimage control in the skin'''
     genre = self.params.get("genre").split(".")[0]
     arttype = self.params.get("arttype", "fanart")
     randomize = self.params.get("random", "false") == "true"
     mediatype = self.params.get("mediatype", "movies")
     if genre and genre != "..":
         filters = [{"operator": "is", "field": "genre", "value": genre}]
         if randomize:
             sort = {"method": "random", "order": "descending"}
         else:
             sort = {"method": "sorttitle", "order": "ascending"}
         items = getattr(self.kodi_db, mediatype)(sort=sort,
                                                  filters=filters,
                                                  limits=(0, 50))
         for item in items:
             image = get_clean_image(item["art"].get(arttype, ""))
             if image:
                 image = get_clean_image(item["art"][arttype])
                 listitem = xbmcgui.ListItem(image, path=image)
                 listitem.setProperty('mimetype', 'image/jpeg')
                 xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                             url=image,
                                             listitem=listitem)
     xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
Exemplo n.º 2
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
Exemplo n.º 3
0
 def get_player_infolabels():
     '''collect basic infolabels for the current item in the videoplayer'''
     details = {"art": {}}
     # normal properties
     props = [
         "title", "filenameandpath", "year", "genre", "duration", "plot",
         "plotoutline", "studio", "tvshowtitle", "premiered", "director",
         "writer", "season", "episode", "artist", "album", "rating",
         "albumartist", "discnumber", "firstaired", "mpaa", "tagline",
         "rating", "imdbnumber"
     ]
     for prop in props:
         propvalue = xbmc.getInfoLabel('VideoPlayer.%s' %
                                       prop).decode('utf-8')
         details[prop] = propvalue
     # art properties
     props = [
         "fanart", "poster", "clearlogo", "clearart", "landscape",
         "characterart", "thumb", "banner", "discart", "tvshow.landscape",
         "tvshow.clearlogo", "tvshow.poster", "tvshow.fanart",
         "tvshow.banner"
     ]
     for prop in props:
         propvalue = xbmc.getInfoLabel('Player.Art(%s)' %
                                       prop).decode('utf-8')
         if propvalue:
             prop = prop.replace("tvshow.", "")
             propvalue = get_clean_image(propvalue)
             details["art"][prop] = propvalue
     return details
Exemplo n.º 4
0
    def get_images_from_vfspath(self, lib_path, arttype):
        '''get all (unique and existing) images from the given vfs path to build the image wall'''
        result = []
        items = self.bgupdater.kodidb.get_json(
            "Files.GetDirectory",
            returntype="",
            optparam=("directory", lib_path),
            fields=["art", "thumbnail", "fanart"],
            sort={
                "method": "random",
                "order": "descending"
            })

        for media in items:
            image = None
            if media.get('art', {}).get(arttype):
                image = media['art'][arttype]
            elif media.get('art', {}).get('tvshow.%s' % arttype):
                image = media['art']['tvshow.%s' % arttype]
            elif media.get('art', {}).get('artist.%s' % arttype):
                image = media['art']['artist.%s' % arttype]
            elif arttype == "thumb" and media.get("thumbnail"):
                image = media["thumbnail"]
            elif arttype == "fanart" and media.get("fanart"):
                image = media["fanart"]
            image = get_clean_image(image)
            if image and image not in result and xbmcvfs.exists(image):
                result.append(image)
        return result
Exemplo n.º 5
0
 def genrebackground(self):
     '''helper to display images for a specific genre in multiimage control in the skin'''
     genre = self.params.get("genre").split(".")[0]
     arttype = self.params.get("arttype", "fanart")
     randomize = self.params.get("random", "false") == "true"
     mediatype = self.params.get("mediatype", "movies")
     if genre and genre != "..":
         filters = [{"operator": "is", "field": "genre", "value": genre}]
         if randomize:
             sort = {"method": "random", "order": "descending"}
         else:
             sort = {"method": "sorttitle", "order": "ascending"}
         items = getattr(self.kodi_db, mediatype)(
             sort=sort,
             filters=filters, limits=(0, 50))
         for item in items:
             image = get_clean_image(item["art"].get(arttype, ""))
             if image:
                 image = get_clean_image(item["art"][arttype])
                 listitem = xbmcgui.ListItem(image, path=image)
                 listitem.setProperty('mimetype', 'image/jpeg')
                 xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=image, listitem=listitem)
     xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
Exemplo n.º 6
0
 def process_channel(self, channeldata):
     '''transform the json received from kodi into something we can use'''
     item = {}
     channelname = channeldata["label"]
     channellogo = get_clean_image(channeldata['thumbnail'])
     if channeldata.get('broadcastnow'):
         # channel with epg data
         item = channeldata['broadcastnow']
         item["runtime"] = item["runtime"] * 60
         item["genre"] = u" / ".join(item["genre"])
         # del firstaired as it's value doesn't make any sense at all
         del item["firstaired"]
         # append artwork
         if self.enable_artwork:
             extend_dict(
                 item,
                 self.metadatautils.get_pvr_artwork(item["title"],
                                                    channelname,
                                                    item["genre"]))
     else:
         # channel without epg
         item = channeldata
         item["title"] = xbmc.getLocalizedString(161)
     item["file"] = u"plugin://script.skin.helper.service?action=playchannel&channelid=%s"\
         % (channeldata["channelid"])
     item["channel"] = channelname
     item["type"] = "channel"
     item["label"] = channelname
     item["channelid"] = channeldata["channelid"]
     if not channellogo:
         channellogo = self.metadatautils.get_channellogo(channelname).get(
             "ChannelLogo", "")
     if channellogo:
         item["art"] = {"thumb": channellogo}
     item["channellogo"] = channellogo
     item["isFolder"] = False
     return item
Exemplo n.º 7
0
 def get_player_infolabels():
     '''collect basic infolabels for the current item in the videoplayer'''
     details = {"art": {}}
     # normal properties
     props = ["title", "filenameandpath", "year", "genre", "duration", "plot", "plotoutline",
              "studio", "tvshowtitle", "premiered", "director", "writer", "season", "episode",
              "artist", "album", "rating", "albumartist", "discnumber",
              "firstaired", "mpaa", "tagline", "rating", "imdbnumber"
              ]
     for prop in props:
         propvalue = xbmc.getInfoLabel('VideoPlayer.%s' % prop).decode('utf-8')
         details[prop] = propvalue
     # art properties
     props = ["fanart", "poster", "clearlogo", "clearart", "landscape",
              "characterart", "thumb", "banner", "discart", "tvshow.landscape",
              "tvshow.clearlogo", "tvshow.poster", "tvshow.fanart", "tvshow.banner"
              ]
     for prop in props:
         propvalue = xbmc.getInfoLabel('Player.Art(%s)' % prop).decode('utf-8')
         if propvalue:
             prop = prop.replace("tvshow.", "")
             propvalue = get_clean_image(propvalue)
             details["art"][prop] = propvalue
     return details
Exemplo n.º 8
0
    def getcast(self):
        '''helper to get all cast for a given media item'''
        db_id = None
        all_cast = []
        all_cast_names = list()
        cache_str = ""
        download_thumbs = self.params.get("downloadthumbs", "") == "true"
        extended_cast_action = self.params.get("castaction", "") == "extendedinfo"
        tmdb = Tmdb()
        movie = self.params.get("movie")
        tvshow = self.params.get("tvshow")
        episode = self.params.get("episode")
        movieset = self.params.get("movieset")

        try:  # try to parse db_id
            if movieset:
                cache_str = "movieset.castcache-%s-%s" % (self.params["movieset"], download_thumbs)
                db_id = int(movieset)
            elif tvshow:
                cache_str = "tvshow.castcache-%s-%s" % (self.params["tvshow"], download_thumbs)
                db_id = int(tvshow)
            elif movie:
                cache_str = "movie.castcache-%s-%s" % (self.params["movie"], download_thumbs)
                db_id = int(movie)
            elif episode:
                cache_str = "episode.castcache-%s-%s" % (self.params["episode"], download_thumbs)
                db_id = int(episode)
        except Exception:
            pass

        cachedata = self.cache.get(cache_str)
        if cachedata:
            # get data from cache
            all_cast = cachedata
        else:
            # retrieve data from json api...
            if movie and db_id:
                all_cast = self.kodi_db.movie(db_id)["cast"]
            elif movie and not db_id:
                filters = [{"operator": "is", "field": "title", "value": movie}]
                result = self.kodi_db.movies(filters=filters)
                all_cast = result[0]["cast"] if result else []
            elif tvshow and db_id:
                all_cast = self.kodi_db.tvshow(db_id)["cast"]
            elif tvshow and not db_id:
                filters = [{"operator": "is", "field": "title", "value": tvshow}]
                result = self.kodi_db.tvshows(filters=filters)
                all_cast = result[0]["cast"] if result else []
            elif episode and db_id:
                all_cast = self.kodi_db.episode(db_id)["cast"]
            elif episode and not db_id:
                filters = [{"operator": "is", "field": "title", "value": episode}]
                result = self.kodi_db.episodes(filters=filters)
                all_cast = result[0]["cast"] if result else []
            elif movieset:
                if not db_id:
                    for item in self.kodi_db.moviesets():
                        if item["title"].lower() == movieset.lower():
                            db_id = item["setid"]
                if db_id:
                    json_result = self.kodi_db.movieset(db_id, include_set_movies_fields=["cast"])
                    if "movies" in json_result:
                        for movie in json_result['movies']:
                            all_cast += movie['cast']

            # optional: download missing actor thumbs
            if all_cast and download_thumbs:
                for cast in all_cast:
                    if cast.get("thumbnail"):
                        cast["thumbnail"] = get_clean_image(cast.get("thumbnail"))
                    if not cast.get("thumbnail"):
                        artwork = tmdb.get_actor(cast["name"])
                        cast["thumbnail"] = artwork.get("thumb", "")
            # lookup tmdb if item is requested that is not in local db
            if not all_cast:
                tmdbdetails = {}
                if movie and not db_id:
                    tmdbdetails = tmdb.search_movie(movie)
                elif tvshow and not db_id:
                    tmdbdetails = tmdb.search_tvshow(tvshow)
                if tmdbdetails.get("cast"):
                    all_cast = tmdbdetails["cast"]
            # save to cache
            self.cache.set(cache_str, all_cast)

        # process listing with the results...
        for cast in all_cast:
            if cast.get("name") not in all_cast_names:
                liz = xbmcgui.ListItem(label=cast.get("name"), label2=cast.get("role"),
                                       iconImage=cast.get("thumbnail"))
                if extended_cast_action:
                    url = "RunScript(script.extendedinfo,info=extendedactorinfo,name=%s)" % cast.get("name")
                    url = "plugin://script.skin.helper.service/?action=launch&path=%s" % url
                    is_folder = False
                else:
                    url = "RunScript(script.skin.helper.service,action=getcastmedia,name=%s)" % cast.get("name")
                    url = "plugin://script.skin.helper.service/?action=launch&path=%s" % urlencode(url)
                    is_folder = False
                all_cast_names.append(cast.get("name"))
                liz.setThumbnailImage(cast.get("thumbnail"))
                xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=liz, isFolder=is_folder)
        xbmcplugin.endOfDirectory(int(sys.argv[1]))
Exemplo n.º 9
0
    def getcast(self):
        '''helper to get all cast for a given media item'''
        db_id = None
        all_cast = []
        all_cast_names = list()
        cache_str = ""
        download_thumbs = self.params.get("downloadthumbs", "") == "true"
        extended_cast_action = self.params.get("castaction",
                                               "") == "extendedinfo"
        tmdb = Tmdb()
        movie = self.params.get("movie")
        tvshow = self.params.get("tvshow")
        episode = self.params.get("episode")
        movieset = self.params.get("movieset")

        try:  # try to parse db_id
            if movieset:
                cache_str = "movieset.castcache-%s-%s" % (
                    self.params["movieset"], download_thumbs)
                db_id = int(movieset)
            elif tvshow:
                cache_str = "tvshow.castcache-%s-%s" % (self.params["tvshow"],
                                                        download_thumbs)
                db_id = int(tvshow)
            elif movie:
                cache_str = "movie.castcache-%s-%s" % (self.params["movie"],
                                                       download_thumbs)
                db_id = int(movie)
            elif episode:
                cache_str = "episode.castcache-%s-%s" % (
                    self.params["episode"], download_thumbs)
                db_id = int(episode)
        except Exception:
            pass

        cachedata = self.cache.get(cache_str)
        if cachedata:
            # get data from cache
            all_cast = cachedata
        else:
            # retrieve data from json api...
            if movie and db_id:
                all_cast = self.kodi_db.movie(db_id)["cast"]
            elif movie and not db_id:
                filters = [{
                    "operator": "is",
                    "field": "title",
                    "value": movie
                }]
                result = self.kodi_db.movies(filters=filters)
                all_cast = result[0]["cast"] if result else []
            elif tvshow and db_id:
                all_cast = self.kodi_db.tvshow(db_id)["cast"]
            elif tvshow and not db_id:
                filters = [{
                    "operator": "is",
                    "field": "title",
                    "value": tvshow
                }]
                result = self.kodi_db.tvshows(filters=filters)
                all_cast = result[0]["cast"] if result else []
            elif episode and db_id:
                all_cast = self.kodi_db.episode(db_id)["cast"]
            elif episode and not db_id:
                filters = [{
                    "operator": "is",
                    "field": "title",
                    "value": episode
                }]
                result = self.kodi_db.episodes(filters=filters)
                all_cast = result[0]["cast"] if result else []
            elif movieset:
                if not db_id:
                    for item in self.kodi_db.moviesets():
                        if item["title"].lower() == movieset.lower():
                            db_id = item["setid"]
                if db_id:
                    json_result = self.kodi_db.movieset(
                        db_id, include_set_movies_fields=["cast"])
                    if "movies" in json_result:
                        for movie in json_result['movies']:
                            all_cast += movie['cast']

            # optional: download missing actor thumbs
            if all_cast and download_thumbs:
                for cast in all_cast:
                    if cast.get("thumbnail"):
                        cast["thumbnail"] = get_clean_image(
                            cast.get("thumbnail"))
                    if not cast.get("thumbnail"):
                        artwork = tmdb.get_actor(cast["name"])
                        cast["thumbnail"] = artwork.get("thumb", "")
            # lookup tmdb if item is requested that is not in local db
            if not all_cast:
                tmdbdetails = {}
                if movie and not db_id:
                    tmdbdetails = tmdb.search_movie(movie)
                elif tvshow and not db_id:
                    tmdbdetails = tmdb.search_tvshow(tvshow)
                if tmdbdetails.get("cast"):
                    all_cast = tmdbdetails["cast"]
            # save to cache
            self.cache.set(cache_str, all_cast)

        # process listing with the results...
        for cast in all_cast:
            if cast.get("name") not in all_cast_names:
                liz = xbmcgui.ListItem(label=cast.get("name"),
                                       label2=cast.get("role"),
                                       iconImage=cast.get("thumbnail"))
                if extended_cast_action:
                    url = "RunScript(script.extendedinfo,info=extendedactorinfo,name=%s)" % cast.get(
                        "name")
                    url = "plugin://script.skin.helper.service/?action=launch&path=%s" % url
                    is_folder = False
                else:
                    url = "RunScript(script.skin.helper.service,action=getcastmedia,name=%s)" % cast.get(
                        "name")
                    url = "plugin://script.skin.helper.service/?action=launch&path=%s" % urlencode(
                        url)
                    is_folder = False
                all_cast_names.append(cast.get("name"))
                liz.setThumbnailImage(cast.get("thumbnail"))
                xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                            url=url,
                                            listitem=liz,
                                            isFolder=is_folder)
        xbmcplugin.endOfDirectory(int(sys.argv[1]))