add new sync methods

This commit is contained in:
Luke Pulverenti
2014-12-15 00:16:23 -05:00
parent ed31b883f4
commit e92e036574
21 changed files with 169 additions and 59 deletions

View File

@@ -1708,7 +1708,7 @@ namespace MediaBrowser.Server.Implementations.Library
public int? GetSeasonNumberFromPath(string path)
{
return SeriesResolver.GetSeasonNumberFromPath(path);
return SeriesResolver.GetSeasonNumberFromPath(path, CollectionType.TvShows);
}
public int? GetSeasonNumberFromEpisodeFile(string path)

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}
}
}

View File

@@ -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)

View File

@@ -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;