2019-01-06 13:50:43 -07:00
|
|
|
using System.Globalization;
|
2019-01-13 12:21:32 -07:00
|
|
|
using Emby.Naming.TV;
|
2017-08-23 09:48:03 -07:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-05-24 08:01:53 -07:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-20 18:33:05 -07:00
|
|
|
using MediaBrowser.Controller.Library;
|
2017-08-23 09:48:03 -07:00
|
|
|
using MediaBrowser.Model.Globalization;
|
2018-12-13 06:18:25 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
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
|
|
|
{
|
2013-02-23 00:57:11 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Class SeasonResolver
|
|
|
|
/// </summary>
|
2013-03-02 23:58:04 -07:00
|
|
|
public class SeasonResolver : FolderResolver<Season>
|
2013-02-20 18:33:05 -07:00
|
|
|
{
|
2013-05-24 08:01:53 -07:00
|
|
|
/// <summary>
|
|
|
|
/// The _config
|
|
|
|
/// </summary>
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
2015-01-09 22:53:35 -07:00
|
|
|
private readonly ILibraryManager _libraryManager;
|
2017-08-23 09:48:03 -07:00
|
|
|
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
|
|
|
private readonly ILocalizationManager _localization;
|
2017-11-20 13:08:20 -07:00
|
|
|
private readonly ILogger _logger;
|
2015-01-09 22:53:35 -07:00
|
|
|
|
2013-05-24 08:01:53 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="SeasonResolver"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="config">The config.</param>
|
2019-01-06 13:50:43 -07:00
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
|
|
|
/// <param name="localization">The localization</param>
|
|
|
|
/// <param name="logger">The logger</param>
|
2017-11-20 13:08:20 -07:00
|
|
|
public SeasonResolver(IServerConfigurationManager config, ILibraryManager libraryManager, ILocalizationManager localization, ILogger logger)
|
2013-05-24 08:01:53 -07:00
|
|
|
{
|
|
|
|
_config = config;
|
2015-01-09 22:53:35 -07:00
|
|
|
_libraryManager = libraryManager;
|
2017-08-23 09:48:03 -07:00
|
|
|
_localization = localization;
|
2017-11-20 13:08:20 -07:00
|
|
|
_logger = logger;
|
2013-05-24 08:01:53 -07:00
|
|
|
}
|
|
|
|
|
2013-02-23 00:57:11 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Resolves the specified args.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
/// <returns>Season.</returns>
|
2013-02-20 18:33:05 -07:00
|
|
|
protected override Season Resolve(ItemResolveArgs args)
|
|
|
|
{
|
|
|
|
if (args.Parent is Series && args.IsDirectory)
|
|
|
|
{
|
2015-01-09 22:53:35 -07:00
|
|
|
var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions();
|
2016-07-09 10:39:04 -07:00
|
|
|
var series = ((Series)args.Parent);
|
|
|
|
|
2017-11-20 13:08:20 -07:00
|
|
|
var path = args.Path;
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
var seasonParserResult = new SeasonPathParser(namingOptions).Parse(path, true, true);
|
|
|
|
|
2013-05-24 08:01:53 -07:00
|
|
|
var season = new Season
|
2013-02-20 18:33:05 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
IndexNumber = seasonParserResult.SeasonNumber,
|
2016-08-19 10:43:16 -07:00
|
|
|
SeriesId = series.Id,
|
|
|
|
SeriesName = series.Name
|
2013-02-20 18:33:05 -07:00
|
|
|
};
|
2016-08-19 10:43:16 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (!season.IndexNumber.HasValue || !seasonParserResult.IsSeasonFolder)
|
2013-05-24 08:01:53 -07:00
|
|
|
{
|
2019-01-13 13:37:13 -07:00
|
|
|
var resolver = new Naming.TV.EpisodeResolver(namingOptions);
|
2017-11-20 13:08:20 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
var folderName = System.IO.Path.GetFileName(path);
|
|
|
|
var testPath = "\\\\test\\" + folderName;
|
|
|
|
|
|
|
|
var episodeInfo = resolver.Resolve(testPath, true);
|
2017-11-20 13:08:20 -07:00
|
|
|
|
|
|
|
if (episodeInfo != null)
|
|
|
|
{
|
|
|
|
if (episodeInfo.EpisodeNumber.HasValue && episodeInfo.SeasonNumber.HasValue)
|
|
|
|
{
|
2018-12-13 06:18:25 -07:00
|
|
|
_logger.LogDebug("Found folder underneath series with episode number: {0}. Season {1}. Episode {2}",
|
2017-11-20 13:08:20 -07:00
|
|
|
path,
|
|
|
|
episodeInfo.SeasonNumber.Value,
|
|
|
|
episodeInfo.EpisodeNumber.Value);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
2017-11-20 13:08:20 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (season.IndexNumber.HasValue)
|
|
|
|
{
|
2017-08-23 09:48:03 -07:00
|
|
|
var seasonNumber = season.IndexNumber.Value;
|
2017-10-20 09:16:56 -07:00
|
|
|
|
2017-08-23 09:48:03 -07:00
|
|
|
season.Name = seasonNumber == 0 ?
|
2017-09-24 13:23:56 -07:00
|
|
|
args.LibraryOptions.SeasonZeroDisplayName :
|
2017-10-20 09:16:56 -07:00
|
|
|
string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.ToString(UsCulture), args.GetLibraryOptions().PreferredMetadataLanguage);
|
2017-11-20 13:08:20 -07:00
|
|
|
|
2013-05-24 08:01:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return season;
|
2013-02-20 18:33:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|