diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-01-09 20:38:01 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-01-09 20:38:01 -0500 |
| commit | 0024aa44ee1f316dc2c9d7d41d9306dd168159ea (patch) | |
| tree | 9f6c9a2499f6f588dbec4e87e946d175348525c1 /MediaBrowser.Server.Implementations/Library/Resolvers | |
| parent | 064c9a02f7a12291d6c60962943a1a3be5c622e6 (diff) | |
update series resolving
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers')
3 files changed, 158 insertions, 17 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index a1c762283..d1a6cbbf8 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -129,17 +129,26 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { var path = fileSystemInfo.FullName; var isMultiDisc = IsMultiDiscFolder(path); - var hasMusic = ContainsMusic(directoryService.GetFileSystemEntries(path), false, directoryService, logger, fileSystem, libraryManager); - if (isMultiDisc && hasMusic) + if (isMultiDisc) { - logger.Debug("Found multi-disc folder: " + path); - discSubfolderCount++; + var hasMusic = ContainsMusic(directoryService.GetFileSystemEntries(path), false, directoryService, logger, fileSystem, libraryManager); + + if (hasMusic) + { + logger.Debug("Found multi-disc folder: " + path); + discSubfolderCount++; + } } - else if (hasMusic) + else { - // If there are folders underneath with music that are not multidisc, then this can't be a multi-disc album - notMultiDisc = true; + var hasMusic = ContainsMusic(directoryService.GetFileSystemEntries(path), false, directoryService, logger, fileSystem, libraryManager); + + if (hasMusic) + { + // If there are folders underneath with music that are not multidisc, then this can't be a multi-disc album + notMultiDisc = true; + } } } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs index 80477e567..fe4832d48 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs @@ -36,7 +36,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { var season = new Season { - IndexNumber = new SeasonPathParser(new ExtendedNamingOptions(), new RegexProvider()).Parse(args.Path, true).SeasonNumber + IndexNumber = new SeasonPathParser(new ExtendedNamingOptions(), new RegexProvider()).Parse(args.Path, true, true).SeasonNumber }; if (season.IndexNumber.HasValue && season.IndexNumber.Value == 0) diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs index 7f1416ad6..ee0fe6b94 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs @@ -1,9 +1,17 @@ -using MediaBrowser.Controller.Entities.TV; +using System.Collections.Generic; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; using System.IO; +using MediaBrowser.Model.Logging; +using MediaBrowser.Naming.Common; +using MediaBrowser.Naming.IO; +using MediaBrowser.Naming.TV; +using EpisodeInfo = MediaBrowser.Controller.Providers.EpisodeInfo; namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { @@ -12,6 +20,17 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV /// </summary> public class SeriesResolver : FolderResolver<Series> { + private readonly IFileSystem _fileSystem; + private readonly ILogger _logger; + private readonly ILibraryManager _libraryManager; + + public SeriesResolver(IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager) + { + _fileSystem = fileSystem; + _logger = logger; + _libraryManager = libraryManager; + } + /// <summary> /// Gets the priority. /// </summary> @@ -34,26 +53,139 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV if (args.IsDirectory) { var collectionType = args.GetCollectionType(); - - // If there's a collection type and it's not tv, it can't be a series if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { if (args.HasParent<Series>()) { return null; - } - - return new Series + } + + 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 (args.HasParent<Series>()) + { + return null; + } + + if (string.IsNullOrWhiteSpace(collectionType)) { - 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, false)) + { + return new Series + { + Path = args.Path, + Name = Path.GetFileName(args.Path) + }; + } + } } } return null; } + public static bool IsSeriesFolder(string path, + IEnumerable<FileSystemInfo> fileSystemChildren, + IDirectoryService directoryService, + IFileSystem fileSystem, + ILogger logger, + ILibraryManager libraryManager, + bool isTvContentType) + { + foreach (var child in fileSystemChildren) + { + var attributes = child.Attributes; + + if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) + { + //logger.Debug("Igoring series file or folder marked hidden: {0}", child.FullName); + continue; + } + + // Can't enforce this because files saved by Bitcasa are always marked System + //if ((attributes & FileAttributes.System) == FileAttributes.System) + //{ + // logger.Debug("Igoring series subfolder marked system: {0}", child.FullName); + // continue; + //} + + if ((attributes & FileAttributes.Directory) == FileAttributes.Directory) + { + if (IsSeasonFolder(child.FullName, isTvContentType)) + { + //logger.Debug("{0} is a series because of season folder {1}.", path, child.FullName); + return true; + } + } + else + { + string fullName = child.FullName; + if (libraryManager.IsVideoFile(fullName)) + { + if (isTvContentType) + { + return true; + } + + var episodeResolver = new Naming.TV.EpisodeResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger()); + var episodeInfo = episodeResolver.Resolve(fullName, FileInfoType.File, false); + if (episodeInfo != null && episodeInfo.EpisodeNumber.HasValue) + { + return true; + } + } + } + } + + logger.Debug("{0} is not a series folder.", path); + return false; + } + + /// <summary> + /// Determines whether [is place holder] [the specified path]. + /// </summary> + /// <param name="path">The path.</param> + /// <returns><c>true</c> if [is place holder] [the specified path]; otherwise, <c>false</c>.</returns> + /// <exception cref="System.ArgumentNullException">path</exception> + private static bool IsVideoPlaceHolder(string path) + { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + + var extension = Path.GetExtension(path); + + return string.Equals(extension, ".disc", StringComparison.OrdinalIgnoreCase); + } + + /// <summary> + /// Determines whether [is season folder] [the specified path]. + /// </summary> + /// <param name="path">The path.</param> + /// <param name="isTvContentType">if set to <c>true</c> [is tv content type].</param> + /// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns> + private static bool IsSeasonFolder(string path, bool isTvContentType) + { + var seasonNumber = new SeasonPathParser(new ExtendedNamingOptions(), new RegexProvider()).Parse(path, isTvContentType, isTvContentType).SeasonNumber; + + return seasonNumber.HasValue; + } + /// <summary> /// Sets the initial item values. /// </summary> |
