public bool TryGetFanArt(FanArtConstants.FanArtMediaType mediaType, FanArtConstants.FanArtType fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <FanArtImage> result) { result = null; if (mediaType != FanArtConstants.FanArtMediaType.Album || fanArtType != FanArtConstants.FanArtType.Poster || string.IsNullOrEmpty(name)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new RelationalFilter(AudioAspect.ATTR_ALBUM, RelationalOperator.EQ, name); MediaItemQuery query = new MediaItemQuery(NECESSARY_MIAS, filter); var items = mediaLibrary.Search(query, false); result = new List <FanArtImage>(); foreach (var mediaItem in items) { byte[] textureData; if (!MediaItemAspect.TryGetAttribute(mediaItem.Aspects, ThumbnailLargeAspect.ATTR_THUMBNAIL, out textureData)) { continue; } // Only one record required result.Add(new FanArtImage(name, textureData)); return(true); } return(true); }
protected bool TryGetMediaItem(string name, out MediaItem mediaItem) { mediaItem = null; Guid mediaItemId; if (!Guid.TryParse(name, out mediaItemId) || mediaItemId == Guid.Empty) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, filter), false, null, true); if (items == null || items.Count == 0) { return(false); } mediaItem = items.First(); return(true); }
/// <summary> /// Checks whether the <paramref name="action"/> has any aspects and if not /// tries to restore them from the media library. /// </summary> /// <param name="action">The action to check.</param> /// <returns>True if the aspects were present or successfully restored.</returns> protected async Task <bool> TryRestoreAspects(FanArtManagerAction action) { //Already has aspects, nothing to do if (action.Aspects != null) { return(true); } //No aspects, this resource was restored from disk, try and restore the aspects from the media library. //Throttle the number of concurrent queries To avoid a spike during startup. await _loadItemThrottle.WaitAsync(_cts.Token); try { IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(); MediaItemQuery query = new MediaItemQuery(null, mediaLibrary.GetManagedMediaItemAspectMetadata().Keys, new MediaItemIdFilter(action.MediaItemId)); var items = mediaLibrary.Search(query, false, null, true); if (items != null && items.Count > 0) { action.Aspects = items[0].Aspects; return(true); } ServiceRegistration.Get <ILogger>().Warn("FanArtActionBlock: Unable to restore FanArtAction, media item with id {0} was not found in the media library", action.MediaItemId); return(false); } finally { _loadItemThrottle.Release(); } }
public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <FanArtImage> result) { result = null; Guid mediaItemId; var isImage = mediaType == FanArtMediaTypes.Image; if (!Guid.TryParse(name, out mediaItemId) || mediaType != FanArtMediaTypes.Undefined && !isImage || fanArtType != FanArtTypes.Thumbnail) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } // Try to load thumbnail from ML List <Guid> thumbGuids = new List <Guid> { ThumbnailLargeAspect.ASPECT_ID }; // Check for Image's rotation info if (isImage) { thumbGuids.Add(ImageAspect.ASPECT_ID); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(thumbGuids, filter), false, null, true); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); byte[] textureData; if (!MediaItemAspect.TryGetAttribute(mediaItem.Aspects, ThumbnailLargeAspect.ATTR_THUMBNAIL, out textureData)) { return(false); } if (isImage) { textureData = AutoRotateThumb(mediaItem, textureData); } // Only one record required result = new List <FanArtImage> { new FanArtImage(name, textureData) }; return(true); }
/// <summary> /// Checks whether the <paramref name="actions"/> has any aspects and if not /// tries to load them from the media library. /// </summary> /// <param name="actions">The action to check.</param> /// <returns>True if the aspects were present or successfully loaded.</returns> protected async Task LoadAspects(FanArtManagerAction[] actions) { var mediaItemIds = actions.Where(a => a.Type == ActionType.Collect && (a.Aspects == null || a.Aspects.Count == 0)) .Select(a => a.MediaItemId).Distinct(); var queryFilter = new MediaItemIdFilter(mediaItemIds); if (queryFilter.MediaItemIds.Count == 0) { return; } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(); MediaItemQuery query = new MediaItemQuery(null, mediaLibrary.GetManagedMediaItemAspectMetadata().Keys, queryFilter); // Throttle the number of concurrent queries To avoid spikes when loading aspects. await _loadItemThrottle.WaitAsync(_cts.Token); try { var items = mediaLibrary.Search(query, false, null, true); if (items != null && items.Count > 0) { foreach (var item in items) { foreach (var action in actions) { if (action.MediaItemId == item.MediaItemId) { action.Aspects = item.Aspects; break; } } } } else { ServiceRegistration.Get <ILogger>().Warn("FanArtActionBlock: Unable to load aspects, no matching media items were found in the media library"); } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("FanArtActionBlock: Error loading aspects from the media library", ex); } finally { _loadItemThrottle.Release(); } }
private IList <MediaItem> GetItems(string sortCriteria) { IMediaLibrary library = ServiceRegistration.Get <IMediaLibrary>(); IFilter filter = new FilteredRelationshipFilter(_role, _linkedRole, AppendUserFilter(null, _necessaryMIAs)); MediaItemQuery query = new MediaItemQuery(NECESSARY_PERSON_MIA_TYPE_IDS, filter) { SortInformation = new List <ISortInformation> { new AttributeSortInformation(PersonAspect.ATTR_PERSON_NAME, SortDirection.Ascending) }, }; return(library.Search(query, true, UserId, false)); }
public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <FanArtImage> result) { result = null; if ((mediaType != FanArtMediaTypes.Album && mediaType != FanArtMediaTypes.Audio) || (fanArtType != FanArtTypes.Poster && fanArtType != FanArtTypes.Cover) || string.IsNullOrEmpty(name)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = BooleanCombinationFilter.CombineFilters(BooleanOperator.Or, new MediaItemIdFilter(new Guid(name)), new RelationshipFilter(AudioAlbumAspect.ROLE_ALBUM, AudioAspect.ROLE_TRACK, new Guid(name))); MediaItemQuery query = new MediaItemQuery(NECESSARY_MIAS, OPTIONAL_MIAS, filter) { Limit = 1, // Only one needed }; var items = mediaLibrary.Search(query, false, null, true); result = new List <FanArtImage>(); foreach (var mediaItem in items) { byte[] textureData; if (!MediaItemAspect.TryGetAttribute(mediaItem.Aspects, ThumbnailLargeAspect.ATTR_THUMBNAIL, out textureData)) { continue; } // Only one record required result.Add(new FanArtImage(name, textureData)); return(true); } return(false); }
public virtual IList <MediaItem> GetItems(string sortCriteria) { IMediaLibrary library = ServiceRegistration.Get <IMediaLibrary>(); //TODO: Check if this is correct handling of missing filter List <IFilter> filters = new List <IFilter>(); if (_filter != null) { filters.Add(_filter); } if (MediaItemId.HasValue) { filters.Add(new RelationalFilter(ProviderResourceAspect.ATTR_PARENT_DIRECTORY_ID, RelationalOperator.EQ, MediaItemId.Value)); } IFilter filter = BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filters); var query = new MediaItemQuery(_necessaryMiaTypeIds, _optionalMiaTypeIds, AppendUserFilter(filter, _necessaryMiaTypeIds)); query.Limit = _queryLimit; query.SortInformation = _sortInformation; return(library.Search(query, true, UserId, false)); }
public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <FanArtImage> result) { result = null; if ((mediaType != FanArtMediaTypes.Episode && mediaType != FanArtMediaTypes.Movie) || (fanArtType != FanArtTypes.Thumbnail && fanArtType != FanArtTypes.Undefined)) { return(false); } Guid mediaItemId; if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, filter), false, null, true); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var resourceLocator = mediaItem.GetResourceLocator(); string fileSystemPath = string.Empty; // File based access try { using (var accessor = resourceLocator?.CreateAccessor()) { ILocalFsResourceAccessor lfsra = accessor as ILocalFsResourceAccessor; if (lfsra != null) { // Check for a reasonable time offset int defaultVideoOffset = 720; long videoDuration; double width = 0; double height = 0; double downscale = 7.5; // Reduces the HD video frame size to a quarter size to around 256 IList <MultipleMediaItemAspect> videoAspects; if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, VideoStreamAspect.Metadata, out videoAspects)) { if ((videoDuration = videoAspects[0].GetAttributeValue <long>(VideoStreamAspect.ATTR_DURATION)) > 0) { if (defaultVideoOffset > videoDuration * DEFAULT_OPENCV_THUMBNAIL_OFFSET) { defaultVideoOffset = Convert.ToInt32(videoDuration * DEFAULT_OPENCV_THUMBNAIL_OFFSET); } } width = videoAspects[0].GetAttributeValue <int>(VideoStreamAspect.ATTR_WIDTH); height = videoAspects[0].GetAttributeValue <int>(VideoStreamAspect.ATTR_HEIGHT); downscale = width / 256.0; //256 is max size of large thumbnail aspect } var sw = Stopwatch.StartNew(); using (VideoCapture capture = new VideoCapture()) { capture.Open(lfsra.LocalFileSystemPath); int capturePos = defaultVideoOffset * 1000; if (capture.FrameCount > 0 && capture.Fps > 0) { var duration = capture.FrameCount / capture.Fps; if (defaultVideoOffset > duration) { capturePos = Convert.ToInt32(duration * DEFAULT_OPENCV_THUMBNAIL_OFFSET * 1000); } } if (capture.FrameWidth > 0) { downscale = capture.FrameWidth / MAX_THUMBNAIL_WIDTH; } capture.PosMsec = capturePos; using (var mat = capture.RetrieveMat()) { if (mat.Height > 0 && mat.Width > 0) { width = mat.Width; height = mat.Height; using (var scaledMat = mat.Resize(new OpenCvSharp.Size(width / downscale, height / downscale))) { var binary = scaledMat.ToBytes(); result = new List <FanArtImage> { new FanArtImage(name, binary) }; ServiceRegistration.Get <ILogger>().Debug("OpenCvFanartProvider: Successfully extracted thumbnail for resource '{0}' ({1} ms)", lfsra.LocalFileSystemPath, sw.ElapsedMilliseconds); return(true); } } else { ServiceRegistration.Get <ILogger>().Warn("OpenCvFanartProvider: Failed to extract thumbnail for resource '{0}'", lfsra.LocalFileSystemPath); } } } } } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Warn("OpenCvFanartProvider: Exception while reading thumbnail of type '{0}' from '{1}'", ex, fanArtType, fileSystemPath); } return(false); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.SeriesSeason && mediaType != FanArtMediaTypes.Episode) { return(false); } // Don't try to load "fanart" for images if (!Guid.TryParse(name, out mediaItemId) || mediaType == FanArtMediaTypes.Image) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = null; if (mediaType == FanArtMediaTypes.SeriesSeason) { filter = new RelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeasonAspect.ROLE_SEASON, mediaItemId); } else if (mediaType == FanArtMediaTypes.Episode) { filter = new MediaItemIdFilter(mediaItemId); } MediaItemQuery episodeQuery = new MediaItemQuery(NECESSARY_MIAS, filter); episodeQuery.Limit = 1; IList <MediaItem> items = mediaLibrary.Search(episodeQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var mediaItemParentDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); var mediaItemExtension = ResourcePathHelper.GetExtension(mediaItemPath.ToString()); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "thumb" select potentialFanArtFile); } if (fanArtType == FanArtTypes.Poster) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "poster" || potentialFanArtFileNameWithoutExtension == "folder" select potentialFanArtFile); } if (fanArtType == FanArtTypes.Logo) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "logo" select potentialFanArtFile); } if (fanArtType == FanArtTypes.ClearArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "clearart" select potentialFanArtFile); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "banner" select potentialFanArtFile); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "backdrop" || potentialFanArtFileNameWithoutExtension == "fanart" select potentialFanArtFile); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemParentDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); int?season = null; MediaItemAspect.TryGetAttribute(mediaItem.Aspects, EpisodeAspect.ATTR_SEASON, out season); if (season.HasValue) { List <string> prefixes = new List <string>(); prefixes.Add(string.Format("season{0:00}-", season.Value)); if (season.Value == 0) { prefixes.Add("season-specials-"); } else { prefixes.Add("season-all-"); } prefixes.Add(""); //For finding series fallback foreach (string prefix in prefixes) { if (fanArtPaths.Count == 0 && fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == prefix + "thumb" select potentialFanArtFile); } if (fanArtPaths.Count == 0 && fanArtType == FanArtTypes.Poster) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == prefix + "poster" select potentialFanArtFile); } if (fanArtPaths.Count == 0 && fanArtType == FanArtTypes.Logo) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == prefix + "logo" select potentialFanArtFile); } if (fanArtPaths.Count == 0 && fanArtType == FanArtTypes.ClearArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == prefix + "clearart" select potentialFanArtFile); } if (fanArtPaths.Count == 0 && fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == prefix + "banner" select potentialFanArtFile); } if (fanArtPaths.Count == 0 && fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == prefix + "fanart" select potentialFanArtFile); } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalSeasonFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.MovieCollection) { return(false); } // Don't try to load "fanart" for images if (!Guid.TryParse(name, out mediaItemId) || mediaType == FanArtMediaTypes.Image) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new RelationshipFilter(MovieAspect.ROLE_MOVIE, MovieCollectionAspect.ROLE_MOVIE_COLLECTION, mediaItemId); MediaItemQuery movieQuery = new MediaItemQuery(NECESSARY_MIAS, filter); IList <MediaItem> items = mediaLibrary.Search(movieQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } var files = new List <IResourceLocator>(); foreach (MediaItem mediaItem in items) { // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { continue; } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var mediaItemCollectionDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "movieset-poster" select potentialFanArtFile); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "movieset-banner" select potentialFanArtFile); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "movieset-fanart" select potentialFanArtFile); } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemCollectionDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "poster" || potentialFanArtFileNameWithoutExtension == "folder" || potentialFanArtFileNameWithoutExtension == "movieset-poster" || potentialFanArtFileNameWithoutExtension.EndsWith("-poster") select potentialFanArtFile); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "banner" || potentialFanArtFileNameWithoutExtension == "movieset-banner" || potentialFanArtFileNameWithoutExtension.EndsWith("-banner") select potentialFanArtFile); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "backdrop" || potentialFanArtFileNameWithoutExtension == "fanart" || potentialFanArtFileNameWithoutExtension == "movieset-fanart" || potentialFanArtFileNameWithoutExtension.EndsWith("-fanart") select potentialFanArtFile); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalMovieCollectionFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } if (files.Count > 0) { break; } } if (files.Count == 0) { foreach (MediaItem mediaItem in items) { // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { continue; } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "poster" || potentialFanArtFileNameWithoutExtension == "folder" || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-poster") select potentialFanArtFile); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "banner" || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-banner") select potentialFanArtFile); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "backdrop" || potentialFanArtFileNameWithoutExtension == "fanart" || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-fanart") select potentialFanArtFile); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalMovieCollectionFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } if (files.Count > 0) { break; } } } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.Artist && mediaType != FanArtMediaTypes.Album && mediaType != FanArtMediaTypes.Audio) { return(false); } // Don't try to load "fanart" for images if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = null; IList <MediaItem> items = null; List <Guid> necessaryMias = new List <Guid>(NECESSARY_MIAS); if (mediaType == FanArtMediaTypes.Artist) { necessaryMias.Add(AudioAspect.ASPECT_ID); necessaryMias.Add(RelationshipAspect.ASPECT_ID); filter = new RelationshipFilter(AudioAspect.ROLE_TRACK, PersonAspect.ROLE_ALBUMARTIST, mediaItemId); } else if (fanArtType == FanArtTypes.FanArt) { if (mediaType == FanArtMediaTypes.Album) { //Might be a request for album FanArt which doesn't exist. Artist FanArt is used instead. filter = new RelationshipFilter(AudioAspect.ROLE_TRACK, AudioAlbumAspect.ROLE_ALBUM, mediaItemId); } else if (mediaType == FanArtMediaTypes.Audio) { //Might be a request for track FanArt which doesn't exist. Artist FanArt is used instead. necessaryMias.Add(AudioAspect.ASPECT_ID); filter = new MediaItemIdFilter(mediaItemId); } } else { return(false); } MediaItemQuery mediaQuery = new MediaItemQuery(necessaryMias, filter); mediaQuery.Limit = 1; items = mediaLibrary.Search(mediaQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); string artistName = null; var mediaItemPath = mediaIteamLocator.NativeResourcePath; var albumMediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var artistMediaItemPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); string album = null; if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, AudioAspect.ATTR_ALBUM, out album) && LocalFanartHelper.IsDiscFolder(album, albumMediaItemDirectoryPath.FileName)) { //Probably a CD folder so try next parent albumMediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); artistMediaItemPath = ResourcePathHelper.Combine(mediaItemPath, "../../../"); } if (mediaType == FanArtMediaTypes.Artist) { SingleMediaItemAspect audioAspect; List <string> artists = new List <string>(); if (MediaItemAspect.TryGetAspect(mediaItem.Aspects, AudioAspect.Metadata, out audioAspect)) { IEnumerable <object> artistObjects = audioAspect.GetCollectionAttribute <object>(AudioAspect.ATTR_ALBUMARTISTS); if (artistObjects != null) { artists.AddRange(artistObjects.Cast <string>()); } } IList <MultipleMediaItemAspect> relationAspects; if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ALBUMARTIST && (Guid?)relation[RelationshipAspect.ATTR_LINKED_ID] == mediaItemId) { int?index = (int?)relation[RelationshipAspect.ATTR_RELATIONSHIP_INDEX]; if (index.HasValue && artists.Count > index.Value && index.Value >= 0) { artistName = artists[index.Value]; } break; } } } } // File based access try { var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); var mediaItemExtension = ResourcePathHelper.GetExtension(mediaItemPath.ToString()); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, artistMediaItemPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Undefined || fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.ARTIST_FILENAMES)); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES)); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES)); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES)); } if (fanArtType == FanArtTypes.Logo) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.LOGO_FILENAMES)); } if (fanArtType == FanArtTypes.ClearArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.CLEARART_FILENAMES)); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES)); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } if (!string.IsNullOrEmpty(artistName)) //Only one artist was found { using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, albumMediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { //Get Artists thumbs IFileSystemResourceAccessor alternateArtistMediaItemDirectory = directoryFsra.GetResource(".artists"); if (alternateArtistMediaItemDirectory != null) { var potentialArtistFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(alternateArtistMediaItemDirectory); foreach (ResourcePath thumbPath in from potentialFanArtFile in potentialArtistFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()) where potentialFanArtFileNameWithoutExtension.StartsWith(artistName.Replace(" ", "_"), StringComparison.InvariantCultureIgnoreCase) select potentialFanArtFile) { files.Add(new ResourceLocator(mediaIteamLocator.NativeSystemId, thumbPath)); } } } } //Find central artist information folder ResourcePath centralArtistFolderPath = LocalFanartHelper.GetCentralPersonFolder(artistMediaItemPath, CentralPersonFolderType.AudioArtists); if (centralArtistFolderPath != null) { // First get the ResourcePath of the central directory var artistFolderPath = ResourcePathHelper.Combine(centralArtistFolderPath, $"{LocalFanartHelper.GetSafePersonFolderName(artistName)}/"); // Then try to create an IFileSystemResourceAccessor for this directory artistFolderPath.TryCreateLocalResourceAccessor(out var artistNfoDirectoryRa); var directoryFsra = artistNfoDirectoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.ARTIST_FILENAMES)); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES)); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES)); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES)); } if (fanArtType == FanArtTypes.Logo) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.LOGO_FILENAMES)); } if (fanArtType == FanArtTypes.ClearArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.CLEARART_FILENAMES)); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES)); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalArtistFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.Actor || (fanArtType != FanArtTypes.Undefined && fanArtType != FanArtTypes.Thumbnail)) { return(false); } // Don't try to load "fanart" for images if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new RelationshipFilter(EpisodeAspect.ROLE_EPISODE, PersonAspect.ROLE_ACTOR, mediaItemId); IList <MediaItem> items = null; List <Guid> necessaryMias = new List <Guid>(NECESSARY_MIAS); MediaItemQuery mediaQuery = new MediaItemQuery(necessaryMias, filter); mediaQuery.Limit = 1; items = mediaLibrary.Search(mediaQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); var mediaIteamLocator = mediaItem.GetResourceLocator(); // Virtual resources won't have any local fanart if (mediaIteamLocator.NativeResourcePath.BasePathSegment.ProviderId == VirtualResourceProvider.VIRTUAL_RESOURCE_PROVIDER_ID) { return(false); } var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); string actorName = null; SingleMediaItemAspect videoAspect; List <string> actors = new List <string>(); if (MediaItemAspect.TryGetAspect(mediaItem.Aspects, VideoAspect.Metadata, out videoAspect)) { IEnumerable <object> actorObjects = videoAspect.GetCollectionAttribute <object>(VideoAspect.ATTR_ACTORS); if (actorObjects != null) { actors.AddRange(actorObjects.Cast <string>()); } } IList <MultipleMediaItemAspect> relationAspects; if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ACTOR && (Guid?)relation[RelationshipAspect.ATTR_LINKED_ID] == mediaItemId) { int?index = (int?)relation[RelationshipAspect.ATTR_RELATIONSHIP_INDEX]; if (index.HasValue && actors.Count > index.Value && index.Value >= 0) { actorName = actors[index.Value]; } } } } // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var seasonMediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var seriesMediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); if (!string.IsNullOrEmpty(actorName)) { using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, seriesMediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { //Get Artists thumbs IFileSystemResourceAccessor actorMediaItemDirectory = directoryFsra.GetResource(".actors"); if (actorMediaItemDirectory != null) { var potentialArtistFanArtFiles = GetPotentialFanArtFiles(actorMediaItemDirectory); foreach (ResourcePath thumbPath in from potentialFanArtFile in potentialArtistFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()) where potentialFanArtFileNameWithoutExtension.StartsWith(actorName.Replace(" ", "_"), StringComparison.InvariantCultureIgnoreCase) select potentialFanArtFile) { files.Add(new ResourceLocator(mediaIteamLocator.NativeSystemId, thumbPath)); } } } } using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, seasonMediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { //Get Artists thumbs IFileSystemResourceAccessor actorMediaItemDirectory = directoryFsra.GetResource(".actors"); if (actorMediaItemDirectory != null) { var potentialArtistFanArtFiles = GetPotentialFanArtFiles(actorMediaItemDirectory); foreach (ResourcePath thumbPath in from potentialFanArtFile in potentialArtistFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension.StartsWith(actorName.Replace(" ", "_")) select potentialFanArtFile) { files.Add(new ResourceLocator(mediaIteamLocator.NativeSystemId, thumbPath)); } } } } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalSeriesActorFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(FanArtConstants.FanArtMediaType mediaType, FanArtConstants.FanArtType fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; // Don't try to load "fanart" for images if (!Guid.TryParse(name, out mediaItemId) || mediaType == FanArtConstants.FanArtMediaType.Image) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(_necessarryMIAs, filter), false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); string fileSystemPath = null; List <string> localPatterns = new List <string>(); List <IResourceLocator> files = new List <IResourceLocator>(); // File based access try { var resourceLocator = mediaItem.GetResourceLocator(); using (var accessor = resourceLocator.CreateAccessor()) { ILocalFsResourceAccessor fsra = accessor as ILocalFsResourceAccessor; if (fsra != null) { fileSystemPath = fsra.LocalFileSystemPath; var path = Path.GetDirectoryName(fileSystemPath); var file = Path.GetFileNameWithoutExtension(fileSystemPath); if (fanArtType == FanArtConstants.FanArtType.Poster || fanArtType == FanArtConstants.FanArtType.Thumbnail) { localPatterns.Add(Path.ChangeExtension(fileSystemPath, ".jpg")); localPatterns.Add(Path.Combine(path, file + "-poster.jpg")); localPatterns.Add(Path.Combine(path, "folder.jpg")); } if (fanArtType == FanArtConstants.FanArtType.FanArt) { localPatterns.Add(Path.Combine(path, "backdrop.jpg")); localPatterns.Add(Path.Combine(path, file + "-fanart*.jpg")); localPatterns.Add(Path.Combine(path, "ExtraFanArt\\*.jpg")); } // Copy all patterns for .jpg -> .png + .tbn localPatterns.AddRange(new List <string>(localPatterns).Select(p => p.Replace(".jpg", ".png"))); localPatterns.AddRange(new List <string>(localPatterns).Select(p => p.Replace(".jpg", ".tbn"))); foreach (var pattern in localPatterns) { try { var pathPart = Path.GetDirectoryName(pattern); var filePart = Path.GetFileName(pattern); DirectoryInfo directoryInfo = new DirectoryInfo(pathPart); if (directoryInfo.Exists) { files.AddRange(directoryInfo.GetFiles(filePart) .Select(f => f.FullName) .Select(fileName => new ResourceLocator(resourceLocator.NativeSystemId, ResourcePath.BuildBaseProviderPath(resourceLocator.NativeResourcePath.LastPathSegment.ProviderId, fileName)))); } } catch { } } } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("Error while search fanart of type '{0}' for path '{1}'", ex, fanArtType, fileSystemPath); #endif } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (!Guid.TryParse(name, out mediaItemId)) { return(false); } if (mediaType == FanArtMediaTypes.Image && fanArtType != FanArtTypes.FanArt) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, filter), false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var mediaIteamLocator = mediaItem.GetResourceLocator(); if (mediaIteamLocator == null) { return(false); } var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); var mediaItemExtension = ResourcePathHelper.GetExtension(mediaItemPath.ToString()); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Undefined || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES, LocalFanartHelper.THUMB_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where /* Allow same file name only for non-images, otherwise each image would be its own thumbnail */ potentialFanArtFileNameWithoutExtension == mediaItemFileNameWithoutExtension && !LocalFanartHelper.EXTENSIONS.Contains(mediaItemExtension) select potentialFanArtFile); } if (fanArtType == FanArtTypes.Poster) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES, LocalFanartHelper.POSTER_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where /* Allow same file name only for non-images, otherwise each image would be its own thumbnail */ potentialFanArtFileNameWithoutExtension == mediaItemFileNameWithoutExtension && !LocalFanartHelper.EXTENSIONS.Contains(mediaItemExtension) select potentialFanArtFile); } if (fanArtType == FanArtTypes.Logo) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.LOGO_FILENAMES, LocalFanartHelper.LOGO_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); } if (fanArtType == FanArtTypes.ClearArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.CLEARART_FILENAMES, LocalFanartHelper.CLEARART_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); } if (fanArtType == FanArtTypes.DiscArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.DISCART_FILENAMES, LocalFanartHelper.DISCART_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES, LocalFanartHelper.BANNER_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); } if (fanArtType == FanArtTypes.FanArt) { if (mediaType == FanArtMediaTypes.Image) { fanArtPaths.Add(mediaIteamLocator.NativeResourcePath); } else { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES, LocalFanartHelper.BACKDROP_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES)); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(FanArtConstants.FanArtMediaType mediaType, FanArtConstants.FanArtType fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; // Don't try to load "fanart" for images if (!Guid.TryParse(name, out mediaItemId) || mediaType == FanArtConstants.FanArtMediaType.Image) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, filter), false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtConstants.FanArtType.Poster || fanArtType == FanArtConstants.FanArtType.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()) where potentialFanArtFileNameWithoutExtension == mediaItemFileNameWithoutExtension || potentialFanArtFileNameWithoutExtension == mediaItemFileNameWithoutExtension + "-poster" || potentialFanArtFileNameWithoutExtension == "folder" select potentialFanArtFile); } if (fanArtType == FanArtConstants.FanArtType.FanArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()) where potentialFanArtFileNameWithoutExtension == "backdrop" || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-fanart") select potentialFanArtFile); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (!Guid.TryParse(name, out mediaItemId)) { return(false); } if (mediaType == FanArtMediaTypes.Image && fanArtType != FanArtTypes.FanArt) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, filter), false, null, true); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); var mediaIteamLocator = mediaItem.GetResourceLocator(); // Virtual resources won't have any local fanart if (mediaIteamLocator.NativeResourcePath.BasePathSegment.ProviderId == VirtualResourceProvider.VIRTUAL_RESOURCE_PROVIDER_ID) { return(false); } var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); var mediaItemExtension = ResourcePathHelper.GetExtension(mediaItemPath.ToString()); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where /* Allow same file name only for non-images, otherwise each image would be its own thumbnail */ potentialFanArtFileNameWithoutExtension == mediaItemFileNameWithoutExtension && !EXTENSIONS.Contains(mediaItemExtension) || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-thumb") || potentialFanArtFileNameWithoutExtension == "thumb" select potentialFanArtFile); } if (fanArtType == FanArtTypes.Poster) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where /* Allow same file name only for non-images, otherwise each image would be its own thumbnail */ potentialFanArtFileNameWithoutExtension == mediaItemFileNameWithoutExtension && !EXTENSIONS.Contains(mediaItemExtension) || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-poster") || potentialFanArtFileNameWithoutExtension == "poster" || potentialFanArtFileNameWithoutExtension == "folder" || potentialFanArtFileNameWithoutExtension == "cover" select potentialFanArtFile); } if (fanArtType == FanArtTypes.Logo) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "logo" || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-logo") select potentialFanArtFile); } if (fanArtType == FanArtTypes.ClearArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "clearart" || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-clearart") select potentialFanArtFile); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "banner" || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-banner") select potentialFanArtFile); } if (fanArtType == FanArtTypes.FanArt) { if (mediaType == FanArtMediaTypes.Image) { fanArtPaths.Add(mediaIteamLocator.NativeResourcePath); } else { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "backdrop" || potentialFanArtFileNameWithoutExtension == "fanart" || potentialFanArtFileNameWithoutExtension.StartsWith(mediaItemFileNameWithoutExtension + "-fanart") select potentialFanArtFile); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <FanArtImage> result) { result = null; Guid mediaItemId; if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, filter), false, null, true); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var resourceLocator = mediaItem.GetResourceLocator(); string fileSystemPath = string.Empty; IList <string> patterns = new List <string>(); switch (fanArtType) { case FanArtTypes.Banner: patterns.Add("banner."); break; case FanArtTypes.ClearArt: patterns.Add("clearart."); break; case FanArtTypes.Poster: case FanArtTypes.Thumbnail: patterns.Add("cover."); patterns.Add("poster."); patterns.Add("folder."); break; case FanArtTypes.FanArt: patterns.Add("backdrop."); patterns.Add("fanart."); break; case FanArtTypes.Logo: patterns.Add("clearlogo."); break; default: return(false); } // File based access try { using (var accessor = resourceLocator?.CreateAccessor()) { ILocalFsResourceAccessor fsra = accessor as ILocalFsResourceAccessor; if (fsra != null) { var ext = Path.GetExtension(fsra.LocalFileSystemPath); if (!SUPPORTED_EXTENSIONS.Contains(ext)) { return(false); } MatroskaBinaryReader mkvReader = new MatroskaBinaryReader(fsra); foreach (string pattern in patterns) { byte[] binaryData = mkvReader.GetAttachmentByNameAsync(pattern).Result; if (binaryData != null) { result = new List <FanArtImage> { new FanArtImage(name, binaryData) }; return(true); } } } } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Warn("MkvAttachmentsProvider: Exception while reading mkv attachment of type '{0}' from '{1}'", ex, fanArtType, fileSystemPath); } return(false); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.Series && mediaType != FanArtMediaTypes.SeriesSeason && mediaType != FanArtMediaTypes.Episode) { return(false); } if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = null; if (mediaType == FanArtMediaTypes.Series) { filter = new RelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, mediaItemId); } else if (mediaType == FanArtMediaTypes.SeriesSeason) { filter = new RelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeasonAspect.ROLE_SEASON, mediaItemId); } else if (mediaType == FanArtMediaTypes.Episode) { filter = new MediaItemIdFilter(mediaItemId); } MediaItemQuery episodeQuery = new MediaItemQuery(NECESSARY_MIAS, filter); episodeQuery.Limit = 1; IList <MediaItem> items = mediaLibrary.Search(episodeQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var mediaItemLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); // File based access try { var mediaItemPath = mediaItemLocator.NativeResourcePath; int seasonNo = -1; MediaItemAspect.TryGetAttribute(mediaItem.Aspects, EpisodeAspect.ATTR_SEASON, out seasonNo); var seasonFolderPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var seriesFolderPath = GetSeriesFolderFromEpisodePath(mediaItemLocator.NativeSystemId, mediaItemPath, seasonNo); bool hasSeasonFolders = seasonFolderPath != seriesFolderPath; //Episode FanArt if (mediaType == FanArtMediaTypes.Episode) { if (fanArtType == FanArtTypes.Undefined || fanArtType == FanArtTypes.Thumbnail) { AddEpisodeFanArt(fanArtPaths, fanArtType, mediaItemLocator.NativeSystemId, mediaItemPath); } else { AddSeriesFanArt(fanArtPaths, fanArtType, mediaItemLocator.NativeSystemId, seriesFolderPath); } } //Season FanArt if (mediaType == FanArtMediaTypes.SeriesSeason) { if (hasSeasonFolders) { AddSeriesFanArt(fanArtPaths, fanArtType, mediaItemLocator.NativeSystemId, seasonFolderPath); AddSpecialSeasonFolderFanArt(fanArtPaths, fanArtType, mediaItemLocator.NativeSystemId, seasonFolderPath, seasonNo); } else { AddSpecialSeasonFolderFanArt(fanArtPaths, fanArtType, mediaItemLocator.NativeSystemId, seasonFolderPath, seasonNo); } if (hasSeasonFolders && fanArtPaths.Count == 0) { //Series fallback AddSeriesFanArt(fanArtPaths, fanArtType, mediaItemLocator.NativeSystemId, seriesFolderPath); } } //Series FanArt if (mediaType == FanArtMediaTypes.Series) { AddSeriesFanArt(fanArtPaths, fanArtType, mediaItemLocator.NativeSystemId, seriesFolderPath); } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalSeriesFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaItemLocator); #endif } result = fanArtPaths.Select(p => (IResourceLocator) new ResourceLocator(mediaItemLocator.NativeSystemId, p)).ToList(); return(result.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.Undefined) { return(false); } if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = null; List <Guid> necessaryMias = new List <Guid>(NECESSARY_MIAS); MediaItemQuery mediaQuery = new MediaItemQuery(necessaryMias, filter); mediaQuery.Limit = 1; items = mediaLibrary.Search(mediaQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); // File based access try { var mediaItemDirectoryPath = mediaIteamLocator.NativeResourcePath; using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES)); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES)); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalContainerFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <FanArtImage> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.Album && mediaType != FanArtMediaTypes.Audio) { return(false); } if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = null; if (mediaType == FanArtMediaTypes.Album) { filter = new RelationshipFilter(AudioAspect.ROLE_TRACK, AudioAlbumAspect.ROLE_ALBUM, mediaItemId); } else if (mediaType == FanArtMediaTypes.Audio) { filter = new MediaItemIdFilter(mediaItemId); } MediaItemQuery mediaQuery = new MediaItemQuery(NECESSARY_MIAS, filter); mediaQuery.Limit = 1; IList <MediaItem> items = mediaLibrary.Search(mediaQuery, false, null, true); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var resourceLocator = mediaItem.GetResourceLocator(); string fileSystemPath = string.Empty; IList <PictureType> patterns = new List <PictureType>(); switch (fanArtType) { case FanArtTypes.Undefined: case FanArtTypes.Poster: case FanArtTypes.Cover: case FanArtTypes.Thumbnail: patterns.Add(PictureType.FrontCover); patterns.Add(PictureType.Other); break; default: return(false); } // File based access try { using (var accessor = resourceLocator?.CreateAccessor()) { ILocalFsResourceAccessor fsra = accessor as ILocalFsResourceAccessor; if (fsra != null) { fileSystemPath = fsra.LocalFileSystemPath; var ext = Path.GetExtension(fsra.LocalFileSystemPath); if (!SUPPORTED_EXTENSIONS.Contains(ext)) { return(false); } ByteVector.UseBrokenLatin1Behavior = true; // Otherwise we have problems retrieving non-latin1 chars using (var tag = TagLib.File.Create(fsra.LocalFileSystemPath)) { IPicture[] pics = tag.Tag.Pictures; if (pics.Length > 0) { foreach (var pattern in patterns) { var picTag = pics.FirstOrDefault(p => p.Type == pattern); if (picTag != null) { result = new List <FanArtImage> { new FanArtImage(name, picTag.Data.Data) }; return(true); } } //If no matching images found, use first images for thumbnails if (fanArtType == FanArtTypes.Thumbnail) { result = new List <FanArtImage> { new FanArtImage(name, pics[0].Data.Data) }; return(true); } } } } } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Warn("AudioTagProvider: Exception while reading tag of type '{0}' from '{1}'", ex, fanArtType, fileSystemPath); } return(false); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.MovieCollection) { return(false); } if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new RelationshipFilter(MovieAspect.ROLE_MOVIE, MovieCollectionAspect.ROLE_MOVIE_COLLECTION, mediaItemId); MediaItemQuery movieQuery = new MediaItemQuery(NECESSARY_MIAS, filter); IList <MediaItem> items = mediaLibrary.Search(movieQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } var files = new List <IResourceLocator>(); foreach (MediaItem mediaItem in items) { // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { continue; } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var mediaItemCollectionDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); var mediaItemCentralCollectionDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../" + MOVIESET_FANART_FOLDER); var mediaItemCentralCollectionDirectoryPath2 = ResourcePathHelper.Combine(mediaItemPath, "../../../" + MOVIESET_FANART_FOLDER); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Undefined || fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES.Select(f => "movieset-" + f))); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES.Select(f => "movieset-" + f))); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES.Select(f => "movieset-" + f))); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES.Select(f => "movieset-" + f))); } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemCollectionDirectoryPath).CreateAccessor()) { fanArtPaths.AddRange(GetCollectionFanart(fanArtType, directoryRa as IFileSystemResourceAccessor)); files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemCentralCollectionDirectoryPath).CreateAccessor()) { fanArtPaths.AddRange(GetCollectionFanart(fanArtType, directoryRa as IFileSystemResourceAccessor)); files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemCentralCollectionDirectoryPath2).CreateAccessor()) { fanArtPaths.AddRange(GetCollectionFanart(fanArtType, directoryRa as IFileSystemResourceAccessor)); files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalMovieCollectionFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } if (files.Count > 0) { break; } } if (files.Count == 0) { foreach (MediaItem mediaItem in items) { // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { continue; } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES, LocalFanartHelper.POSTER_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES, LocalFanartHelper.THUMB_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES, LocalFanartHelper.BANNER_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES, LocalFanartHelper.BACKDROP_FILENAMES.Select(f => mediaItemFileNameWithoutExtension + "-" + f))); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES)); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalMovieCollectionFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } if (files.Count > 0) { break; } } } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.Album && mediaType != FanArtMediaTypes.Audio) { return(false); } // Don't try to load "fanart" for images if (!Guid.TryParse(name, out mediaItemId) || mediaType == FanArtMediaTypes.Image) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = null; IList <MediaItem> items = null; List <Guid> necessaryMias = new List <Guid>(NECESSARY_MIAS); if (mediaType == FanArtMediaTypes.Album) { filter = new RelationshipFilter(AudioAspect.ROLE_TRACK, AudioAlbumAspect.ROLE_ALBUM, mediaItemId); } else if (mediaType == FanArtMediaTypes.Audio) { //Might be a request for track cover which doesn't exist. Album cover is used instead. filter = new MediaItemIdFilter(mediaItemId); } else { return(false); } MediaItemQuery mediaQuery = new MediaItemQuery(necessaryMias, filter); mediaQuery.Limit = 1; items = mediaLibrary.Search(mediaQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); string album = null; if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, AudioAspect.ATTR_ALBUM, out album) && LocalFanartHelper.IsDiscFolder(album, mediaItemDirectoryPath.FileName)) { //Probably a CD folder so try next parent mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); } var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); var mediaItemExtension = ResourcePathHelper.GetExtension(mediaItemPath.ToString()); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Cover || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "poster" || potentialFanArtFileNameWithoutExtension == "folder" || potentialFanArtFileNameWithoutExtension == "cover" select potentialFanArtFile); } if (fanArtType == FanArtTypes.DiscArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "discart" || potentialFanArtFileNameWithoutExtension == "disc" select potentialFanArtFile); } if (fanArtType == FanArtTypes.DiscArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "cdart" select potentialFanArtFile); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "backdrop" || potentialFanArtFileNameWithoutExtension == "fanart" select potentialFanArtFile); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalAlbumFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; if (!VALID_MEDIA_TYPES.Contains(mediaType) || !VALID_FANART_TYPES.Contains(fanArtType)) { return(false); } if (string.IsNullOrWhiteSpace(name)) { return(false); } Guid mediaItemId; if (Guid.TryParse(name, out mediaItemId) == false) { return(false); } List <string> fanArtFiles = new List <string>(); fanArtFiles.AddRange(FanArtCache.GetFanArtFiles(mediaItemId.ToString().ToUpperInvariant(), fanArtType)); // Try fallback if (fanArtFiles.Count == 0 && (mediaType == FanArtMediaTypes.SeriesSeason || mediaType == FanArtMediaTypes.Character || (mediaType == FanArtMediaTypes.Episode && fanArtType == FanArtTypes.FanArt))) { IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, OPTIONAL_MIAS, filter), false, null, true); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); if (mediaType == FanArtMediaTypes.Episode && fanArtType == FanArtTypes.FanArt) { if (mediaItem.Aspects.ContainsKey(EpisodeAspect.ASPECT_ID)) { IList <MultipleMediaItemAspect> relationAspects; if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { //Season fallback foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == SeasonAspect.ROLE_SEASON) { fanArtFiles.AddRange(FanArtCache.GetFanArtFiles(relation[RelationshipAspect.ATTR_LINKED_ID].ToString().ToUpperInvariant(), fanArtType)); if (fanArtFiles.Count > 0) { break; } } } //Series fallback if (fanArtFiles.Count == 0) { foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == SeriesAspect.ROLE_SERIES) { fanArtFiles.AddRange(FanArtCache.GetFanArtFiles(relation[RelationshipAspect.ATTR_LINKED_ID].ToString().ToUpperInvariant(), fanArtType)); if (fanArtFiles.Count > 0) { break; } } } } } } } else if (mediaType == FanArtMediaTypes.SeriesSeason) { if (mediaItem.Aspects.ContainsKey(SeasonAspect.ASPECT_ID)) { IList <MultipleMediaItemAspect> relationAspects; if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == SeriesAspect.ROLE_SERIES) { fanArtFiles.AddRange(FanArtCache.GetFanArtFiles(relation[RelationshipAspect.ATTR_LINKED_ID].ToString().ToUpperInvariant(), fanArtType)); if (fanArtFiles.Count > 0) { break; } } } } } } else if (mediaType == FanArtMediaTypes.Character) { if (mediaItem.Aspects.ContainsKey(CharacterAspect.ASPECT_ID)) { IList <MultipleMediaItemAspect> relationAspects; if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ACTOR) { fanArtFiles.AddRange(FanArtCache.GetFanArtFiles(relation[RelationshipAspect.ATTR_LINKED_ID].ToString().ToUpperInvariant(), fanArtType)); if (fanArtFiles.Count > 0) { break; } } } } } } } List <IResourceLocator> files = new List <IResourceLocator>(); try { files.AddRange(fanArtFiles .Select(fileName => new ResourceLocator(ResourcePath.BuildBaseProviderPath(LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID, fileName))) ); result = files; return(result.Count > 0); } catch (Exception) { } return(false); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; if (!VALID_MEDIA_TYPES.Contains(mediaType) || !VALID_FANART_TYPES.Contains(fanArtType)) { return(false); } if (string.IsNullOrWhiteSpace(name)) { return(false); } Guid mediaItemId; if (Guid.TryParse(name, out mediaItemId) == false) { return(false); } IFanArtCache fanArtCache = ServiceRegistration.Get <IFanArtCache>(); List <string> fanArtFiles = new List <string>(); fanArtFiles.AddRange(fanArtCache.GetFanArtFiles(mediaItemId, fanArtType)); if (fanArtFiles.Count == 0 && fanArtType == FanArtTypes.Poster) { fanArtFiles.AddRange(fanArtCache.GetFanArtFiles(mediaItemId, FanArtTypes.Cover)); } // Try fallback if (fanArtFiles.Count == 0 && (mediaType == FanArtMediaTypes.Audio || mediaType == FanArtMediaTypes.Album)) { IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, OPTIONAL_MIAS, filter), false, null, true); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); IList <MultipleMediaItemAspect> relationAspects; if (mediaType == FanArtMediaTypes.Audio && fanArtType == FanArtTypes.FanArt) { //No FanArt exists for Audio so use Artists if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { //Artist fallback foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ARTIST) { fanArtFiles.AddRange(fanArtCache.GetFanArtFiles((Guid)relation[RelationshipAspect.ATTR_LINKED_ID], fanArtType)); if (fanArtFiles.Count > 0) { break; } } } } } else if (mediaType == FanArtMediaTypes.Album && fanArtType == FanArtTypes.FanArt) { //No FanArt exists for Album so use Artists if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { //Album artist fallback foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ALBUMARTIST) { fanArtFiles.AddRange(fanArtCache.GetFanArtFiles((Guid)relation[RelationshipAspect.ATTR_LINKED_ID], fanArtType)); if (fanArtFiles.Count > 0) { break; } } } } } else if (mediaItem.Aspects.ContainsKey(AudioAspect.ASPECT_ID)) { if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { //Album fallback foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == AudioAlbumAspect.ROLE_ALBUM) { fanArtFiles.AddRange(fanArtCache.GetFanArtFiles((Guid)relation[RelationshipAspect.ATTR_LINKED_ID], fanArtType)); if (fanArtFiles.Count > 0) { break; } } } } } } List <IResourceLocator> files = new List <IResourceLocator>(); try { files.AddRange(fanArtFiles .Select(fileName => new ResourceLocator(ResourcePath.BuildBaseProviderPath(LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID, fileName))) ); result = files; return(result.Count > 0); } catch (Exception) { } return(false); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.Series && mediaType != FanArtMediaTypes.Episode) { return(false); } // Don't try to load "fanart" for images if (!Guid.TryParse(name, out mediaItemId) || mediaType == FanArtMediaTypes.Image) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = null; if (mediaType == FanArtMediaTypes.Series) { filter = new RelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, mediaItemId); } else if (mediaType == FanArtMediaTypes.Episode) { filter = new MediaItemIdFilter(mediaItemId); } MediaItemQuery episodeQuery = new MediaItemQuery(NECESSARY_MIAS, filter); episodeQuery.Limit = 1; IList <MediaItem> items = mediaLibrary.Search(episodeQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); var mediaIteamLocator = mediaItem.GetResourceLocator(); // Virtual resources won't have any local fanart if (mediaIteamLocator.NativeResourcePath.BasePathSegment.ProviderId == VirtualResourceProvider.VIRTUAL_RESOURCE_PROVIDER_ID) { return(false); } var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var mediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); var mediaItemFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemPath.ToString()).ToLowerInvariant(); var mediaItemExtension = ResourcePathHelper.GetExtension(mediaItemPath.ToString()); using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, mediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "poster" || potentialFanArtFileNameWithoutExtension == "folder" select potentialFanArtFile); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "banner" select potentialFanArtFile); } if (fanArtType == FanArtTypes.Logo) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "logo" select potentialFanArtFile); } if (fanArtType == FanArtTypes.ClearArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "clearart" select potentialFanArtFile); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange( from potentialFanArtFile in potentialFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension == "backdrop" || potentialFanArtFileNameWithoutExtension == "fanart" select potentialFanArtFile); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalSeriesFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }
protected bool GetPattern(string mediaType, string fanArtType, Guid mediaItemId, string name, out string[] patterns) { patterns = null; string basePath = null; if (mediaItemId != Guid.Empty) { IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new MediaItemIdFilter(mediaItemId); IList <MediaItem> items = mediaLibrary.Search(new MediaItemQuery(NECESSARY_MIAS, filter), false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); int movieDbId; if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, MovieAspect.ATTR_TMDB_ID, out movieDbId)) { switch (mediaType) { case FanArtMediaTypes.Undefined: case FanArtMediaTypes.Movie: basePath = Path.Combine(MovieTheMovieDbMatcher.CACHE_PATH, movieDbId.ToString()); break; } } } else { switch (mediaType) { case FanArtMediaTypes.Undefined: case FanArtMediaTypes.Movie: int movieDbId; basePath = !MovieTheMovieDbMatcher.Instance.TryGetMovieDbId(name, out movieDbId) ? null : Path.Combine(MovieTheMovieDbMatcher.CACHE_PATH, movieDbId.ToString()); break; case FanArtMediaTypes.MovieCollection: int collectionId; basePath = !MovieTheMovieDbMatcher.Instance.TryGetCollectionId(name, out collectionId) ? null : Path.Combine(MovieTheMovieDbMatcher.CACHE_PATH, "COLL_" + collectionId); break; } } if (string.IsNullOrWhiteSpace(basePath)) { return(false); } switch (fanArtType) { case FanArtTypes.Thumbnail: case FanArtTypes.Poster: patterns = new[] { Path.Combine(basePath, "Posters\\*.jpg") }; return(true); case FanArtTypes.FanArt: patterns = new[] { Path.Combine(basePath, "Backdrops\\*.jpg") }; return(true); } return(false); }
/// <summary> /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>. /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>. /// </summary> /// <param name="mediaType">Requested FanArtMediaType</param> /// <param name="fanArtType">Requested FanArtType</param> /// <param name="name">Requested name of Series, Actor, Artist...</param> /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param> /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param> /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param> /// <param name="result">Result if return code is <c>true</c>.</param> /// <returns><c>true</c> if at least one match was found.</returns> public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result) { result = null; Guid mediaItemId; if (mediaType != FanArtMediaTypes.Actor || (fanArtType != FanArtTypes.Undefined && fanArtType != FanArtTypes.Thumbnail)) { return(false); } if (!Guid.TryParse(name, out mediaItemId)) { return(false); } IMediaLibrary mediaLibrary = ServiceRegistration.Get <IMediaLibrary>(false); if (mediaLibrary == null) { return(false); } IFilter filter = new RelationshipFilter(EpisodeAspect.ROLE_EPISODE, PersonAspect.ROLE_ACTOR, mediaItemId); IList <MediaItem> items = null; List <Guid> necessaryMias = new List <Guid>(NECESSARY_MIAS); MediaItemQuery mediaQuery = new MediaItemQuery(necessaryMias, filter); mediaQuery.Limit = 1; items = mediaLibrary.Search(mediaQuery, false, null, false); if (items == null || items.Count == 0) { return(false); } MediaItem mediaItem = items.First(); // Virtual resources won't have any local fanart if (mediaItem.IsVirtual) { return(false); } var mediaIteamLocator = mediaItem.GetResourceLocator(); var fanArtPaths = new List <ResourcePath>(); var files = new List <IResourceLocator>(); string actorName = null; SingleMediaItemAspect videoAspect; List <string> actors = new List <string>(); if (MediaItemAspect.TryGetAspect(mediaItem.Aspects, VideoAspect.Metadata, out videoAspect)) { IEnumerable <object> actorObjects = videoAspect.GetCollectionAttribute <object>(VideoAspect.ATTR_ACTORS); if (actorObjects != null) { actors.AddRange(actorObjects.Cast <string>()); } } IList <MultipleMediaItemAspect> relationAspects; if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, RelationshipAspect.Metadata, out relationAspects)) { foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ACTOR && (Guid?)relation[RelationshipAspect.ATTR_LINKED_ID] == mediaItemId) { int?index = (int?)relation[RelationshipAspect.ATTR_RELATIONSHIP_INDEX]; if (index.HasValue && actors.Count > index.Value && index.Value >= 0) { actorName = actors[index.Value]; } break; } } } // File based access try { var mediaItemPath = mediaIteamLocator.NativeResourcePath; var seasonMediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../"); var seriesMediaItemDirectoryPath = ResourcePathHelper.Combine(mediaItemPath, "../../"); if (!string.IsNullOrEmpty(actorName)) { using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, seriesMediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { //Get series actor thumbs IFileSystemResourceAccessor actorMediaItemDirectory = directoryFsra.GetResource(".actors"); if (actorMediaItemDirectory != null) { var potentialArtistFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(actorMediaItemDirectory); foreach (ResourcePath thumbPath in from potentialFanArtFile in potentialArtistFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()) where potentialFanArtFileNameWithoutExtension.StartsWith(actorName.Replace(" ", "_"), StringComparison.InvariantCultureIgnoreCase) select potentialFanArtFile) { files.Add(new ResourceLocator(mediaIteamLocator.NativeSystemId, thumbPath)); } } } } using (var directoryRa = new ResourceLocator(mediaIteamLocator.NativeSystemId, seasonMediaItemDirectoryPath).CreateAccessor()) { var directoryFsra = directoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { //Get season actor thumbs IFileSystemResourceAccessor actorMediaItemDirectory = directoryFsra.GetResource(".actors"); if (actorMediaItemDirectory != null) { var potentialArtistFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(actorMediaItemDirectory); foreach (ResourcePath thumbPath in from potentialFanArtFile in potentialArtistFanArtFiles let potentialFanArtFileNameWithoutExtension = ResourcePathHelper.GetFileNameWithoutExtension(potentialFanArtFile.ToString()).ToLowerInvariant() where potentialFanArtFileNameWithoutExtension.StartsWith(actorName.Replace(" ", "_")) select potentialFanArtFile) { files.Add(new ResourceLocator(mediaIteamLocator.NativeSystemId, thumbPath)); } } } } //Find central actor information folder ResourcePath centralActorFolderPath = LocalFanartHelper.GetCentralPersonFolder(seriesMediaItemDirectoryPath, CentralPersonFolderType.SeriesActors); if (centralActorFolderPath != null) { // First get the ResourcePath of the central directory var actorFolderPath = ResourcePathHelper.Combine(centralActorFolderPath, $"{LocalFanartHelper.GetSafePersonFolderName(actorName)}/"); // Then try to create an IFileSystemResourceAccessor for this directory actorFolderPath.TryCreateLocalResourceAccessor(out var artistNfoDirectoryRa); var directoryFsra = artistNfoDirectoryRa as IFileSystemResourceAccessor; if (directoryFsra != null) { var potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryFsra); if (fanArtType == FanArtTypes.Poster || fanArtType == FanArtTypes.Thumbnail) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.ARTIST_FILENAMES)); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES)); fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES)); } if (fanArtType == FanArtTypes.Banner) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES)); } if (fanArtType == FanArtTypes.Logo) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.LOGO_FILENAMES)); } if (fanArtType == FanArtTypes.ClearArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.CLEARART_FILENAMES)); } if (fanArtType == FanArtTypes.FanArt) { fanArtPaths.AddRange(LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES)); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) fanArtPaths.AddRange(LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } files.AddRange(fanArtPaths.Select(path => new ResourceLocator(mediaIteamLocator.NativeSystemId, path))); } } } } catch (Exception ex) { #if DEBUG ServiceRegistration.Get <ILogger>().Warn("LocalSeriesActorFanArtProvider: Error while searching fanart of type '{0}' for '{1}'", ex, fanArtType, mediaIteamLocator); #endif } result = files; return(files.Count > 0); }