2016-03-27 21:11:27 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2015-01-10 01:38:01 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-03-03 16:53:58 +00:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2015-01-10 01:38:01 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Naming.Common;
|
|
|
|
|
using MediaBrowser.Naming.TV;
|
2015-01-17 04:38:24 +00:00
|
|
|
|
using MediaBrowser.Server.Implementations.Logging;
|
2015-03-02 18:48:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2015-10-04 04:23:11 +00:00
|
|
|
|
using CommonIO;
|
2016-08-13 05:49:00 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2016-08-13 20:54:29 +00:00
|
|
|
|
using MediaBrowser.Model.Configuration;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-03-03 06:58:04 +00:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class SeriesResolver
|
|
|
|
|
/// </summary>
|
2013-03-03 06:58:04 +00:00
|
|
|
|
public class SeriesResolver : FolderResolver<Series>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2015-01-10 01:38:01 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override ResolverPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ResolverPriority.Second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves the specified args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
|
/// <returns>Series.</returns>
|
|
|
|
|
protected override Series Resolve(ItemResolveArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (args.IsDirectory)
|
|
|
|
|
{
|
2016-09-15 23:19:27 +00:00
|
|
|
|
if (args.HasParent<Series>() || args.HasParent<Season>())
|
2016-09-03 17:16:36 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:07:35 +00:00
|
|
|
|
var collectionType = args.GetCollectionType();
|
2014-12-28 06:21:39 +00:00
|
|
|
|
if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2015-01-10 01:38:01 +00:00
|
|
|
|
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))
|
2014-11-29 19:51:30 +00:00
|
|
|
|
{
|
2015-01-10 01:38:01 +00:00
|
|
|
|
if (args.Parent.IsRoot)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-09-15 23:19:27 +00:00
|
|
|
|
if (IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager, args.GetLibraryOptions(), false) ||
|
|
|
|
|
args.ContainsFileSystemEntryByName("tvshow.nfo"))
|
2015-01-10 01:38:01 +00:00
|
|
|
|
{
|
|
|
|
|
return new Series
|
|
|
|
|
{
|
|
|
|
|
Path = args.Path,
|
|
|
|
|
Name = Path.GetFileName(args.Path)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-10 01:38:01 +00:00
|
|
|
|
public static bool IsSeriesFolder(string path,
|
2015-10-04 03:38:46 +00:00
|
|
|
|
IEnumerable<FileSystemMetadata> fileSystemChildren,
|
2015-01-10 01:38:01 +00:00
|
|
|
|
IDirectoryService directoryService,
|
|
|
|
|
IFileSystem fileSystem,
|
|
|
|
|
ILogger logger,
|
|
|
|
|
ILibraryManager libraryManager,
|
2016-08-13 05:49:00 +00:00
|
|
|
|
LibraryOptions libraryOptions,
|
2015-01-10 01:38:01 +00:00
|
|
|
|
bool isTvContentType)
|
|
|
|
|
{
|
|
|
|
|
foreach (var child in fileSystemChildren)
|
|
|
|
|
{
|
|
|
|
|
var attributes = child.Attributes;
|
|
|
|
|
|
2015-08-10 17:37:50 +00:00
|
|
|
|
//if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
|
|
|
|
//{
|
|
|
|
|
// //logger.Debug("Igoring series file or folder marked hidden: {0}", child.FullName);
|
|
|
|
|
// continue;
|
|
|
|
|
//}
|
2015-01-10 01:38:01 +00:00
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
2015-07-23 16:32:34 +00:00
|
|
|
|
if (IsSeasonFolder(child.FullName, isTvContentType, libraryManager))
|
2015-01-10 01:38:01 +00:00
|
|
|
|
{
|
|
|
|
|
//logger.Debug("{0} is a series because of season folder {1}.", path, child.FullName);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string fullName = child.FullName;
|
2016-08-13 05:49:00 +00:00
|
|
|
|
if (libraryManager.IsVideoFile(fullName, libraryOptions))
|
2015-01-10 01:38:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (isTvContentType)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-10 05:53:35 +00:00
|
|
|
|
var namingOptions = ((LibraryManager)libraryManager).GetNamingOptions();
|
|
|
|
|
|
2015-01-10 19:42:14 +00:00
|
|
|
|
// In mixed folders we need to be conservative and avoid expressions that may result in false positives (e.g. movies with numbers in the title)
|
|
|
|
|
if (!isTvContentType)
|
|
|
|
|
{
|
|
|
|
|
namingOptions.EpisodeExpressions = namingOptions.EpisodeExpressions
|
2015-01-12 05:01:24 +00:00
|
|
|
|
.Where(i => i.IsNamed && !i.IsOptimistic)
|
2015-01-10 19:42:14 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-17 04:38:24 +00:00
|
|
|
|
var episodeResolver = new Naming.TV.EpisodeResolver(namingOptions, new PatternsLogger());
|
2015-04-29 18:48:34 +00:00
|
|
|
|
var episodeInfo = episodeResolver.Resolve(fullName, false, false);
|
2015-01-10 01:38:01 +00:00
|
|
|
|
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>
|
2015-07-23 16:32:34 +00:00
|
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
2015-01-10 01:38:01 +00:00
|
|
|
|
/// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns>
|
2015-07-23 16:32:34 +00:00
|
|
|
|
private static bool IsSeasonFolder(string path, bool isTvContentType, ILibraryManager libraryManager)
|
2015-01-10 01:38:01 +00:00
|
|
|
|
{
|
2015-07-23 16:32:34 +00:00
|
|
|
|
var namingOptions = ((LibraryManager)libraryManager).GetNamingOptions();
|
|
|
|
|
|
|
|
|
|
var seasonNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(path, isTvContentType, isTvContentType).SeasonNumber;
|
2015-01-10 01:38:01 +00:00
|
|
|
|
|
|
|
|
|
return seasonNumber.HasValue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the initial item values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
|
protected override void SetInitialItemValues(Series item, ItemResolveArgs args)
|
|
|
|
|
{
|
|
|
|
|
base.SetInitialItemValues(item, args);
|
|
|
|
|
|
2013-03-03 06:58:04 +00:00
|
|
|
|
SetProviderIdFromPath(item, args.Path);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the provider id from path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
2013-04-10 16:04:13 +00:00
|
|
|
|
/// <param name="path">The path.</param>
|
2013-03-03 06:58:04 +00:00
|
|
|
|
private void SetProviderIdFromPath(Series item, string path)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-03-03 06:58:04 +00:00
|
|
|
|
var justName = Path.GetFileName(path);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
var id = justName.GetAttributeValue("tvdbid");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tvdb, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|