2019-01-06 13:50:43 -07:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-20 18:33:05 -07:00
|
|
|
using MediaBrowser.Controller.Library;
|
2015-01-09 18:38:01 -07:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-03-03 09:53:58 -07:00
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-02-20 18:33:05 -07:00
|
|
|
using MediaBrowser.Model.Entities;
|
2018-12-13 06:18:25 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
2017-09-10 13:40:31 -07:00
|
|
|
using Emby.Naming.Common;
|
|
|
|
using Emby.Naming.TV;
|
2015-03-02 11:48:21 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2017-05-25 23:48:54 -07:00
|
|
|
|
2016-10-25 12:02:04 -07:00
|
|
|
using MediaBrowser.Model.IO;
|
2016-08-12 22:49:00 -07:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2016-10-25 12:02:04 -07:00
|
|
|
using MediaBrowser.Controller.IO;
|
2016-08-13 13:54:29 -07:00
|
|
|
using MediaBrowser.Model.Configuration;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
2016-11-02 23:37:52 -07:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers.TV
|
2013-02-20 18:33:05 -07:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class SeriesResolver
|
|
|
|
/// </summary>
|
2013-03-02 23:58:04 -07:00
|
|
|
public class SeriesResolver : FolderResolver<Series>
|
2013-02-20 18:33:05 -07:00
|
|
|
{
|
2015-01-09 18:38:01 -07: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-20 18:33:05 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the priority.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The priority.</value>
|
2019-01-06 13:50:43 -07:00
|
|
|
public override ResolverPriority Priority => ResolverPriority.Second;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
/// <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 16:19:27 -07:00
|
|
|
if (args.HasParent<Series>() || args.HasParent<Season>())
|
2016-09-03 10:16:36 -07:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:07:35 -07:00
|
|
|
var collectionType = args.GetCollectionType();
|
2014-12-27 23:21:39 -07:00
|
|
|
if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
|
2013-02-20 18:33:05 -07:00
|
|
|
{
|
2016-10-13 14:13:30 -07:00
|
|
|
//if (args.ContainsFileSystemEntryByName("tvshow.nfo"))
|
|
|
|
//{
|
|
|
|
// return new Series
|
|
|
|
// {
|
|
|
|
// Path = args.Path,
|
|
|
|
// Name = Path.GetFileName(args.Path)
|
|
|
|
// };
|
|
|
|
//}
|
2016-10-13 11:43:47 -07:00
|
|
|
|
2015-01-09 18:38:01 -07: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)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 10:26:21 -07:00
|
|
|
else if (string.IsNullOrEmpty(collectionType))
|
2015-01-09 18:38:01 -07:00
|
|
|
{
|
2016-10-13 11:43:47 -07:00
|
|
|
if (args.ContainsFileSystemEntryByName("tvshow.nfo"))
|
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
if (args.Parent != null && args.Parent.IsRoot)
|
2016-10-15 15:12:16 -07:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2016-10-13 11:43:47 -07:00
|
|
|
return new Series
|
|
|
|
{
|
|
|
|
Path = args.Path,
|
|
|
|
Name = Path.GetFileName(args.Path)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (args.Parent != null && args.Parent.IsRoot)
|
2014-11-29 12:51:30 -07:00
|
|
|
{
|
2016-10-09 00:18:43 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager, args.GetLibraryOptions(), false))
|
|
|
|
{
|
|
|
|
return new Series
|
2015-01-09 18:38:01 -07:00
|
|
|
{
|
2016-10-09 00:18:43 -07:00
|
|
|
Path = args.Path,
|
|
|
|
Name = Path.GetFileName(args.Path)
|
|
|
|
};
|
2015-01-09 18:38:01 -07:00
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:38:01 -07:00
|
|
|
public static bool IsSeriesFolder(string path,
|
2015-10-03 20:38:46 -07:00
|
|
|
IEnumerable<FileSystemMetadata> fileSystemChildren,
|
2015-01-09 18:38:01 -07:00
|
|
|
IDirectoryService directoryService,
|
|
|
|
IFileSystem fileSystem,
|
|
|
|
ILogger logger,
|
|
|
|
ILibraryManager libraryManager,
|
2016-08-12 22:49:00 -07:00
|
|
|
LibraryOptions libraryOptions,
|
2015-01-09 18:38:01 -07:00
|
|
|
bool isTvContentType)
|
|
|
|
{
|
|
|
|
foreach (var child in fileSystemChildren)
|
|
|
|
{
|
2015-08-10 10:37:50 -07:00
|
|
|
//if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
|
|
|
//{
|
2018-12-13 06:18:25 -07:00
|
|
|
// //logger.LogDebug("Igoring series file or folder marked hidden: {0}", child.FullName);
|
2015-08-10 10:37:50 -07:00
|
|
|
// continue;
|
|
|
|
//}
|
2015-01-09 18:38:01 -07:00
|
|
|
|
|
|
|
// Can't enforce this because files saved by Bitcasa are always marked System
|
|
|
|
//if ((attributes & FileAttributes.System) == FileAttributes.System)
|
|
|
|
//{
|
2018-12-13 06:18:25 -07:00
|
|
|
// logger.LogDebug("Igoring series subfolder marked system: {0}", child.FullName);
|
2015-01-09 18:38:01 -07:00
|
|
|
// continue;
|
|
|
|
//}
|
|
|
|
|
2016-10-25 12:02:04 -07:00
|
|
|
if (child.IsDirectory)
|
2015-01-09 18:38:01 -07:00
|
|
|
{
|
2015-07-23 09:32:34 -07:00
|
|
|
if (IsSeasonFolder(child.FullName, isTvContentType, libraryManager))
|
2015-01-09 18:38:01 -07:00
|
|
|
{
|
2018-12-13 06:18:25 -07:00
|
|
|
//logger.LogDebug("{0} is a series because of season folder {1}.", path, child.FullName);
|
2015-01-09 18:38:01 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string fullName = child.FullName;
|
2016-08-12 22:49:00 -07:00
|
|
|
if (libraryManager.IsVideoFile(fullName, libraryOptions))
|
2015-01-09 18:38:01 -07:00
|
|
|
{
|
|
|
|
if (isTvContentType)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
var namingOptions = ((LibraryManager)libraryManager).GetNamingOptions();
|
2015-01-10 12:42:14 -07:00
|
|
|
|
2017-09-10 13:40:31 -07:00
|
|
|
var episodeResolver = new Emby.Naming.TV.EpisodeResolver(namingOptions);
|
2018-09-12 10:26:21 -07:00
|
|
|
bool? isNamed = null;
|
|
|
|
bool? isOptimistic = null;
|
|
|
|
|
|
|
|
if (!isTvContentType)
|
|
|
|
{
|
|
|
|
isNamed = true;
|
|
|
|
isOptimistic = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var episodeInfo = episodeResolver.Resolve(fullName, false, isNamed, isOptimistic, null, false);
|
2015-01-09 18:38:01 -07:00
|
|
|
if (episodeInfo != null && episodeInfo.EpisodeNumber.HasValue)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 06:18:25 -07:00
|
|
|
//logger.LogDebug("{0} is not a series folder.", path);
|
2015-01-09 18:38:01 -07:00
|
|
|
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))
|
|
|
|
{
|
2019-01-06 13:50:43 -07:00
|
|
|
throw new ArgumentNullException(nameof(path));
|
2015-01-09 18:38:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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 09:32:34 -07:00
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
2015-01-09 18:38:01 -07:00
|
|
|
/// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns>
|
2015-07-23 09:32:34 -07:00
|
|
|
private static bool IsSeasonFolder(string path, bool isTvContentType, ILibraryManager libraryManager)
|
2015-01-09 18:38:01 -07:00
|
|
|
{
|
2015-07-23 09:32:34 -07:00
|
|
|
var namingOptions = ((LibraryManager)libraryManager).GetNamingOptions();
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
var seasonNumber = new SeasonPathParser(namingOptions).Parse(path, isTvContentType, isTvContentType).SeasonNumber;
|
2015-01-09 18:38:01 -07:00
|
|
|
|
|
|
|
return seasonNumber.HasValue;
|
|
|
|
}
|
|
|
|
|
2013-02-20 18:33:05 -07: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-02 23:58:04 -07:00
|
|
|
SetProviderIdFromPath(item, args.Path);
|
2013-02-20 18:33:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets the provider id from path.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
2013-04-10 09:04:13 -07:00
|
|
|
/// <param name="path">The path.</param>
|
2019-01-06 13:50:43 -07:00
|
|
|
private static void SetProviderIdFromPath(Series item, string path)
|
2013-02-20 18:33:05 -07:00
|
|
|
{
|
2013-03-02 23:58:04 -07:00
|
|
|
var justName = Path.GetFileName(path);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
var id = justName.GetAttributeValue("tvdbid");
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
|
|
{
|
|
|
|
item.SetProviderId(MetadataProviders.Tvdb, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|