jellyfin/Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs

94 lines
3.3 KiB
C#
Raw Normal View History

2017-08-23 16:48:03 +00:00
using System.Globalization;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
2013-02-21 01:33:05 +00:00
using MediaBrowser.Controller.Library;
2017-08-23 16:48:03 +00:00
using MediaBrowser.Model.Globalization;
using Emby.Naming.Common;
using Emby.Naming.TV;
using MediaBrowser.Model.Logging;
2013-02-21 01:33:05 +00:00
namespace Emby.Server.Implementations.Library.Resolvers.TV
2013-02-21 01:33:05 +00:00
{
2013-02-23 07:57:11 +00:00
/// <summary>
/// Class SeasonResolver
/// </summary>
public class SeasonResolver : FolderResolver<Season>
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// The _config
/// </summary>
private readonly IServerConfigurationManager _config;
2015-01-10 05:53:35 +00:00
private readonly ILibraryManager _libraryManager;
2017-08-23 16:48:03 +00:00
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
private readonly ILocalizationManager _localization;
private readonly ILogger _logger;
2015-01-10 05:53:35 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="SeasonResolver"/> class.
/// </summary>
/// <param name="config">The config.</param>
public SeasonResolver(IServerConfigurationManager config, ILibraryManager libraryManager, ILocalizationManager localization, ILogger logger)
{
_config = config;
2015-01-10 05:53:35 +00:00
_libraryManager = libraryManager;
2017-08-23 16:48:03 +00:00
_localization = localization;
_logger = logger;
}
2013-02-23 07:57:11 +00:00
/// <summary>
/// Resolves the specified args.
/// </summary>
/// <param name="args">The args.</param>
/// <returns>Season.</returns>
2013-02-21 01:33:05 +00:00
protected override Season Resolve(ItemResolveArgs args)
{
if (args.Parent is Series && args.IsDirectory)
{
2015-01-10 05:53:35 +00:00
var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions();
2016-07-09 17:39:04 +00:00
var series = ((Series)args.Parent);
var path = args.Path;
var season = new Season
2013-02-21 01:33:05 +00:00
{
IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(path, true, true).SeasonNumber,
2016-08-19 17:43:16 +00:00
SeriesId = series.Id,
SeriesName = series.Name
2013-02-21 01:33:05 +00:00
};
2016-08-19 17:43:16 +00:00
2017-08-23 16:48:03 +00:00
if (season.IndexNumber.HasValue)
{
var resolver = new Emby.Naming.TV.EpisodeResolver(namingOptions);
var episodeInfo = resolver.Resolve(path, true);
if (episodeInfo != null)
{
if (episodeInfo.EpisodeNumber.HasValue && episodeInfo.SeasonNumber.HasValue)
{
_logger.Info("Found folder underneath series with episode number: {0}. Season {1}. Episode {2}",
path,
episodeInfo.SeasonNumber.Value,
episodeInfo.EpisodeNumber.Value);
return null;
}
}
2017-08-23 16:48:03 +00:00
var seasonNumber = season.IndexNumber.Value;
2017-10-20 16:16:56 +00:00
2017-08-23 16:48:03 +00:00
season.Name = seasonNumber == 0 ?
args.LibraryOptions.SeasonZeroDisplayName :
2017-10-20 16:16:56 +00:00
string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.ToString(UsCulture), args.GetLibraryOptions().PreferredMetadataLanguage);
}
return season;
2013-02-21 01:33:05 +00:00
}
return null;
}
}
}