/// <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); }
/// <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 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 (!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)))); } }
/// <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> /// 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 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); } }