def calc_trajectories(forward_flows, backward_flows, frame_dimensions, len_thresh): f_num = 0 trajectories = {'positions': [], 'deltas': [], 'st_frame': []} completed_trajectories = {'positions': [], 'st_frame': []} for forward_flow, backward_flow in zip(forward_flows, backward_flows): _init_missing_trajectories(forward_flow, trajectories, f_num) _update_trajectories(forward_flow, backward_flow, trajectories, completed_trajectories, frame_dimensions, len_thresh) f_num += 1 extend_dict(completed_trajectories, trajectories) return completed_trajectories
def get_moviesetdetails(metadatautils, title, set_id): '''Returns complete (nicely formatted) information about the movieset and it's movies''' details = {} # try to get from cache first # use checksum compare based on playcounts because moviesets do not get refreshed automatically movieset = metadatautils.kodidb.movieset(set_id, ["playcount"]) cache_str = "MovieSetDetails.%s" % (set_id) cache_checksum = "%s.%s" % (set_id, metadatautils.studiologos_path) if movieset and len(movieset["movies"]) < 50: for movie in movieset["movies"]: cache_checksum += "%s" % movie["playcount"] cache = metadatautils.cache.get(cache_str, checksum=cache_checksum) if cache: return cache # grab all details online and from kodi dbid details = get_online_setdata(metadatautils, title) details = extend_dict(details, get_kodidb_setdata(metadatautils, set_id)) if not details.get("plot"): details["plot"] = details["plots"] details["extendedplot"] = details["titles"] + u"[CR]" + details["plot"] all_fanarts = details["art"]["fanarts"] efa_path = "plugin://script.skin.helper.service/?action=extrafanart&fanarts=%s" % quote_plus(repr(all_fanarts)) details["art"]["extrafanart"] = efa_path for count, fanart in enumerate(all_fanarts): details["art"]["ExtraFanArt.%s" % count] = fanart metadatautils.cache.set(cache_str, details, checksum=cache_checksum) return details
def get_online_setdata(metadatautils, title): """get moviesetdetails from TMDB and fanart.tv""" details = metadatautils.tmdb.search_movieset(title) if details: # append images from fanart.tv details["art"] = extend_dict( details["art"], metadatautils.fanarttv.movie(details["tmdb_id"]), ["poster", "fanart", "clearlogo", "clearart"]) return details
def get_online_setdata(artutils, title): '''get moviesetdetails from TMDB and fanart.tv''' details = artutils.tmdb.search_movieset(title) if details: # append images from fanart.tv details["art"] = extend_dict( details["art"], artutils.fanarttv.movie(details["tmdb_id"]), ["poster", "fanart"]) return details
def get_online_setdata(metadatautils, title): '''get moviesetdetails from TMDB and fanart.tv''' details = metadatautils.tmdb.search_movieset(title) if details: # append images from fanart.tv details["art"] = extend_dict( details["art"], metadatautils.fanarttv.movie(details["tmdb_id"]), ["poster", "fanart"]) return details
def get_music_artwork(self, artist, album, track, disc, ignore_cache=False, flush_cache=False, manual=False): """ get music metadata by providing artist and/or album/track returns combined result of artist and album metadata """ if artist == track or album == track: track = "" artists = self.get_all_artists(artist, track) album = self.get_clean_title(album) track = self.get_clean_title(track) # retrieve artist and album details artist_details = self.get_artists_metadata(artists, album, track, ignore_cache=ignore_cache, flush_cache=flush_cache, manual=manual) album_artist = artist_details.get("albumartist", artists[0]) if album or track: album_details = self.get_album_metadata(album_artist, album, track, disc, ignore_cache=ignore_cache, flush_cache=flush_cache, manual=manual) else: album_details = {"art": {}} # combine artist details and album details details = extend_dict(album_details, artist_details) # combine artist plot and album plot as extended plot if artist_details.get("plot") and album_details.get("plot"): details["extendedplot"] = "%s -- %s" % (album_details["plot"], artist_details["plot"]) else: details["extendedplot"] = details.get("plot", "") # append track title to results if track: details["title"] = track # return the endresult return details
def get_music_artwork(self, artist, album, track, disc, ignore_cache=False, flush_cache=False, manual=False): ''' get music metadata by providing artist and/or album/track returns combined result of artist and album metadata ''' if artist == track or album == track: track = "" artists = self.get_all_artists(artist, track) album = self.get_clean_title(album) track = self.get_clean_title(track) # retrieve artist and album details artist_details = self.get_artists_metadata(artists, album, track, ignore_cache=ignore_cache, flush_cache=flush_cache, manual=manual) album_artist = artist_details.get("albumartist", artists[0]) if album or track: album_details = self.get_album_metadata(album_artist, album, track, disc, ignore_cache=ignore_cache, flush_cache=flush_cache, manual=manual) else: album_details = {"art": {}} # combine artist details and album details details = extend_dict(album_details, artist_details) # combine artist plot and album plot as extended plot if artist_details.get("plot") and album_details.get("plot"): details["extendedplot"] = "%s -- %s" % (album_details["plot"], artist_details["plot"]) else: details["extendedplot"] = details.get("plot", "") # append track title to results if track: details["title"] = track # return the endresult return details
def get_album_metadata(self, artist, album, track, disc, ignore_cache=False, flush_cache=False, manual=False): """collect all album metadata""" cache_str = "music_artwork.album.%s.%s.%s" % ( artist.lower(), album.lower(), disc.lower()) if not album: cache_str = "music_artwork.album.%s.%s" % (artist.lower(), track.lower()) details = {"art": {}, "cachestr": cache_str} # retrieve details from cache cache = self._mutils.cache.get(cache_str) if not cache and flush_cache: # nothing to do - just return empty results return details elif cache and flush_cache: # only update kodi metadata for updated counts etc details = extend_dict( self.get_album_kodi_metadata(artist, album, track, disc), cache) elif cache and not ignore_cache: # we have a valid cache - return that details = cache elif cache and manual: # user wants to manually override the artwork in the cache details = self.manual_set_music_artwork(cache, "album") else: # nothing in cache - start metadata retrieval local_path = "" local_path_custom = "" # get metadata from kodi db details = extend_dict( details, self.get_album_kodi_metadata(artist, album, track, disc)) if not album and details.get("title"): album = details["title"] # get artwork from songlevel path if details.get("diskpath") and self._mutils.addon.getSetting( "music_art_musicfolders") == "true": details["art"] = extend_dict( details["art"], self.lookup_albumart_in_folder(details["diskpath"])) local_path = details["diskpath"] # get artwork from custom folder if self._mutils.addon.getSetting("music_art_custom") == "true": if sys.version_info.major == 3: custom_path = self._mutils.addon.getSetting( "music_art_custom_path") else: custom_path = self._mutils.addon.getSetting( "music_art_custom_path").decode("utf-8") local_path_custom = self.get_custom_album_path( custom_path, artist, album, disc) details["art"] = extend_dict( details["art"], self.lookup_albumart_in_folder(local_path_custom)) details["customartpath"] = local_path_custom # lookup online metadata if self._mutils.addon.getSetting("music_art_scraper") == "true": # prefer the musicbrainzid that is already in the kodi database - only perform lookup if missing mb_albumid = details.get("musicbrainzalbumid") if not mb_albumid: mb_albumid = self.get_mb_album_id(artist, album, track) if mb_albumid: # get artwork from fanarttv if self._mutils.addon.getSetting( "music_art_scraper_fatv") == "true": details["art"] = extend_dict( details["art"], self._mutils.fanarttv.album(mb_albumid)) # get metadata from theaudiodb if self._mutils.addon.getSetting( "music_art_scraper_adb") == "true": details = extend_dict( details, self.audiodb.album_info(mb_albumid)) # get metadata from lastfm if self._mutils.addon.getSetting( "music_art_scraper_lfm") == "true": details = extend_dict( details, self.lastfm.album_info(mb_albumid)) # metadata from musicbrainz if not details.get("year") or not details.get("genre"): details = extend_dict( details, self.mbrainz.get_albuminfo(mb_albumid)) # musicbrainz thumb as last resort if not details["art"].get("thumb"): details["art"]["thumb"] = self.mbrainz.get_albumthumb( mb_albumid) # download artwork to music folder if local_path and self._mutils.addon.getSetting( "music_art_download") == "true": details["art"] = download_artwork( local_path, details["art"]) # download artwork to custom folder if local_path_custom and self._mutils.addon.getSetting( "music_art_download_custom") == "true": details["art"] = download_artwork( local_path_custom, details["art"]) # set default details if not details.get("album") and details.get("title"): details["album"] = details["title"] if details["art"].get("thumb"): details["art"]["albumthumb"] = details["art"]["thumb"] # store results in cache and return results self._mutils.cache.set(cache_str, details) return details
def get_artist_metadata(self, artist, album, track, ignore_cache=False, flush_cache=False, manual=False): """collect artist metadata for given artist""" details = {"art": {}} cache_str = "music_artwork.artist.%s" % artist.lower() # retrieve details from cache cache = self._mutils.cache.get(cache_str) if not cache and flush_cache: # nothing to do - just return empty results return details elif cache and flush_cache: # only update kodi metadata for updated counts etc details = extend_dict(self.get_artist_kodi_metadata(artist), cache) elif cache and not ignore_cache: # we have a valid cache - return that details = cache elif cache and manual: # user wants to manually override the artwork in the cache details = self.manual_set_music_artwork(cache, "artist") else: # nothing in cache - start metadata retrieval log_msg( "get_artist_metadata --> artist: %s - album: %s - track: %s" % (artist, album, track)) details["cachestr"] = cache_str local_path = "" local_path_custom = "" # get metadata from kodi db details = extend_dict(details, self.get_artist_kodi_metadata(artist)) # get artwork from songlevel path if details.get("diskpath") and self._mutils.addon.getSetting( "music_art_musicfolders") == "true": details["art"] = extend_dict( details["art"], self.lookup_artistart_in_folder(details["diskpath"])) local_path = details["diskpath"] # get artwork from custom folder if self._mutils.addon.getSetting("music_art_custom") == "true": if sys.version_info.major == 3: custom_path = self._mutils.addon.getSetting( "music_art_custom_path") else: custom_path = self._mutils.addon.getSetting( "music_art_custom_path").decode("utf-8") local_path_custom = self.get_customfolder_path( custom_path, artist) log_msg("custom path on disk for artist: %s --> %s" % (artist, local_path_custom)) details["art"] = extend_dict( details["art"], self.lookup_artistart_in_folder(local_path_custom)) details["customartpath"] = local_path_custom # lookup online metadata if self._mutils.addon.getSetting("music_art_scraper") == "true": if not album and not track: album = details.get("ref_album") track = details.get("ref_track") # prefer the musicbrainzid that is already in the kodi database - only perform lookup if missing mb_artistid = details.get( "musicbrainzartistid", self.get_mb_artist_id(artist, album, track)) details["musicbrainzartistid"] = mb_artistid if mb_artistid: # get artwork from fanarttv if self._mutils.addon.getSetting( "music_art_scraper_fatv") == "true": details["art"] = extend_dict( details["art"], self._mutils.fanarttv.artist(mb_artistid)) # get metadata from theaudiodb if self._mutils.addon.getSetting( "music_art_scraper_adb") == "true": details = extend_dict( details, self.audiodb.artist_info(mb_artistid)) # get metadata from lastfm if self._mutils.addon.getSetting( "music_art_scraper_lfm") == "true": details = extend_dict( details, self.lastfm.artist_info(mb_artistid)) # download artwork to music folder if local_path and self._mutils.addon.getSetting( "music_art_download") == "true": details["art"] = download_artwork( local_path, details["art"]) # download artwork to custom folder if local_path_custom and self._mutils.addon.getSetting( "music_art_download_custom") == "true": details["art"] = download_artwork( local_path_custom, details["art"]) # fix extrafanart if details["art"].get("fanarts"): for count, item in enumerate( details["art"]["fanarts"]): details["art"]["fanart.%s" % count] = item if not details["art"].get("extrafanart") and len( details["art"]["fanarts"]) > 1: details["art"]["extrafanart"] = "plugin://script.skin.helper.service/"\ "?action=extrafanart&fanarts=%s" % quote_plus(repr(details["art"]["fanarts"])) # multi-image path for all images for each arttype for arttype in ["banners", "clearlogos", "thumbs"]: art = details["art"].get(arttype, []) if len(art) > 1: # use the extrafanart plugin entry to display multi images details["art"][arttype] = "plugin://script.skin.helper.service/"\ "?action=extrafanart&fanarts=%s" % quote_plus(repr(art)) # set default details if not details.get("artist"): details["artist"] = artist if details["art"].get("thumb"): details["art"]["artistthumb"] = details["art"]["thumb"] # always store results in cache and return results self._mutils.cache.set(cache_str, details) return details
def get_album_metadata(self, artist, album, track, disc, ignore_cache=False, flush_cache=False, manual=False): '''collect all album metadata''' cache_str = "music_artwork.album.%s.%s.%s" % (artist.lower(), album.lower(), disc.lower()) if not album: cache_str = "music_artwork.album.%s.%s" % (artist.lower(), track.lower()) details = {"art": {}} details["cachestr"] = cache_str # retrieve details from cache cache = self.metadatautils.cache.get(cache_str) if not cache and flush_cache: # nothing to do - just return empty results return details elif cache and flush_cache: # only update kodi metadata for updated counts etc details = extend_dict(self.get_album_kodi_metadata(artist, album, track, disc), cache) elif cache and not ignore_cache: # we have a valid cache - return that details = cache elif cache and manual: # user wants to manually override the artwork in the cache details = self.manual_set_music_artwork(cache, "album") else: # nothing in cache - start metadata retrieval local_path = "" local_path_custom = "" # get metadata from kodi db details = extend_dict(details, self.get_album_kodi_metadata(artist, album, track, disc)) # get artwork from songlevel path if details.get("diskpath") and self.metadatautils.addon.getSetting("music_art_musicfolders") == "true": details["art"] = extend_dict(details["art"], self.lookup_albumart_in_folder(details["diskpath"])) local_path = details["diskpath"] # get artwork from custom folder if self.metadatautils.addon.getSetting("music_art_custom") == "true": custom_path = self.metadatautils.addon.getSetting("music_art_custom_path").decode("utf-8") if custom_path: diskpath = self.get_custom_album_path(custom_path, artist, album, disc) if diskpath: details["art"] = extend_dict(details["art"], self.lookup_albumart_in_folder(diskpath)) local_path_custom = diskpath details["customartpath"] = diskpath # lookup online metadata if self.metadatautils.addon.getSetting("music_art_scraper") == "true": # prefer the musicbrainzid that is already in the kodi database - only perform lookup if missing mb_albumid = details.get("musicbrainzalbumid") if not mb_albumid: mb_albumid = self.get_mb_album_id(artist, album, track) if mb_albumid: # get artwork from fanarttv if self.metadatautils.addon.getSetting("music_art_scraper_fatv") == "true": details["art"] = extend_dict(details["art"], self.metadatautils.fanarttv.album(mb_albumid)) # get metadata from theaudiodb if self.metadatautils.addon.getSetting("music_art_scraper_adb") == "true": details = extend_dict(details, self.audiodb.album_info(mb_albumid)) # get metadata from lastfm if self.metadatautils.addon.getSetting("music_art_scraper_lfm") == "true": details = extend_dict(details, self.lastfm.album_info(mb_albumid)) # metadata from musicbrainz if not details.get("year") or not details.get("genre"): details = extend_dict(details, self.mbrainz.get_albuminfo(mb_albumid)) # musicbrainz thumb as last resort if not details["art"].get("thumb"): details["art"]["thumb"] = self.mbrainz.get_albumthumb(mb_albumid) # download artwork to music folder if local_path and self.metadatautils.addon.getSetting("music_art_download") == "true": details["art"] = download_artwork(local_path, details["art"]) # download artwork to custom folder if local_path_custom and self.metadatautils.addon.getSetting("music_art_download_custom") == "true": details["art"] = download_artwork(local_path_custom, details["art"]) # set default details if not details.get("album") and details.get("title"): details["album"] = details["title"] if details["art"].get("thumb"): details["art"]["albumthumb"] = details["art"]["thumb"] # store results in cache and return results self.metadatautils.cache.set(cache_str, details) return details
def get_artist_metadata(self, artist, album, track, ignore_cache=False, flush_cache=False, manual=False): '''collect artist metadata for given artist''' details = {"art": {}} cache_str = "music_artwork.artist.%s" % artist.lower() # retrieve details from cache cache = self.metadatautils.cache.get(cache_str) if not cache and flush_cache: # nothing to do - just return empty results return details elif cache and flush_cache: # only update kodi metadata for updated counts etc details = extend_dict(self.get_artist_kodi_metadata(artist), cache) elif cache and not ignore_cache: # we have a valid cache - return that details = cache elif cache and manual: # user wants to manually override the artwork in the cache details = self.manual_set_music_artwork(cache, "artist") else: # nothing in cache - start metadata retrieval log_msg("get_artist_metadata --> artist: %s - album: %s - track: %s" % (artist, album, track)) details["cachestr"] = cache_str local_path = "" local_path_custom = "" # get metadata from kodi db details = extend_dict(details, self.get_artist_kodi_metadata(artist)) # get artwork from songlevel path if details.get("diskpath") and self.metadatautils.addon.getSetting("music_art_musicfolders") == "true": details["art"] = extend_dict(details["art"], self.lookup_artistart_in_folder(details["diskpath"])) local_path = details["diskpath"] # get artwork from custom folder if self.metadatautils.addon.getSetting("music_art_custom") == "true": custom_path = self.metadatautils.addon.getSetting("music_art_custom_path").decode("utf-8") if custom_path: diskpath = self.get_customfolder_path(custom_path, artist) log_msg("custom path on disk for artist: %s --> %s" % (artist, diskpath)) if diskpath: details["art"] = extend_dict(details["art"], self.lookup_artistart_in_folder(diskpath)) local_path_custom = diskpath details["customartpath"] = diskpath # lookup online metadata if self.metadatautils.addon.getSetting("music_art_scraper") == "true": if not album and not track: album = details.get("ref_album") track = details.get("ref_track") # prefer the musicbrainzid that is already in the kodi database - only perform lookup if missing mb_artistid = details.get("musicbrainzartistid", self.get_mb_artist_id(artist, album, track)) details["musicbrainzartistid"] = mb_artistid if mb_artistid: # get artwork from fanarttv if self.metadatautils.addon.getSetting("music_art_scraper_fatv") == "true": details["art"] = extend_dict(details["art"], self.metadatautils.fanarttv.artist(mb_artistid)) # get metadata from theaudiodb if self.metadatautils.addon.getSetting("music_art_scraper_adb") == "true": details = extend_dict(details, self.audiodb.artist_info(mb_artistid)) # get metadata from lastfm if self.metadatautils.addon.getSetting("music_art_scraper_lfm") == "true": details = extend_dict(details, self.lastfm.artist_info(mb_artistid)) # download artwork to music folder if local_path and self.metadatautils.addon.getSetting("music_art_download") == "true": details["art"] = download_artwork(local_path, details["art"]) # download artwork to custom folder if local_path_custom and self.metadatautils.addon.getSetting("music_art_download_custom") == "true": details["art"] = download_artwork(local_path_custom, details["art"]) # fix extrafanart if details["art"].get("fanarts"): for count, item in enumerate(details["art"]["fanarts"]): details["art"]["fanart.%s" % count] = item if not details["art"].get("extrafanart") and len(details["art"]["fanarts"]) > 1: details["art"]["extrafanart"] = "plugin://script.skin.helper.service/"\ "?action=extrafanart&fanarts=%s" % quote_plus(repr(details["art"]["fanarts"])) # multi-image path for all images for each arttype for arttype in ["banners", "clearlogos", "thumbs"]: art = details["art"].get(arttype, []) if len(art) > 1: # use the extrafanart plugin entry to display multi images details["art"][arttype] = "plugin://script.skin.helper.service/"\ "?action=extrafanart&fanarts=%s" % quote_plus(repr(art)) # set default details if not details.get("artist"): details["artist"] = artist if details["art"].get("thumb"): details["art"]["artistthumb"] = details["art"]["thumb"] # always store results in cache and return results self.metadatautils.cache.set(cache_str, details) return details
def get_pvr_artwork(self, title, channel, genre="", manual_select=False, ignore_cache=False): """ collect full metadata and artwork for pvr entries parameters: title (required) channel: channel name (required) year: year or date (optional) genre: (optional) the more optional parameters are supplied, the better the search results """ details = {"art": {}} # try cache first cache_str = "pvr_artwork.%s.%s" % (title.lower(), channel.lower()) cache = self._mutils.cache.get(cache_str) if cache and not manual_select and not ignore_cache: log_msg("get_pvr_artwork - return data from cache - %s" % cache_str) details = cache else: # no cache - start our lookup adventure log_msg("get_pvr_artwork - no data in cache - start lookup - %s" % cache_str) # workaround for recordings recordingdetails = self.lookup_local_recording(title, channel) if recordingdetails and not (channel and genre): genre = recordingdetails["genre"] channel = recordingdetails["channel"] details["pvrtitle"] = title details["pvrchannel"] = channel details["pvrgenre"] = genre details["cachestr"] = cache_str details["media_type"] = "" details["art"] = {} # filter genre unknown/other if not genre or genre.split(" / ")[0] in xbmc.getLocalizedString( 19499).split(" / "): details["genre"] = [] genre = "" log_msg("genre is unknown so ignore....") else: details["genre"] = genre.split(" / ") details["media_type"] = self.get_mediatype_from_genre(genre) searchtitle = self.get_searchtitle(title, channel) # only continue if we pass our basic checks filterstr = self.pvr_proceed_lookup(title, channel, genre, recordingdetails) proceed_lookup = False if filterstr else True if not proceed_lookup and manual_select: # warn user about active skip filter proceed_lookup = xbmcgui.Dialog().yesno( line1=self._mutils.addon.getLocalizedString(32027), line2=filterstr, heading=xbmc.getLocalizedString(750)) if proceed_lookup: # if manual lookup get the title from the user if manual_select: if sys.version_info.major == 3: searchtitle = xbmcgui.Dialog().input( xbmc.getLocalizedString(16017), searchtitle, type=xbmcgui.INPUT_ALPHANUM) else: searchtitle = xbmcgui.Dialog().input( xbmc.getLocalizedString(16017), searchtitle, type=xbmcgui.INPUT_ALPHANUM).decode("utf-8") if not searchtitle: return # if manual lookup and no mediatype, ask the user if manual_select and not details["media_type"]: yesbtn = self._mutils.addon.getLocalizedString(32042) nobtn = self._mutils.addon.getLocalizedString(32043) header = self._mutils.addon.getLocalizedString(32041) if xbmcgui.Dialog().yesno(header, header, yeslabel=yesbtn, nolabel=nobtn): details["media_type"] = "movie" else: details["media_type"] = "tvshow" # append thumb from recordingdetails if recordingdetails and recordingdetails.get("thumbnail"): details["art"]["thumb"] = recordingdetails["thumbnail"] # lookup custom path details = extend_dict( details, self.lookup_custom_path(searchtitle, title)) # lookup movie/tv library details = extend_dict( details, self.lookup_local_library(searchtitle, details["media_type"])) # do internet scraping if enabled if self._mutils.addon.getSetting("pvr_art_scraper") == "true": log_msg( "pvrart start scraping metadata for title: %s - media_type: %s" % (searchtitle, details["media_type"])) # prefer tmdb scraper tmdb_result = self._mutils.get_tmdb_details( "", "", searchtitle, "", "", details["media_type"], manual_select=manual_select, ignore_cache=manual_select) log_msg("pvrart lookup for title: %s - TMDB result: %s" % (searchtitle, tmdb_result)) if tmdb_result: details["media_type"] = tmdb_result["media_type"] details = extend_dict(details, tmdb_result) # fallback to tvdb scraper if (not tmdb_result or (tmdb_result and not tmdb_result.get("art")) or details["media_type"] == "tvshow"): tvdb_match = self.lookup_tvdb( searchtitle, channel, manual_select=manual_select) log_msg( "pvrart lookup for title: %s - TVDB result: %s" % (searchtitle, tvdb_match)) if tvdb_match: # get full tvdb results and extend with tmdb if not details["media_type"]: details["media_type"] = "tvshow" details = extend_dict( details, self._mutils.thetvdb.get_series(tvdb_match)) details = extend_dict( details, self._mutils.tmdb. get_videodetails_by_externalid( tvdb_match, "tvdb_id"), ["poster", "fanart"]) # fanart.tv scraping - append result to existing art if details.get( "imdbnumber") and details["media_type"] == "movie": details["art"] = extend_dict( details["art"], self._mutils.fanarttv.movie(details["imdbnumber"]), ["poster", "fanart", "landscape"]) elif details.get( "tvdb_id") and details["media_type"] == "tvshow": details["art"] = extend_dict( details["art"], self._mutils.fanarttv.tvshow(details["tvdb_id"]), ["poster", "fanart", "landscape"]) # append omdb details if details.get("imdbnumber"): details = extend_dict( details, self._mutils.omdb.get_details_by_imdbid( details["imdbnumber"]), ["rating", "votes"]) # set thumbnail - prefer scrapers thumb = "" if details.get("thumbnail"): thumb = details["thumbnail"] elif details["art"].get("landscape"): thumb = details["art"]["landscape"] elif details["art"].get("fanart"): thumb = details["art"]["fanart"] elif details["art"].get("poster"): thumb = details["art"]["poster"] # use google images as last-resort fallback for thumbs - if enabled elif self._mutils.addon.getSetting( "pvr_art_google") == "true": if manual_select: google_title = searchtitle else: google_title = '%s %s' % ( searchtitle, channel.lower().split(" hd")[0]) thumb = self._mutils.google.search_image( google_title, manual_select) if thumb: details["thumbnail"] = thumb details["art"]["thumb"] = thumb # extrafanart if details["art"].get("fanarts"): for count, item in enumerate( details["art"]["fanarts"]): details["art"]["fanart.%s" % count] = item if not details["art"].get("extrafanart") and len( details["art"]["fanarts"]) > 1: details["art"]["extrafanart"] = "plugin://script.skin.helper.service/"\ "?action=extrafanart&fanarts=%s" % quote_plus(repr(details["art"]["fanarts"])) # download artwork to custom folder if self._mutils.addon.getSetting( "pvr_art_download") == "true": details["art"] = download_artwork( self.get_custom_path(searchtitle, title), details["art"]) log_msg("pvrart lookup for title: %s - final result: %s" % (searchtitle, details)) # always store result in cache # manual lookups should not expire too often if manual_select: self._mutils.cache.set(cache_str, details, expiration=timedelta(days=365)) else: self._mutils.cache.set(cache_str, details) return details
def test_extend_dict(): animals = {'cats': ['sam', 'john'], 'dogs': ['max']} u.extend_dict(animals, {'cats': ['tim'], 'dogs': ['lou']}) assert animals == {'cats': ['sam', 'john', 'tim'], 'dogs': ['max', 'lou']}
def get_info_object_layer(self, layer): self.actionsprites.add(layer.actionsprites) self.mobs.add(layer) self.hostiles.add([i for i in layer.sprites() if i.hostile]) extend_dict(self.player_spawns, layer.player_spawns) self.cameras.extend(layer.cameras)
def get_artists_metadata(self, artists, album, track, ignore_cache=False, flush_cache=False, manual=False): '''collect artist metadata for all artists''' artist_details = {"art": {}} # for multi artist songs/albums we grab details from all artists if len(artists) == 1: # single artist artist_details = self.get_artist_metadata( artists[0], album, track, ignore_cache=ignore_cache, flush_cache=flush_cache, manual=manual) artist_details["albumartist"] = artists[0] else: # multi-artist track # The first artist with details is considered the main artist # all others are assumed as featuring artists artist_details = {"art": {}} feat_artist_details = {"art": {}} for artist in artists: if not (artist_details.get("plot") or artist_details.get("art")): # get main artist details artist_details["albumartist"] = artist artist_details = self.get_artist_metadata( artist, album, track, ignore_cache=ignore_cache, manual=manual) else: # assume featuring artist feat_artist_details = extend_dict( feat_artist_details, self.get_artist_metadata(artist, album, track, ignore_cache=ignore_cache, manual=manual)) # combined images to use as multiimage (for all artists) # append featuring artist details for arttype in ["banners", "fanarts", "clearlogos", "thumbs"]: art = artist_details["art"].get(arttype, []) art += feat_artist_details["art"].get(arttype, []) if art: # use the extrafanart plugin entry to display multi images artist_details["art"][arttype] = "plugin://script.skin.helper.service/"\ "?action=extrafanart&fanarts=%s" % quote_plus(repr(art)) # also set extrafanart path if arttype == "fanarts": artist_details["art"]["extrafanart"] = artist_details[ "art"][arttype] # return the result return artist_details
def get_pvr_artwork(self, title, channel, genre="", manual_select=False, ignore_cache=False): ''' collect full metadata and artwork for pvr entries parameters: title (required) channel: channel name (required) year: year or date (optional) genre: (optional) the more optional parameters are supplied, the better the search results ''' details = {"art": {}} # try cache first cache_str = "pvr_artwork.%s.%s" % (title.lower(), channel.lower()) cache = self.metadatautils.cache.get(cache_str) if cache and not manual_select and not ignore_cache: log_msg("get_pvr_artwork - return data from cache - %s" % cache_str) details = cache else: # no cache - start our lookup adventure log_msg("get_pvr_artwork - no data in cache - start lookup - %s" % cache_str) # workaround for recordings recordingdetails = self.lookup_local_recording(title, channel) if recordingdetails and not (channel and genre): genre = recordingdetails["genre"] channel = recordingdetails["channel"] details["pvrtitle"] = title details["pvrchannel"] = channel details["pvrgenre"] = genre details["cachestr"] = cache_str details["media_type"] = "" details["art"] = {} # filter genre unknown/other if not genre or genre.split(" / ")[0] in xbmc.getLocalizedString(19499).split(" / "): details["genre"] = [] genre = "" log_msg("genre is unknown so ignore....") else: details["genre"] = genre.split(" / ") details["media_type"] = self.get_mediatype_from_genre(genre) searchtitle = self.get_searchtitle(title, channel) # only continue if we pass our basic checks filterstr = self.pvr_proceed_lookup(title, channel, genre, recordingdetails) proceed_lookup = False if filterstr else True if not proceed_lookup and manual_select: # warn user about active skip filter proceed_lookup = xbmcgui.Dialog().yesno( line1=self.metadatautils.addon.getLocalizedString(32027), line2=filterstr, heading=xbmc.getLocalizedString(750)) if proceed_lookup: # if manual lookup get the title from the user if manual_select: searchtitle = xbmcgui.Dialog().input(xbmc.getLocalizedString(16017), searchtitle, type=xbmcgui.INPUT_ALPHANUM).decode("utf-8") if not searchtitle: return # if manual lookup and no mediatype, ask the user if manual_select and not details["media_type"]: yesbtn = self.metadatautils.addon.getLocalizedString(32042) nobtn = self.metadatautils.addon.getLocalizedString(32043) header = self.metadatautils.addon.getLocalizedString(32041) if xbmcgui.Dialog().yesno(header, header, yeslabel=yesbtn, nolabel=nobtn): details["media_type"] = "movie" else: details["media_type"] = "tvshow" # append thumb from recordingdetails if recordingdetails and recordingdetails.get("thumbnail"): details["art"]["thumb"] = recordingdetails["thumbnail"] # lookup custom path details = extend_dict(details, self.lookup_custom_path(searchtitle, title)) # lookup movie/tv library details = extend_dict(details, self.lookup_local_library(searchtitle, details["media_type"])) # do internet scraping if enabled if self.metadatautils.addon.getSetting("pvr_art_scraper") == "true": log_msg( "pvrart start scraping metadata for title: %s - media_type: %s" % (searchtitle, details["media_type"])) # prefer tmdb scraper tmdb_result = self.metadatautils.get_tmdb_details( "", "", searchtitle, "", "", details["media_type"], manual_select=manual_select, ignore_cache=manual_select) log_msg("pvrart lookup for title: %s - TMDB result: %s" % (searchtitle, tmdb_result)) if tmdb_result: details["media_type"] = tmdb_result["media_type"] details = extend_dict(details, tmdb_result) # fallback to tvdb scraper if (not tmdb_result or (tmdb_result and not tmdb_result.get("art")) or details["media_type"] == "tvshow"): tvdb_match = self.lookup_tvdb(searchtitle, channel, manual_select=manual_select) log_msg("pvrart lookup for title: %s - TVDB result: %s" % (searchtitle, tvdb_match)) if tvdb_match: # get full tvdb results and extend with tmdb if not details["media_type"]: details["media_type"] = "tvshow" details = extend_dict(details, self.metadatautils.thetvdb.get_series(tvdb_match)) details = extend_dict(details, self.metadatautils.tmdb.get_videodetails_by_externalid( tvdb_match, "tvdb_id"), ["poster", "fanart"]) # fanart.tv scraping - append result to existing art if details.get("imdbnumber") and details["media_type"] == "movie": details["art"] = extend_dict( details["art"], self.metadatautils.fanarttv.movie( details["imdbnumber"]), [ "poster", "fanart", "landscape"]) elif details.get("tvdb_id") and details["media_type"] == "tvshow": details["art"] = extend_dict( details["art"], self.metadatautils.fanarttv.tvshow( details["tvdb_id"]), [ "poster", "fanart", "landscape"]) # append omdb details if details.get("imdbnumber"): details = extend_dict( details, self.metadatautils.omdb.get_details_by_imdbid( details["imdbnumber"]), [ "rating", "votes"]) # set thumbnail - prefer scrapers thumb = "" if details.get("thumbnail"): thumb = details["thumbnail"] elif details["art"].get("landscape"): thumb = details["art"]["landscape"] elif details["art"].get("fanart"): thumb = details["art"]["fanart"] elif details["art"].get("poster"): thumb = details["art"]["poster"] # use google images as last-resort fallback for thumbs - if enabled elif self.metadatautils.addon.getSetting("pvr_art_google") == "true": if manual_select: google_title = searchtitle else: google_title = '%s %s' % (searchtitle, channel.lower().split(" hd")[0]) thumb = self.metadatautils.google.search_image(google_title, manual_select) if thumb: details["thumbnail"] = thumb details["art"]["thumb"] = thumb # extrafanart if details["art"].get("fanarts"): for count, item in enumerate(details["art"]["fanarts"]): details["art"]["fanart.%s" % count] = item if not details["art"].get("extrafanart") and len(details["art"]["fanarts"]) > 1: details["art"]["extrafanart"] = "plugin://script.skin.helper.service/"\ "?action=extrafanart&fanarts=%s" % quote_plus(repr(details["art"]["fanarts"])) # download artwork to custom folder if self.metadatautils.addon.getSetting("pvr_art_download") == "true": details["art"] = download_artwork(self.get_custom_path(searchtitle, title), details["art"]) log_msg("pvrart lookup for title: %s - final result: %s" % (searchtitle, details)) # store result in cache and return details # always re-store in cache to prevent the cache from expiring self.metadatautils.cache.set(cache_str, details) return details