/// <summary> /// Gets all collection folder images and caches them in the <see cref="IFanArtCache"/> service. /// </summary> /// <param name="mediaItemLocator"><see cref="IResourceLocator>"/> that points to the file.</param> /// <param name="collectionMediaItemId">Id of the series media item.</param> /// <param name="title">Title of the media item.</param> /// <returns><see cref="Task"/> that completes when the images have been cached.</returns> protected async Task ExtractCollectionFolderFanArt(IResourceLocator mediaItemLocator, Guid collectionMediaItemId, string title) { var collectionDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../"); var centralCollectionDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../../" + MOVIESET_FANART_FOLDER); var centralCollectionDirectory2 = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../" + MOVIESET_FANART_FOLDER); var movieDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../"); try { FanArtPathCollection paths = new FanArtPathCollection(); using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, centralCollectionDirectory).CreateAccessor()) paths.AddRange(GetCollectionFolderFanArt(accessor as IFileSystemResourceAccessor)); using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, centralCollectionDirectory2).CreateAccessor()) paths.AddRange(GetCollectionFolderFanArt(accessor as IFileSystemResourceAccessor)); using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, collectionDirectory).CreateAccessor()) paths.AddRange(GetCollectionFolderFanArt(accessor as IFileSystemResourceAccessor)); using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, movieDirectory).CreateAccessor()) paths.AddRange(GetMovieFolderCollectionFanArt(accessor as IFileSystemResourceAccessor)); await SaveFolderImagesToCache(mediaItemLocator.NativeSystemId, paths, collectionMediaItemId, title).ConfigureAwait(false); } catch (Exception ex) { Logger.Warn("MovieFanArtHandler: Exception while reading folder images for '{0}'", ex, collectionDirectory); } }
/// <summary> /// Gets all season folder images and caches them in the <see cref="IFanArtCache"/> service. /// </summary> /// <param name="mediaItemLocator"><see cref="IResourceLocator>"/> that points to the file.</param> /// <param name="seasonMediaItemId">Id of the season media item.</param> /// <param name="title">Title of the media item.</param> /// <param name="seasonNumber">Season number.</param> /// <param name="actors">Collection of actor ids and names.</param> /// <returns><see cref="Task"/> that completes when the images have been cached.</returns> protected async Task ExtractSeasonFolderFanArt(IResourceLocator mediaItemLocator, Guid seasonMediaItemId, string title, int?seasonNumber, IList <Tuple <Guid, string> > actors) { var seasonDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../"); try { FanArtPathCollection paths = null; IList <ResourcePath> potentialActorImages = null; using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, seasonDirectory).CreateAccessor()) if (accessor is IFileSystemResourceAccessor fsra) { paths = GetSeasonFolderFanArt(fsra, seasonNumber); //See if there's an actor fanart directory and try and get any actor fanart if (actors != null && actors.Count > 0 && fsra.ResourceExists(".actors")) { using (IFileSystemResourceAccessor actorsDirectory = fsra.GetResource(".actors")) potentialActorImages = LocalFanartHelper.GetPotentialFanArtFiles(actorsDirectory); } } if (paths != null) { await SaveFolderImagesToCache(mediaItemLocator.NativeSystemId, paths, seasonMediaItemId, title).ConfigureAwait(false); } if (potentialActorImages != null) { await SavePersonFolderImages(mediaItemLocator.NativeSystemId, potentialActorImages, actors).ConfigureAwait(false); } } catch (Exception ex) { Logger.Warn("SeriesFanArtHandler: Exception while reading folder images for '{0}'", ex, seasonDirectory); } }
/// <summary> /// Gets a <see cref="FanArtPathCollection"/> containing all matching fanart paths in the specified <see cref="ResourcePath"/>. /// </summary> /// <param name="albumDirectory"><see cref="IFileSystemResourceAccessor"/> that points to the album directory.</param> /// <returns><see cref="FanArtPathCollection"/> containing all matching paths.</returns> protected FanArtPathCollection GetAlbumFolderFanArt(IFileSystemResourceAccessor albumDirectory) { FanArtPathCollection paths = new FanArtPathCollection(); if (albumDirectory == null) { return(paths); } //Get all fanart in the current directory List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(albumDirectory); ExtractAllFanArtImages(potentialFanArtFiles, paths); //Add extra backdrops in ExtraFanArt directory if (albumDirectory.ResourceExists("ExtraFanArt/")) { using (IFileSystemResourceAccessor extraFanArtDirectory = albumDirectory.GetResource("ExtraFanArt/")) paths.AddRange(FanArtTypes.FanArt, LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectory)); } List <ResourcePath> covers; //Albums store posters as covers so switch the fanart type if (paths.Paths.TryGetValue(FanArtTypes.Poster, out covers)) { paths.Paths.Remove(FanArtTypes.Poster); paths.AddRange(FanArtTypes.Cover, covers); } return(paths); }
public FanArtPathCollection TestGetAdditionalSeasonFolderFanArt(IList <ResourcePath> potentialFanArtFiles, int seasonNumber) { FanArtPathCollection paths = new FanArtPathCollection(); GetAdditionalSeasonFolderFanArt(paths, potentialFanArtFiles, seasonNumber); return(paths); }
/// <summary> /// Gets a <see cref="FanArtPathCollection"/> containing all matching season fanart paths in the specified <see cref="ResourcePath"/>. /// </summary> /// <param name="seasonDirectory"><see cref="IFileSystemResourceAccessor"/> that points to the season directory.</param> /// <param name="seasonNumber">Season number.</param> /// <returns><see cref="FanArtPathCollection"/> containing all matching paths.</returns> protected FanArtPathCollection GetSeasonFolderFanArt(IFileSystemResourceAccessor seasonDirectory, int?seasonNumber, bool isSeriesFolder) { FanArtPathCollection paths = new FanArtPathCollection(); if (seasonDirectory == null) { return(paths); } List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(seasonDirectory); if (!isSeriesFolder) { ExtractAllFanArtImages(potentialFanArtFiles, paths); if (!seasonNumber.HasValue || !seasonDirectory.ResourceExists("../")) { return(paths); } //Try and populate any missing fanart from the series directory using (IFileSystemResourceAccessor seriesDirectory = seasonDirectory.GetResource("../")) potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(seriesDirectory); } GetAdditionalSeasonFolderFanArt(paths, potentialFanArtFiles, seasonNumber); return(paths); }
/// <summary> /// Gets all album folder images and caches them in the <see cref="IFanArtCache"/> service. /// </summary> /// <param name="nativeSystemId">The native system id of the media item.</param> /// <param name="albumDirectory"><see cref="ResourcePath>"/> that points to the album directory.</param> /// <param name="albumMediaItemId">Id of the media item.</param> /// <param name="title">Title of the media item.</param> /// <param name="artists">List of artists.</param> /// <returns><see cref="Task"/> that completes when the images have been cached.</returns> protected async Task ExtractAlbumFolderFanArt(string nativeSystemId, ResourcePath albumDirectory, Guid albumMediaItemId, string title, IList <Tuple <Guid, string> > artists) { try { FanArtPathCollection paths = null; IList <ResourcePath> potentialArtistImages = null; using (IResourceAccessor accessor = new ResourceLocator(nativeSystemId, albumDirectory).CreateAccessor()) if (accessor is IFileSystemResourceAccessor fsra) { paths = GetAlbumFolderFanArt(fsra); //See if there's an actor fanart directory and try and get any actor fanart if (artists != null && artists.Count > 0 && fsra.ResourceExists(".artists")) { using (IFileSystemResourceAccessor actorsDirectory = fsra.GetResource(".artists")) potentialArtistImages = LocalFanartHelper.GetPotentialFanArtFiles(actorsDirectory); } } if (paths != null) { await SaveFolderImagesToCache(nativeSystemId, paths, albumMediaItemId, title).ConfigureAwait(false); } if (potentialArtistImages != null) { await SavePersonFolderImages(nativeSystemId, potentialArtistImages, artists).ConfigureAwait(false); } } catch (Exception ex) { Logger.Warn("AudioFanArtHandler: Exception while reading folder images for '{0}'", ex, albumDirectory); } }
public FanArtPathCollection TestGetAllFolderFanArt(IList <ResourcePath> potentialFanArtFiles, string filename) { FanArtPathCollection paths = new FanArtPathCollection(); ExtractAllFanArtImages(potentialFanArtFiles, paths, filename); return(paths); }
/// <summary> /// Gets all artist folder images and caches them in the <see cref="IFanArtCache"/> service. /// </summary> /// <param name="nativeSystemId">The native system id of the media item.</param> /// <param name="albumDirectory"><see cref="ResourcePath>"/> that points to the album directory.</param> /// <param name="albumMediaItemId">Id of the media item.</param> /// <param name="title">Title of the media item.</param> /// <param name="artists">List of artists.</param> /// <returns><see cref="Task"/> that completes when the images have been cached.</returns> protected async Task ExtractArtistFolderFanArt(string nativeSystemId, ResourcePath albumDirectory, IList <Tuple <Guid, string> > artists) { if (artists == null || artists.Count == 0) { return; } //Get the file's directory var artistDirectory = ResourcePathHelper.Combine(albumDirectory, "../"); try { var artist = artists.FirstOrDefault(a => string.Compare(a.Item2, artistDirectory.FileName, StringComparison.OrdinalIgnoreCase) == 0); if (artist == null) { artist = artists[0]; } //See if we've already processed this artist if (!AddToCache(artist.Item1)) { return; } //Get all fanart paths in the current directory FanArtPathCollection paths = new FanArtPathCollection(); using (IResourceAccessor accessor = new ResourceLocator(nativeSystemId, artistDirectory).CreateAccessor()) { foreach (var path in GetArtistFolderFanArt(accessor as IFileSystemResourceAccessor)) { paths.AddRange(path.Key, path.Value); } } //Find central artist information folder ResourcePath centralArtistFolderPath = LocalFanartHelper.GetCentralPersonFolder(artistDirectory, CentralPersonFolderType.AudioArtists); if (centralArtistFolderPath != null) { // First get the ResourcePath of the central directory var artistFolderPath = ResourcePathHelper.Combine(centralArtistFolderPath, $"{LocalFanartHelper.GetSafePersonFolderName(artist.Item2)}/"); using (IResourceAccessor accessor = new ResourceLocator(nativeSystemId, artistFolderPath).CreateAccessor()) { foreach (var path in GetArtistFolderFanArt(accessor as IFileSystemResourceAccessor)) { paths.AddRange(path.Key, path.Value); } } } //Save the fanart to the IFanArtCache service await SaveFolderImagesToCache(nativeSystemId, paths, artist.Item1, artist.Item2).ConfigureAwait(false); } catch (Exception ex) { Logger.Warn("AudioFanArtHandler: Exception while reading folder images for '{0}'", ex, artistDirectory); } }
/// <summary> /// Tries to populate any empty fanart types in the specified <see cref="FanArtPathCollection"/> with image paths /// contained in <paramref name="potentialFanArtFiles"/> that start with 'season-all', 'season{<paramref name="seasonNumber"/>}' /// or, if <paramref name="seasonNumber"/> is 0, 'season-specials'. /// </summary> /// <param name="paths">The <see cref="FanArtPathCollection"/> to add matching paths to.</param> /// <param name="potentialFanArtFiles">Collection of potential fanart paths.</param> /// <param name="seasonNumber">The season number.</param> protected void GetAdditionalSeasonFolderFanArt(FanArtPathCollection paths, ICollection <ResourcePath> potentialFanArtFiles, int seasonNumber) { if (potentialFanArtFiles == null || potentialFanArtFiles.Count == 0) { return; } string[] prefixes = new[] { string.Format("season{0:00}", seasonNumber), seasonNumber == 0 ? "season-specials" : "season-all" }; if (paths.Count(FanArtTypes.Thumbnail) == 0) { paths.AddRange(FanArtTypes.Thumbnail, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.Poster) == 0) { paths.AddRange(FanArtTypes.Poster, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.Logo) == 0) { paths.AddRange(FanArtTypes.Logo, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.LOGO_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.ClearArt) == 0) { paths.AddRange(FanArtTypes.ClearArt, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.CLEARART_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.DiscArt) == 0) { paths.AddRange(FanArtTypes.DiscArt, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.DISCART_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.Banner) == 0) { paths.AddRange(FanArtTypes.Banner, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.FanArt) == 0) { paths.AddRange(FanArtTypes.FanArt, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } }
/// <summary> /// Tries to populate any empty fanart types in the specified <see cref="FanArtPathCollection"/> with image paths /// contained in <paramref name="potentialFanArtFiles"/> that start with 'season-all', 'season{<paramref name="seasonNumber"/>}' /// or, if <paramref name="seasonNumber"/> is 0, 'season-specials'. /// </summary> /// <param name="paths">The <see cref="FanArtPathCollection"/> to add matching paths to.</param> /// <param name="potentialFanArtFiles">Collection of potential fanart paths.</param> /// <param name="seasonNumber">The season number.</param> protected void GetAdditionalSeasonFolderFanArt(FanArtPathCollection paths, ICollection <ResourcePath> potentialFanArtFiles, int?seasonNumber) { if (!seasonNumber.HasValue) { return; } if (potentialFanArtFiles == null || potentialFanArtFiles.Count == 0) { return; } string[] prefixes = LocalFanartHelper.GetAdditionalSeasonPrefixes(seasonNumber); if (paths.Count(FanArtTypes.Thumbnail) == 0) { paths.AddRange(FanArtTypes.Thumbnail, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.Poster) == 0) { paths.AddRange(FanArtTypes.Poster, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.Logo) == 0) { paths.AddRange(FanArtTypes.Logo, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.LOGO_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.ClearArt) == 0) { paths.AddRange(FanArtTypes.ClearArt, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.CLEARART_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.DiscArt) == 0) { paths.AddRange(FanArtTypes.DiscArt, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.DISCART_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.Banner) == 0) { paths.AddRange(FanArtTypes.Banner, LocalFanartHelper.FilterPotentialFanArtFilesByName(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } if (paths.Count(FanArtTypes.FanArt) == 0) { paths.AddRange(FanArtTypes.FanArt, LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES.SelectMany(f => prefixes.Select(p => p + "-" + f)))); } }
public void TestFanArtGetAdditionalSeasonFolderFanArt(string[] paths, int seasonNumber, int expectedCount) { //Arrange List <ResourcePath> resourcePaths = paths.Select(p => ResourcePath.BuildBaseProviderPath(MockResourceProvider.PROVIDER_ID, p)).ToList(); SeriesFanArtHandlerForTests fh = new SeriesFanArtHandlerForTests(); //Act FanArtPathCollection fanart = fh.TestGetAdditionalSeasonFolderFanArt(resourcePaths, seasonNumber); //Assert Assert.AreEqual(expectedCount, fanart.Sum(kvp => kvp.Value.Count)); }
/// <summary> /// Gets a <see cref="FanArtPathCollection"/> containing all matching collection fanart paths in the specified <see cref="ResourcePath"/>. /// </summary> /// <param name="movieDirectory"><see cref="IFileSystemResourceAccessor"/> that points to the movie directory.</param> /// <returns><see cref="FanArtPathCollection"/> containing all matching paths.</returns> protected FanArtPathCollection GetMovieFolderCollectionFanArt(IFileSystemResourceAccessor movieDirectory) { FanArtPathCollection paths = new FanArtPathCollection(); if (movieDirectory == null) { return(paths); } List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(movieDirectory); ExtractAllFanArtImagesByPrefix(potentialFanArtFiles, paths, "movieset"); return(paths); }
/// <summary> /// Gets a <see cref="FanArtPathCollection"/> containing all matching episode fanart paths in the specified <see cref="ResourcePath"/>. /// </summary> /// <param name="episodeDirectory"><see cref="IFileSystemResourceAccessor"/> that points to the episode directory.</param> /// <param name="filename">The file name of the media item to extract images for.</param> /// <returns><see cref="FanArtPathCollection"/> containing all matching paths.</returns> protected FanArtPathCollection GetEpisodeFolderFanArt(IFileSystemResourceAccessor episodeDirectory, string filename) { FanArtPathCollection paths = new FanArtPathCollection(); if (episodeDirectory == null) { return(paths); } List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(episodeDirectory); paths.AddRange(FanArtTypes.Thumbnail, LocalFanartHelper.FilterPotentialFanArtFilesByNameOrPrefix(potentialFanArtFiles, null, LocalFanartHelper.THUMB_FILENAMES.Select(f => filename + "-" + f))); return(paths); }
/// <summary> /// Gets a <see cref="FanArtPathCollection"/> containing all matching series fanart paths in the specified <see cref="ResourcePath"/>. /// </summary> /// <param name="seriesDirectory"><see cref="IFileSystemResourceAccessor"/> that points to the series directory.</param> /// <returns><see cref="FanArtPathCollection"/> containing all matching paths.</returns> protected FanArtPathCollection GetSeriesFolderFanArt(IFileSystemResourceAccessor seriesDirectory) { FanArtPathCollection paths = new FanArtPathCollection(); if (seriesDirectory != null) { List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(seriesDirectory); ExtractAllFanArtImages(potentialFanArtFiles, paths); if (seriesDirectory.ResourceExists("ExtraFanArt/")) { using (IFileSystemResourceAccessor extraFanArtDirectory = seriesDirectory.GetResource("ExtraFanArt/")) paths.AddRange(FanArtTypes.FanArt, LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectory)); } } return(paths); }
/// <summary> /// Gets a <see cref="FanArtPathCollection"/> containing all matching fanart paths in the specified <see cref="ResourcePath"/>. /// </summary> /// <param name="artistDirectory"><see cref="IFileSystemResourceAccessor"/> that points to the artist directory.</param> /// <returns><see cref="FanArtPathCollection"/> containing all matching paths.</returns> protected FanArtPathCollection GetArtistFolderFanArt(IFileSystemResourceAccessor artistDirectory) { FanArtPathCollection paths = new FanArtPathCollection(); if (artistDirectory == null) { return(paths); } //Get all fanart in the current directory List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(artistDirectory); ExtractAllFanArtImages(potentialFanArtFiles, paths); //Add extra backdrops in ExtraFanArt directory if (artistDirectory.ResourceExists("ExtraFanArt/")) { using (IFileSystemResourceAccessor extraFanArtDirectory = artistDirectory.GetResource("ExtraFanArt/")) paths.AddRange(FanArtTypes.FanArt, LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectory)); } return(paths); }
/// <summary> /// Gets a <see cref="FanArtPathCollection"/> containing all matching fanart paths in the specified <see cref="ResourcePath"/>. /// </summary> /// <param name="videoDirectory"><see cref="IFileSystemResourceAccessor"/> that points to the episode directory.</param> /// <param name="filename">The file name of the media item to extract images for.</param> /// <returns><see cref="FanArtPathCollection"/> containing all matching paths.</returns> protected FanArtPathCollection GetFolderFanArt(IFileSystemResourceAccessor videoDirectory, string filename, IDictionary <Guid, IList <MediaItemAspect> > aspects) { FanArtPathCollection paths = new FanArtPathCollection(); if (videoDirectory == null) { return(paths); } //Get all fanart in the current directory List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(videoDirectory); ExtractAllFanArtImages(potentialFanArtFiles, paths, filename); //Add extra backdrops in ExtraFanArt directory if (videoDirectory.ResourceExists("ExtraFanArt/")) { using (IFileSystemResourceAccessor extraFanArtDirectory = videoDirectory.GetResource("ExtraFanArt/")) paths.AddRange(FanArtTypes.FanArt, LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectory)); } return(paths); }
/// <summary> /// Gets all movie folder images and caches them in the <see cref="IFanArtCache"/> service. /// </summary> /// <param name="mediaItemLocator"><see cref="IResourceLocator>"/> that points to the file.</param> /// <param name="movieMediaItemId">Id of the media item.</param> /// <param name="title">Title of the media item.</param> /// <returns><see cref="Task"/> that completes when the images have been cached.</returns> protected async Task ExtractMovieFolderFanArt(IResourceLocator mediaItemLocator, Guid movieMediaItemId, string title, IList <Tuple <Guid, string> > actors) { //Get the file's directory var movieDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../"); try { var mediaItemFileName = ResourcePathHelper.GetFileNameWithoutExtension(mediaItemLocator.NativeResourcePath.ToString()).ToLowerInvariant(); FanArtPathCollection paths = null; IList <ResourcePath> potentialActorImages = null; using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, movieDirectory).CreateAccessor()) if (accessor is IFileSystemResourceAccessor fsra) { paths = GetMovieFolderFanArt(fsra, mediaItemFileName); //See if there's an actor fanart directory and try and get any actor fanart if (actors != null && actors.Count > 0 && fsra.ResourceExists(".actors")) { using (IFileSystemResourceAccessor actorsDirectory = fsra.GetResource(".actors")) potentialActorImages = LocalFanartHelper.GetPotentialFanArtFiles(actorsDirectory); } } if (paths != null) { await SaveFolderImagesToCache(mediaItemLocator.NativeSystemId, paths, movieMediaItemId, title).ConfigureAwait(false); } if (potentialActorImages != null) { await SavePersonFolderImages(mediaItemLocator.NativeSystemId, potentialActorImages, actors).ConfigureAwait(false); } } catch (Exception ex) { Logger.Warn("MovieFanArtHandler: Exception while reading folder images for '{0}'", ex, movieDirectory); } }
protected async Task ExtractEpisodeFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { bool shouldCacheLocal = false; IResourceLocator mediaItemLocator = null; if (!BaseInfo.IsVirtualResource(aspects)) { mediaItemLocator = GetResourceLocator(aspects); //Whether local fanart should be stored in the fanart cache shouldCacheLocal = ShouldCacheLocalFanArt(mediaItemLocator.NativeResourcePath, SeriesMetadataExtractor.CacheLocalFanArt, SeriesMetadataExtractor.CacheOfflineFanArt); } if (mediaItemLocator == null) { return; } if (!shouldCacheLocal && SeriesMetadataExtractor.SkipFanArtDownload) { return; //Nothing to do } EpisodeInfo episodeInfo = new EpisodeInfo(); episodeInfo.FromMetadata(aspects); //Episode fanart if (AddToCache(mediaItemId)) { if (shouldCacheLocal) { await ExtractEpisodeFolderFanArt(mediaItemLocator, mediaItemId, episodeInfo.ToString()).ConfigureAwait(false); } if (!SeriesMetadataExtractor.SkipFanArtDownload) { await OnlineMatcherService.Instance.DownloadSeriesFanArtAsync(mediaItemId, episodeInfo).ConfigureAwait(false); } } //Actor fanart may be stored in the season or series directory, so get the actors now IList <Tuple <Guid, string> > actors = null; if (MediaItemAspect.TryGetAspect(aspects, VideoAspect.Metadata, out SingleMediaItemAspect videoAspect)) { var actorNames = videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_ACTORS); if (actorNames != null) { RelationshipExtractorUtils.TryGetMappedLinkedIds(PersonAspect.ROLE_ACTOR, aspects, actorNames.ToList(), out actors); } } //Take advantage of the audio language being known and download season and series too //Season fanart if (RelationshipExtractorUtils.TryGetLinkedId(SeasonAspect.ROLE_SEASON, aspects, out Guid seasonMediaItemId) && AddToCache(seasonMediaItemId)) { SeasonInfo seasonInfo = episodeInfo.CloneBasicInstance <SeasonInfo>(); if (shouldCacheLocal) { await ExtractSeasonFolderFanArt(mediaItemLocator, seasonMediaItemId, seasonInfo.ToString(), seasonInfo.SeasonNumber, actors).ConfigureAwait(false); } if (!SeriesMetadataExtractor.SkipFanArtDownload) { await OnlineMatcherService.Instance.DownloadSeriesFanArtAsync(seasonMediaItemId, seasonInfo).ConfigureAwait(false); } } //Series fanart if (RelationshipExtractorUtils.TryGetLinkedId(SeriesAspect.ROLE_SERIES, aspects, out Guid seriesMediaItemId) && AddToCache(seriesMediaItemId)) { SeriesInfo seriesInfo = episodeInfo.CloneBasicInstance <SeriesInfo>(); if (shouldCacheLocal) { await ExtractSeriesFolderFanArt(mediaItemLocator, seriesMediaItemId, seriesInfo.ToString(), episodeInfo.SeasonNumber, actors).ConfigureAwait(false); } if (!SeriesMetadataExtractor.SkipFanArtDownload) { await OnlineMatcherService.Instance.DownloadSeriesFanArtAsync(seriesMediaItemId, seriesInfo).ConfigureAwait(false); } } //Find central actor information folder var seriesDirectory = ResourcePathHelper.Combine(mediaItemLocator.NativeResourcePath, "../../"); ResourcePath centralActorFolderPath = LocalFanartHelper.GetCentralPersonFolder(seriesDirectory, CentralPersonFolderType.SeriesActors); if (shouldCacheLocal && centralActorFolderPath != null && actors != null) { foreach (var actor in actors) { // Check if we already processed this actor if (!AddToCache(actor.Item1)) { continue; } // First get the ResourcePath of the central directory var artistFolderPath = ResourcePathHelper.Combine(centralActorFolderPath, $"{LocalFanartHelper.GetSafePersonFolderName(actor.Item2)}/"); using (IResourceAccessor accessor = new ResourceLocator(mediaItemLocator.NativeSystemId, artistFolderPath).CreateAccessor()) { if (accessor is IFileSystemResourceAccessor directoryAccessor) { FanArtPathCollection paths = new FanArtPathCollection(); List <ResourcePath> potentialFanArtFiles = LocalFanartHelper.GetPotentialFanArtFiles(directoryAccessor); ExtractAllFanArtImages(potentialFanArtFiles, paths); await SaveFolderImagesToCache(mediaItemLocator.NativeSystemId, paths, actor.Item1, actor.Item2).ConfigureAwait(false); } } } } }
/// <summary> /// Gets all album folder images and caches them in the <see cref="IFanArtCache"/> service. /// </summary> /// <param name="nativeSystemId">The native system id of the media item.</param> /// <param name="albumDirectory"><see cref="ResourcePath>"/> that points to the album directory.</param> /// <param name="albumMediaItemId">Id of the media item.</param> /// <param name="title">Title of the media item.</param> /// <param name="artists">List of artists.</param> /// <returns><see cref="Task"/> that completes when the images have been cached.</returns> protected async Task ExtractAlbumFolderFanArt(string nativeSystemId, ResourcePath albumDirectory, Guid albumMediaItemId, string title, IList <Tuple <Guid, string> > artists) { try { FanArtPathCollection paths = null; IList <ResourcePath> potentialArtistImages = null; using (IResourceAccessor accessor = new ResourceLocator(nativeSystemId, albumDirectory).CreateAccessor()) if (accessor is IFileSystemResourceAccessor fsra) { paths = GetAlbumFolderFanArt(fsra); //See if there's an actor fanart directory and try and get any actor fanart if (artists != null && artists.Count > 0 && fsra.ResourceExists(".artists")) { using (IFileSystemResourceAccessor actorsDirectory = fsra.GetResource(".artists")) potentialArtistImages = LocalFanartHelper.GetPotentialFanArtFiles(actorsDirectory); } } if (paths != null) { await SaveFolderImagesToCache(nativeSystemId, paths, albumMediaItemId, title).ConfigureAwait(false); } if (potentialArtistImages != null) { await SavePersonFolderImages(nativeSystemId, potentialArtistImages, artists).ConfigureAwait(false); } if (artists != null && artists.Count > 0) { //Find central artist information folder ResourcePath centralArtistFolderPath = null; for (int level = 1; level <= 3; level++) //Look for central artist folder { // First get the ResourcePath of the central directory for the current level var centralArtistNfoDirectoryResourcePath = albumDirectory; for (int addLevel = 0; addLevel < level; addLevel++) { centralArtistNfoDirectoryResourcePath = ResourcePathHelper.Combine(centralArtistNfoDirectoryResourcePath, "../"); } if (centralArtistNfoDirectoryResourcePath.BasePathSegment.Path.Length < 3) { break; //Path no longer valid } centralArtistNfoDirectoryResourcePath = ResourcePathHelper.Combine(centralArtistNfoDirectoryResourcePath, $"{ARTIST_INFO_FOLDER}/"); // Then try to create an IFileSystemResourceAccessor for this directory centralArtistNfoDirectoryResourcePath.TryCreateLocalResourceAccessor(out var artistNfoDirectoryRa); var artistNfoDirectoryFsra = artistNfoDirectoryRa as IFileSystemResourceAccessor; if (artistNfoDirectoryFsra != null) { using (artistNfoDirectoryFsra) { centralArtistFolderPath = centralArtistNfoDirectoryResourcePath; break; } } } if (centralArtistFolderPath != null) { foreach (var artist in artists) { var artistName = artist.Item2; FanArtPathCollection artistsPaths = new FanArtPathCollection(); // First get the ResourcePath of the central directory var artistFolderPath = ResourcePathHelper.Combine(centralArtistFolderPath, $"{FileUtils.GetSafeFilename(artistName, '¤').Replace("¤", "")}/"); // 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); artistsPaths.AddRange(FanArtTypes.Thumbnail, LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.ARTIST_FILENAMES)); artistsPaths.AddRange(FanArtTypes.Poster, LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.POSTER_FILENAMES)); artistsPaths.AddRange(FanArtTypes.Thumbnail, LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.THUMB_FILENAMES)); artistsPaths.AddRange(FanArtTypes.Banner, LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BANNER_FILENAMES)); artistsPaths.AddRange(FanArtTypes.Logo, LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.LOGO_FILENAMES)); artistsPaths.AddRange(FanArtTypes.ClearArt, LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.CLEARART_FILENAMES)); artistsPaths.AddRange(FanArtTypes.FanArt, LocalFanartHelper.FilterPotentialFanArtFilesByPrefix(potentialFanArtFiles, LocalFanartHelper.BACKDROP_FILENAMES)); if (directoryFsra.ResourceExists("ExtraFanArt/")) { using (var extraFanArtDirectoryFsra = directoryFsra.GetResource("ExtraFanArt/")) artistsPaths.AddRange(FanArtTypes.FanArt, LocalFanartHelper.GetPotentialFanArtFiles(extraFanArtDirectoryFsra)); } } await SaveFolderImagesToCache(nativeSystemId, paths, artist.Item1, title).ConfigureAwait(false); } } } } catch (Exception ex) { Logger.Warn("AudioFanArtHandler: Exception while reading folder images for '{0}'", ex, albumDirectory); } }