private bool HasPhotos(ItemResolveArgs args) { var files = args.FileSystemChildren; foreach (var file in files) { if (!file.IsDirectory && PhotoResolver.IsImageFile(file.FullName, _imageProcessor)) { var libraryOptions = args.GetLibraryOptions(); var filename = file.Name; var ownedByMedia = false; foreach (var siblingFile in files) { if (PhotoResolver.IsOwnedByMedia(_libraryManager, libraryOptions, siblingFile.FullName, filename)) { ownedByMedia = true; break; } } if (!ownedByMedia) { return(true); } } } return(false); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Entities.Audio.Audio.</returns> protected override Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args) { // Return audio if the path is a file and has a matching extension if (!args.IsDirectory) { var libraryOptions = args.GetLibraryOptions(); if (_libraryManager.IsAudioFile(args.Path, libraryOptions)) { var collectionType = args.GetCollectionType(); var isMixed = string.IsNullOrWhiteSpace(collectionType); // For conflicting extensions, give priority to videos if (isMixed && _libraryManager.IsVideoFile(args.Path, libraryOptions)) { return(null); } var isStandalone = args.Parent == null; if (isStandalone || string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) || isMixed) { return(new Controller.Entities.Audio.Audio()); } } } return(null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Season.</returns> protected override Season Resolve(ItemResolveArgs args) { if (args.Parent is Series series && args.IsDirectory) { var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions(); var path = args.Path; var seasonParserResult = SeasonPathParser.Parse(path, true, true); var season = new Season { IndexNumber = seasonParserResult.SeasonNumber, SeriesId = series.Id, SeriesName = series.Name }; if (!season.IndexNumber.HasValue || !seasonParserResult.IsSeasonFolder) { var resolver = new Naming.TV.EpisodeResolver(namingOptions); var folderName = System.IO.Path.GetFileName(path); var testPath = "\\\\test\\" + folderName; var episodeInfo = resolver.Resolve(testPath, true); if (episodeInfo != null) { if (episodeInfo.EpisodeNumber.HasValue && episodeInfo.SeasonNumber.HasValue) { _logger.LogDebug( "Found folder underneath series with episode number: {0}. Season {1}. Episode {2}", path, episodeInfo.SeasonNumber.Value, episodeInfo.EpisodeNumber.Value); return(null); } } } if (season.IndexNumber.HasValue) { var seasonNumber = season.IndexNumber.Value; season.Name = seasonNumber == 0 ? args.LibraryOptions.SeasonZeroDisplayName : string.Format( CultureInfo.InvariantCulture, _localization.GetLocalizedString("NameSeasonNumber"), seasonNumber, args.GetLibraryOptions().PreferredMetadataLanguage); } return(season); } return(null); }
private T FindAudio <T>(ItemResolveArgs args, string path, Folder parent, List <FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, string collectionType, bool parseName) where T : MediaBrowser.Controller.Entities.Audio.Audio, new() { var multiDiscFolders = new List <FileSystemMetadata>(); var libraryOptions = args.GetLibraryOptions(); var filesFromOtherItems = new List <FileSystemMetadata>(); // TODO: Allow GetMultiDiscMovie in here var supportsMultiVersion = false; var result = ResolveMultipleAudio <T>(parent, fileSystemEntries, directoryService, supportsMultiVersion, collectionType, parseName) ?? new MultiItemResolverResult(); if (result.Items.Count == 1) { var videoPath = result.Items[0].Path; // If we were supporting this we'd be checking filesFromOtherItems var hasOtherItems = false; if (!hasOtherItems) { var item = (T)result.Items[0]; item.IsInMixedFolder = false; item.Name = Path.GetFileName(item.ContainingFolderPath); return(item); } } if (result.Items.Count == 0 && multiDiscFolders.Count > 0) { //return GetMultiDiscAudio<T>(multiDiscFolders, directoryService); } return(null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Trailer.</returns> protected override Photo Resolve(ItemResolveArgs args) { if (!args.IsDirectory) { // Must be an image file within a photo collection var collectionType = args.GetCollectionType(); if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) || (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos)) { if (IsImageFile(args.Path, _imageProcessor)) { var filename = Path.GetFileNameWithoutExtension(args.Path); // Make sure the image doesn't belong to a video file var files = args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path)); var libraryOptions = args.GetLibraryOptions(); foreach (var file in files) { if (IsOwnedByMedia(_libraryManager, libraryOptions, file.FullName, filename)) { return(null); } } return(new Photo { Path = args.Path }); } } } return(null); }
/// <summary> /// Finds a movie based on a child file system entries /// </summary> /// <typeparam name="T"></typeparam> /// <returns>Movie.</returns> private T FindMovie <T>(ItemResolveArgs args, string path, Folder parent, List <FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, string collectionType, bool parseName) where T : Video, new() { var multiDiscFolders = new List <FileSystemMetadata>(); var libraryOptions = args.GetLibraryOptions(); var supportPhotos = string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && libraryOptions.EnablePhotos; var photos = new List <FileSystemMetadata>(); // Search for a folder rip foreach (var child in fileSystemEntries) { var filename = child.Name; if (child.IsDirectory) { if (IsDvdDirectory(child.FullName, filename, directoryService)) { var movie = new T { Path = path, VideoType = VideoType.Dvd }; Set3DFormat(movie); return(movie); } if (IsBluRayDirectory(child.FullName, filename, directoryService)) { var movie = new T { Path = path, VideoType = VideoType.BluRay }; Set3DFormat(movie); return(movie); } multiDiscFolders.Add(child); } else if (IsDvdFile(filename)) { var movie = new T { Path = path, VideoType = VideoType.Dvd }; Set3DFormat(movie); return(movie); } else if (supportPhotos && !child.IsHidden && PhotoResolver.IsImageFile(child.FullName, _imageProcessor)) { photos.Add(child); } } // TODO: Allow GetMultiDiscMovie in here var supportsMultiVersion = !string.Equals(collectionType, CollectionType.HomeVideos) && !string.Equals(collectionType, CollectionType.Photos) && !string.Equals(collectionType, CollectionType.MusicVideos); var result = ResolveVideos <T>(parent, fileSystemEntries, directoryService, supportsMultiVersion, collectionType, parseName) ?? new MultiItemResolverResult(); if (result.Items.Count == 1) { var videoPath = result.Items[0].Path; var hasPhotos = photos.Any(i => !PhotoResolver.IsOwnedByResolvedMedia(LibraryManager, libraryOptions, videoPath, i.Name)); if (!hasPhotos) { var movie = (T)result.Items[0]; movie.IsInMixedFolder = false; movie.Name = Path.GetFileName(movie.ContainingFolderPath); return(movie); } } if (result.Items.Count == 0 && multiDiscFolders.Count > 0) { return(GetMultiDiscMovie <T>(multiDiscFolders, directoryService)); } return(null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Series.</returns> protected override Series Resolve(ItemResolveArgs args) { if (args.IsDirectory) { if (args.HasParent <Series>() || args.HasParent <Season>()) { return(null); } var collectionType = args.GetCollectionType(); if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { //if (args.ContainsFileSystemEntryByName("tvshow.nfo")) //{ // return new Series // { // Path = args.Path, // Name = Path.GetFileName(args.Path) // }; //} var configuredContentType = _libraryManager.GetConfiguredContentType(args.Path); if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { return(new Series { Path = args.Path, Name = Path.GetFileName(args.Path) }); } } else if (string.IsNullOrEmpty(collectionType)) { if (args.ContainsFileSystemEntryByName("tvshow.nfo")) { if (args.Parent.IsRoot) { // For now, return null, but if we want to allow this in the future then add some additional checks to guard against a misplaced tvshow.nfo return(null); } return(new Series { Path = args.Path, Name = Path.GetFileName(args.Path) }); } if (args.Parent.IsRoot) { return(null); } if (IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager, args.GetLibraryOptions(), false)) { return(new Series { Path = args.Path, Name = Path.GetFileName(args.Path) }); } } } return(null); }
/// <summary> /// Resolves the video. /// </summary> /// <typeparam name="TVideoType">The type of the T video type.</typeparam> /// <param name="args">The args.</param> /// <param name="parseName">if set to <c>true</c> [parse name].</param> /// <returns>``0.</returns> protected TVideoType ResolveVideo <TVideoType>(ItemResolveArgs args, bool parseName) where TVideoType : Video, new() { var namingOptions = ((LibraryManager)LibraryManager).GetNamingOptions(); // If the path is a file check for a matching extensions var parser = new MediaBrowser.Naming.Video.VideoResolver(namingOptions, new NullLogger()); if (args.IsDirectory) { TVideoType video = null; VideoFileInfo videoInfo = null; // Loop through each child file/folder and see if we find a video foreach (var child in args.FileSystemChildren) { var filename = child.Name; if (child.IsDirectory) { if (IsDvdDirectory(child.FullName, filename, args.DirectoryService)) { videoInfo = parser.ResolveDirectory(args.Path); if (videoInfo == null) { return(null); } video = new TVideoType { Path = args.Path, VideoType = VideoType.Dvd, ProductionYear = videoInfo.Year }; break; } if (IsBluRayDirectory(child.FullName, filename, args.DirectoryService)) { videoInfo = parser.ResolveDirectory(args.Path); if (videoInfo == null) { return(null); } video = new TVideoType { Path = args.Path, VideoType = VideoType.BluRay, ProductionYear = videoInfo.Year }; break; } } else if (IsDvdFile(filename)) { videoInfo = parser.ResolveDirectory(args.Path); if (videoInfo == null) { return(null); } video = new TVideoType { Path = args.Path, VideoType = VideoType.Dvd, ProductionYear = videoInfo.Year }; break; } } if (video != null) { video.Name = parseName ? videoInfo.Name : Path.GetFileName(args.Path); Set3DFormat(video, videoInfo); } return(video); } else { var videoInfo = parser.Resolve(args.Path, false, false); if (videoInfo == null) { return(null); } if (LibraryManager.IsVideoFile(args.Path, args.GetLibraryOptions()) || videoInfo.IsStub) { var path = args.Path; var video = new TVideoType { Path = path, IsInMixedFolder = true, ProductionYear = videoInfo.Year }; SetVideoType(video, videoInfo); video.Name = parseName ? videoInfo.Name : Path.GetFileNameWithoutExtension(args.Path); Set3DFormat(video, videoInfo); return(video); } } return(null); }
/// <summary> /// Determine if the supplied resolve args should be considered a music album /// </summary> /// <param name="args">The args.</param> /// <returns><c>true</c> if [is music album] [the specified args]; otherwise, <c>false</c>.</returns> private bool IsMusicAlbum(ItemResolveArgs args) { // Args points to an album if parent is an Artist folder or it directly contains music if (args.IsDirectory) { // if (args.Parent is MusicArtist) return true; //saves us from testing children twice if (ContainsMusic(args.FileSystemChildren, true, args.DirectoryService, _logger, _fileSystem, args.GetLibraryOptions(), _libraryManager)) { return true; } } return false; }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Entities.Audio.Audio.</returns> protected override MediaBrowser.Controller.Entities.Audio.Audio Resolve(ItemResolveArgs args) { // Return audio if the path is a file and has a matching extension var libraryOptions = args.GetLibraryOptions(); var collectionType = args.GetCollectionType(); var isBooksCollectionType = string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase); if (args.IsDirectory) { if (!isBooksCollectionType) { return(null); } var files = args.FileSystemChildren .Where(i => !LibraryManager.IgnoreFile(i, args.Parent)) .ToList(); return(FindAudio <AudioBook>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false)); } if (LibraryManager.IsAudioFile(args.Path, libraryOptions)) { var extension = Path.GetExtension(args.Path); if (string.Equals(extension, ".cue", StringComparison.OrdinalIgnoreCase)) { // if audio file exists of same name, return null return(null); } var isMixedCollectionType = string.IsNullOrEmpty(collectionType); // For conflicting extensions, give priority to videos if (isMixedCollectionType && LibraryManager.IsVideoFile(args.Path, libraryOptions)) { return(null); } MediaBrowser.Controller.Entities.Audio.Audio item = null; var isMusicCollectionType = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase); // Use regular audio type for mixed libraries, owned items and music if (isMixedCollectionType || args.Parent == null || isMusicCollectionType) { item = new MediaBrowser.Controller.Entities.Audio.Audio(); } else if (isBooksCollectionType) { item = new AudioBook(); } if (item != null) { item.IsShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase); item.IsInMixedFolder = true; } return(item); } return(null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>MusicArtist.</returns> protected override MusicArtist Resolve(ItemResolveArgs args) { if (!args.IsDirectory) { return(null); } // Don't allow nested artists if (args.HasParent <MusicArtist>() || args.HasParent <MusicAlbum>()) { return(null); } var collectionType = args.GetCollectionType(); var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase); // If there's a collection type and it's not music, it can't be a series if (!isMusicMediaFolder) { return(null); } if (args.ContainsFileSystemEntryByName("artist.nfo")) { return(new MusicArtist()); } if (_config.Configuration.EnableSimpleArtistDetection) { return(null); } // Avoid mis-identifying top folders if (args.Parent.IsRoot) { return(null); } var directoryService = args.DirectoryService; var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager); // If we contain an album assume we are an artist folder return(args.FileSystemChildren.Where(i => i.IsDirectory).Any(i => albumResolver.IsMusicAlbum(i.FullName, directoryService, args.GetLibraryOptions())) ? new MusicArtist() : null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Season.</returns> protected override Season Resolve(ItemResolveArgs args) { if (args.Parent is Series && args.IsDirectory) { var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions(); var series = ((Series)args.Parent); var season = new Season { IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(args.Path, true, true).SeasonNumber, SeriesId = series.Id, SeriesName = series.Name }; if (season.IndexNumber.HasValue) { var seasonNumber = season.IndexNumber.Value; season.Name = seasonNumber == 0 ? args.LibraryOptions.SeasonZeroDisplayName : string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.ToString(UsCulture), args.GetLibraryOptions().PreferredMetadataLanguage); } return(season); } return(null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Trailer.</returns> protected override Photo Resolve(ItemResolveArgs args) { if (!args.IsDirectory) { // Must be an image file within a photo collection var collectionType = args.GetCollectionType(); if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) || (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos)) { if (IsImageFile(args.Path, _imageProcessor)) { var filename = Path.GetFileNameWithoutExtension(args.Path); // Make sure the image doesn't belong to a video file if (_fileSystem.GetFilePaths(_fileSystem.GetDirectoryName(args.Path)).Any(i => IsOwnedByMedia(args.GetLibraryOptions(), i, filename))) { return(null); } return(new Photo { Path = args.Path }); } } } return(null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Trailer.</returns> protected override PhotoAlbum Resolve(ItemResolveArgs args) { // Must be an image file within a photo collection if (args.IsDirectory) { // Must be an image file within a photo collection var collectionType = args.GetCollectionType(); if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) || (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos)) { if (HasPhotos(args)) { return(new PhotoAlbum { Path = args.Path }); } } } return(null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Season.</returns> protected override Season Resolve(ItemResolveArgs args) { if (args.Parent is Series && args.IsDirectory) { var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions(); var series = ((Series)args.Parent); var path = args.Path; var season = new Season { IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(path, true, true).SeasonNumber, SeriesId = series.Id, SeriesName = series.Name }; if (season.IndexNumber.HasValue) { var resolver = new Emby.Naming.TV.EpisodeResolver(namingOptions); var episodeInfo = resolver.Resolve(path, true); if (episodeInfo != null) { if (episodeInfo.EpisodeNumber.HasValue && episodeInfo.SeasonNumber.HasValue) { _logger.Info("Found folder underneath series with episode number: {0}. Season {1}. Episode {2}", path, episodeInfo.SeasonNumber.Value, episodeInfo.EpisodeNumber.Value); return(null); } } var seasonNumber = season.IndexNumber.Value; season.Name = seasonNumber == 0 ? args.LibraryOptions.SeasonZeroDisplayName : string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.ToString(UsCulture), args.GetLibraryOptions().PreferredMetadataLanguage); } return(season); } return(null); }
/// <summary> /// Resolves the specified args. /// </summary> /// <param name="args">The args.</param> /// <returns>Series.</returns> protected override Series Resolve(ItemResolveArgs args) { if (args.IsDirectory) { if (args.HasParent <Series>()) { return(null); } var collectionType = args.GetCollectionType(); if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { var configuredContentType = _libraryManager.GetConfiguredContentType(args.Path); if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { return(new Series { Path = args.Path, Name = Path.GetFileName(args.Path) }); } } else { if (string.IsNullOrWhiteSpace(collectionType)) { if (args.Parent.IsRoot) { return(null); } if (IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager, args.GetLibraryOptions(), false)) { return(new Series { Path = args.Path, Name = Path.GetFileName(args.Path) }); } } } } return(null); }