| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | using System.Globalization; |
| | | 4 | | using Emby.Naming.Common; |
| | | 5 | | using Emby.Naming.TV; |
| | | 6 | | using MediaBrowser.Controller.Entities.TV; |
| | | 7 | | using MediaBrowser.Controller.Library; |
| | | 8 | | using MediaBrowser.Model.Globalization; |
| | | 9 | | using Microsoft.Extensions.Logging; |
| | | 10 | | |
| | | 11 | | namespace Emby.Server.Implementations.Library.Resolvers.TV |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Class SeasonResolver. |
| | | 15 | | /// </summary> |
| | | 16 | | public class SeasonResolver : GenericFolderResolver<Season> |
| | | 17 | | { |
| | | 18 | | private readonly ILocalizationManager _localization; |
| | | 19 | | private readonly ILogger<SeasonResolver> _logger; |
| | | 20 | | private readonly NamingOptions _namingOptions; |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Initializes a new instance of the <see cref="SeasonResolver"/> class. |
| | | 24 | | /// </summary> |
| | | 25 | | /// <param name="namingOptions">The naming options.</param> |
| | | 26 | | /// <param name="localization">The localization.</param> |
| | | 27 | | /// <param name="logger">The logger.</param> |
| | 21 | 28 | | public SeasonResolver( |
| | 21 | 29 | | NamingOptions namingOptions, |
| | 21 | 30 | | ILocalizationManager localization, |
| | 21 | 31 | | ILogger<SeasonResolver> logger) |
| | | 32 | | { |
| | 21 | 33 | | _namingOptions = namingOptions; |
| | 21 | 34 | | _localization = localization; |
| | 21 | 35 | | _logger = logger; |
| | 21 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Resolves the specified args. |
| | | 40 | | /// </summary> |
| | | 41 | | /// <param name="args">The args.</param> |
| | | 42 | | /// <returns>Season.</returns> |
| | | 43 | | protected override Season Resolve(ItemResolveArgs args) |
| | | 44 | | { |
| | 10 | 45 | | if (args.Parent is Series series && args.IsDirectory) |
| | | 46 | | { |
| | 0 | 47 | | var namingOptions = _namingOptions; |
| | | 48 | | |
| | 0 | 49 | | var path = args.Path; |
| | | 50 | | |
| | 0 | 51 | | var seasonParserResult = SeasonPathParser.Parse(path, series.ContainingFolderPath, true, true); |
| | | 52 | | |
| | 0 | 53 | | var season = new Season |
| | 0 | 54 | | { |
| | 0 | 55 | | IndexNumber = seasonParserResult.SeasonNumber, |
| | 0 | 56 | | SeriesId = series.Id, |
| | 0 | 57 | | SeriesName = series.Name, |
| | 0 | 58 | | Path = seasonParserResult.IsSeasonFolder ? path : null |
| | 0 | 59 | | }; |
| | | 60 | | |
| | 0 | 61 | | if (!season.IndexNumber.HasValue || !seasonParserResult.IsSeasonFolder) |
| | | 62 | | { |
| | 0 | 63 | | var resolver = new Naming.TV.EpisodeResolver(namingOptions); |
| | | 64 | | |
| | 0 | 65 | | var folderName = System.IO.Path.GetFileName(path); |
| | 0 | 66 | | var testPath = @"\\test\" + folderName; |
| | | 67 | | |
| | 0 | 68 | | var episodeInfo = resolver.Resolve(testPath, true); |
| | | 69 | | |
| | 0 | 70 | | if (episodeInfo?.EpisodeNumber is not null && episodeInfo.SeasonNumber.HasValue) |
| | | 71 | | { |
| | 0 | 72 | | _logger.LogDebug( |
| | 0 | 73 | | "Found folder underneath series with episode number: {0}. Season {1}. Episode {2}", |
| | 0 | 74 | | path, |
| | 0 | 75 | | episodeInfo.SeasonNumber.Value, |
| | 0 | 76 | | episodeInfo.EpisodeNumber.Value); |
| | | 77 | | |
| | 0 | 78 | | return null; |
| | | 79 | | } |
| | | 80 | | } |
| | | 81 | | |
| | 0 | 82 | | if (season.IndexNumber.HasValue && string.IsNullOrEmpty(season.Name)) |
| | | 83 | | { |
| | 0 | 84 | | var seasonNumber = season.IndexNumber.Value; |
| | 0 | 85 | | season.Name = seasonNumber == 0 ? |
| | 0 | 86 | | args.LibraryOptions.SeasonZeroDisplayName : |
| | 0 | 87 | | string.Format( |
| | 0 | 88 | | CultureInfo.InvariantCulture, |
| | 0 | 89 | | _localization.GetLocalizedString("NameSeasonNumber"), |
| | 0 | 90 | | seasonNumber, |
| | 0 | 91 | | args.LibraryOptions.PreferredMetadataLanguage); |
| | | 92 | | } |
| | | 93 | | |
| | 0 | 94 | | return season; |
| | | 95 | | } |
| | | 96 | | |
| | 10 | 97 | | return null; |
| | | 98 | | } |
| | | 99 | | } |
| | | 100 | | } |