jellyfin-server/Emby.Naming/TV/EpisodeResolver.cs

73 lines
2.3 KiB
C#
Raw Normal View History

using System;
2018-09-12 17:26:21 +00:00
using System.IO;
using System.Linq;
2019-01-13 19:17:29 +00:00
using Emby.Naming.Common;
using Emby.Naming.Video;
2018-09-12 17:26:21 +00:00
namespace Emby.Naming.TV
{
public class EpisodeResolver
{
private readonly NamingOptions _options;
public EpisodeResolver(NamingOptions options)
{
_options = options;
}
2020-01-22 21:18:56 +00:00
public EpisodeInfo? Resolve(
2019-05-10 18:37:42 +00:00
string path,
bool isDirectory,
bool? isNamed = null,
bool? isOptimistic = null,
bool? supportsAbsoluteNumbers = null,
bool fillExtendedInfo = true)
2018-09-12 17:26:21 +00:00
{
bool isStub = false;
2020-01-22 21:18:56 +00:00
string? container = null;
string? stubType = null;
2018-09-12 17:26:21 +00:00
2019-05-10 18:37:42 +00:00
if (!isDirectory)
2018-09-12 17:26:21 +00:00
{
var extension = Path.GetExtension(path);
2018-09-12 17:26:21 +00:00
// Check supported extensions
if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
{
// It's not supported. Check stub extensions
2020-01-22 21:18:56 +00:00
if (!StubResolver.TryResolveFile(path, _options, out stubType))
2018-09-12 17:26:21 +00:00
{
return null;
}
2020-01-22 21:18:56 +00:00
isStub = true;
2018-09-12 17:26:21 +00:00
}
container = extension.TrimStart('.');
}
var flags = new FlagParser(_options).GetFlags(path);
var format3DResult = new Format3DParser(_options).Parse(flags);
var parsingResult = new EpisodePathParser(_options)
2019-05-10 18:37:42 +00:00
.Parse(path, isDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);
2019-01-07 23:27:46 +00:00
2020-11-01 09:47:31 +00:00
return new EpisodeInfo(path)
2018-09-12 17:26:21 +00:00
{
Container = container,
IsStub = isStub,
2020-11-01 10:19:22 +00:00
EndingEpisodeNumber = parsingResult.EndingEpisodeNumber,
2018-09-12 17:26:21 +00:00
EpisodeNumber = parsingResult.EpisodeNumber,
SeasonNumber = parsingResult.SeasonNumber,
SeriesName = parsingResult.SeriesName,
StubType = stubType,
Is3D = format3DResult.Is3D,
Format3D = format3DResult.Format3D,
IsByDate = parsingResult.IsByDate,
Day = parsingResult.Day,
Month = parsingResult.Month,
Year = parsingResult.Year
};
}
}
}