diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-12-15 00:16:23 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-12-15 00:16:23 -0500 |
| commit | e92e0365747c04f081be0efbb9afb78dc96aef9b (patch) | |
| tree | 51a7d2c0647d491737ca0bf9b9b8b3a11e9ee313 /MediaBrowser.Server.Implementations/Library/Resolvers | |
| parent | ed31b883f4bf1884ee974171501e61f83c768379 (diff) | |
add new sync methods
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers')
5 files changed, 51 insertions, 19 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 7f844ca0e..f32ed2b20 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; @@ -9,10 +8,10 @@ using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Naming.Audio; +using MediaBrowser.Naming.Common; using System; using System.Collections.Generic; using System.IO; -using MediaBrowser.Naming.Common; namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { @@ -53,10 +52,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio //Avoid mis-identifying top folders if (args.Parent == null) return null; if (args.Parent.IsRoot) return null; - if (args.Parent is MusicAlbum) return null; + if (args.HasParent<MusicAlbum>()) return null; // Optimization - if (args.Parent is BoxSet || args.Parent is Series || args.Parent is Season) + if (args.HasParent<BoxSet>() || args.HasParent<Series>() || args.HasParent<Season>()) { return null; } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs index 53063b35e..71b6c0843 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs @@ -51,13 +51,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio if (args.Parent.IsRoot) return null; // Don't allow nested artists - if (args.Parent is MusicArtist) + if (args.HasParent<MusicArtist>() || args.HasParent<MusicAlbum>()) { return null; } // Optimization - if (args.Parent is BoxSet || args.Parent is Series || args.Parent is Season) + if (args.HasParent<BoxSet>() || args.HasParent<Series>() || args.HasParent<Season>()) { return null; } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 9f714cfc5..276b99d3a 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -456,7 +456,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies // Don't do any resolving within a series structure if (string.IsNullOrEmpty(collectionType)) { - if (parent is Season || parent is Series) + if (HasParent<Series>(parent) || HasParent<Season>(parent)) { return true; } @@ -480,5 +480,25 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase); } + + private bool HasParent<T>(Folder parent) + where T : Folder + { + if (parent != null) + { + var item = parent as T; + + // Just in case the user decided to nest episodes. + // Not officially supported but in some cases we can handle it. + if (item == null) + { + item = parent.Parents.OfType<T>().FirstOrDefault(); + } + + return item != null; + + } + return false; + } } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs index d3580aaf8..058fb1489 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Entities; namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { @@ -34,7 +35,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV { var season = new Season { - IndexNumber = SeriesResolver.GetSeasonNumberFromPath(args.Path) + IndexNumber = SeriesResolver.GetSeasonNumberFromPath(args.Path, CollectionType.TvShows) }; 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 ce7491524..72c0bae53 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs @@ -60,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV } // Optimization to avoid running these tests against Seasons - if (args.Parent is Series || args.Parent is Season || args.Parent is MusicArtist || args.Parent is MusicAlbum) + if (args.HasParent<Series>() || args.HasParent<Season>() || args.HasParent<MusicArtist>() || args.HasParent<MusicAlbum>()) { return null; } @@ -78,7 +78,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return null; } - if (IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager)) + if (IsSeriesFolder(args.Path, collectionType, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager)) { return new Series { @@ -95,14 +95,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV /// Determines whether [is series folder] [the specified path]. /// </summary> /// <param name="path">The path.</param> - /// <param name="considerSeasonlessEntries">if set to <c>true</c> [consider seasonless entries].</param> + /// <param name="collectionType">Type of the collection.</param> /// <param name="fileSystemChildren">The file system children.</param> /// <param name="directoryService">The directory service.</param> /// <param name="fileSystem">The file system.</param> /// <param name="logger">The logger.</param> /// <param name="libraryManager">The library manager.</param> /// <returns><c>true</c> if [is series folder] [the specified path]; otherwise, <c>false</c>.</returns> - public static bool IsSeriesFolder(string path, bool considerSeasonlessEntries, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService, IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager) + public static bool IsSeriesFolder(string path, string collectionType, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService, IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager) { foreach (var child in fileSystemChildren) { @@ -123,7 +123,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV if ((attributes & FileAttributes.Directory) == FileAttributes.Directory) { - if (IsSeasonFolder(child.FullName, directoryService, fileSystem)) + if (IsSeasonFolder(child.FullName, collectionType, directoryService, fileSystem)) { //logger.Debug("{0} is a series because of season folder {1}.", path, child.FullName); return true; @@ -135,7 +135,9 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV if (libraryManager.IsVideoFile(fullName) || IsVideoPlaceHolder(fullName)) { - if (GetEpisodeNumberFromFile(fullName, considerSeasonlessEntries).HasValue) + var isTvShowsFolder = string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase); + + if (GetEpisodeNumberFromFile(fullName, isTvShowsFolder).HasValue) { return true; } @@ -169,12 +171,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV /// Determines whether [is season folder] [the specified path]. /// </summary> /// <param name="path">The path.</param> + /// <param name="collectionType">Type of the collection.</param> /// <param name="directoryService">The directory service.</param> /// <param name="fileSystem">The file system.</param> /// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns> - private static bool IsSeasonFolder(string path, IDirectoryService directoryService, IFileSystem fileSystem) + private static bool IsSeasonFolder(string path, string collectionType, IDirectoryService directoryService, IFileSystem fileSystem) { - var seasonNumber = GetSeasonNumberFromPath(path); + var seasonNumber = GetSeasonNumberFromPath(path, collectionType); var hasSeasonNumber = seasonNumber != null; if (!hasSeasonNumber) @@ -309,18 +312,27 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV // "blah - 01.avi", "blah 2 - 01.avi", "blah - 01 blah.avi", "blah 2 - 01 blah", "blah - 01 - blah.avi", "blah 2 - 01 - blah" }; + public static int? GetSeasonNumberFromPath(string path) + { + return GetSeasonNumberFromPath(path, CollectionType.TvShows); + } + /// <summary> /// Gets the season number from path. /// </summary> /// <param name="path">The path.</param> + /// <param name="collectionType">Type of the collection.</param> /// <returns>System.Nullable{System.Int32}.</returns> - public static int? GetSeasonNumberFromPath(string path) + public static int? GetSeasonNumberFromPath(string path, string collectionType) { var filename = Path.GetFileName(path); - if (string.Equals(filename, "specials", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { - return 0; + if (string.Equals(filename, "specials", StringComparison.OrdinalIgnoreCase)) + { + return 0; + } } int val; |
