| | 1 | | using System; |
| | 2 | | using System.IO; |
| | 3 | | using Emby.Naming.Common; |
| | 4 | | using Emby.Naming.Video; |
| | 5 | | using Jellyfin.Extensions; |
| | 6 | |
|
| | 7 | | namespace Emby.Naming.TV |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Used to resolve information about episode from path. |
| | 11 | | /// </summary> |
| | 12 | | public class EpisodeResolver |
| | 13 | | { |
| | 14 | | private readonly NamingOptions _options; |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Initializes a new instance of the <see cref="EpisodeResolver"/> class. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="options"><see cref="NamingOptions"/> object containing VideoFileExtensions and passed to <see c |
| | 20 | | public EpisodeResolver(NamingOptions options) |
| | 21 | | { |
| 84 | 22 | | _options = options; |
| 84 | 23 | | } |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Resolve information about episode from path. |
| | 27 | | /// </summary> |
| | 28 | | /// <param name="path">Path.</param> |
| | 29 | | /// <param name="isDirectory">Is path for a directory or file.</param> |
| | 30 | | /// <param name="isNamed">Do we want to use IsNamed expressions.</param> |
| | 31 | | /// <param name="isOptimistic">Do we want to use Optimistic expressions.</param> |
| | 32 | | /// <param name="supportsAbsoluteNumbers">Do we want to use expressions supporting absolute episode numbers.</pa |
| | 33 | | /// <param name="fillExtendedInfo">Should we attempt to retrieve extended information.</param> |
| | 34 | | /// <returns>Returns null or <see cref="EpisodeInfo"/> object if successful.</returns> |
| | 35 | | public EpisodeInfo? Resolve( |
| | 36 | | string path, |
| | 37 | | bool isDirectory, |
| | 38 | | bool? isNamed = null, |
| | 39 | | bool? isOptimistic = null, |
| | 40 | | bool? supportsAbsoluteNumbers = null, |
| | 41 | | bool fillExtendedInfo = true) |
| | 42 | | { |
| 84 | 43 | | bool isStub = false; |
| 84 | 44 | | string? container = null; |
| 84 | 45 | | string? stubType = null; |
| | 46 | |
|
| 84 | 47 | | if (!isDirectory) |
| | 48 | | { |
| 84 | 49 | | var extension = Path.GetExtension(path); |
| | 50 | | // Check supported extensions |
| 84 | 51 | | if (!_options.VideoFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase)) |
| | 52 | | { |
| | 53 | | // It's not supported. Check stub extensions |
| 2 | 54 | | if (!StubResolver.TryResolveFile(path, _options, out stubType)) |
| | 55 | | { |
| 1 | 56 | | return null; |
| | 57 | | } |
| | 58 | |
|
| 1 | 59 | | isStub = true; |
| | 60 | | } |
| | 61 | |
|
| 83 | 62 | | container = extension.TrimStart('.'); |
| | 63 | | } |
| | 64 | |
|
| 83 | 65 | | var format3DResult = Format3DParser.Parse(path, _options); |
| | 66 | |
|
| 83 | 67 | | var parsingResult = new EpisodePathParser(_options) |
| 83 | 68 | | .Parse(path, isDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo); |
| | 69 | |
|
| 83 | 70 | | if (!parsingResult.Success && !isStub) |
| | 71 | | { |
| 0 | 72 | | return null; |
| | 73 | | } |
| | 74 | |
|
| 83 | 75 | | return new EpisodeInfo(path) |
| 83 | 76 | | { |
| 83 | 77 | | Container = container, |
| 83 | 78 | | IsStub = isStub, |
| 83 | 79 | | EndingEpisodeNumber = parsingResult.EndingEpisodeNumber, |
| 83 | 80 | | EpisodeNumber = parsingResult.EpisodeNumber, |
| 83 | 81 | | SeasonNumber = parsingResult.SeasonNumber, |
| 83 | 82 | | SeriesName = parsingResult.SeriesName, |
| 83 | 83 | | StubType = stubType, |
| 83 | 84 | | Is3D = format3DResult.Is3D, |
| 83 | 85 | | Format3D = format3DResult.Format3D, |
| 83 | 86 | | IsByDate = parsingResult.IsByDate, |
| 83 | 87 | | Day = parsingResult.Day, |
| 83 | 88 | | Month = parsingResult.Month, |
| 83 | 89 | | Year = parsingResult.Year |
| 83 | 90 | | }; |
| | 91 | | } |
| | 92 | | } |
| | 93 | | } |