2019-01-13 12:54:44 -07:00
|
|
|
using System;
|
2018-09-12 10:26:21 -07:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2019-01-13 12:17:29 -07:00
|
|
|
using Emby.Naming.Common;
|
|
|
|
using Emby.Naming.Video;
|
2018-09-12 10:26:21 -07:00
|
|
|
|
|
|
|
namespace Emby.Naming.TV
|
|
|
|
{
|
|
|
|
public class EpisodeResolver
|
|
|
|
{
|
|
|
|
private readonly NamingOptions _options;
|
|
|
|
|
|
|
|
public EpisodeResolver(NamingOptions options)
|
|
|
|
{
|
|
|
|
_options = options;
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:37:42 -07:00
|
|
|
public EpisodeInfo Resolve(
|
|
|
|
string path,
|
|
|
|
bool isDirectory,
|
|
|
|
bool? isNamed = null,
|
|
|
|
bool? isOptimistic = null,
|
|
|
|
bool? supportsAbsoluteNumbers = null,
|
|
|
|
bool fillExtendedInfo = true)
|
2018-09-12 10:26:21 -07:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
{
|
2019-01-06 13:50:43 -07:00
|
|
|
throw new ArgumentNullException(nameof(path));
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
|
|
|
|
2019-01-18 12:40:08 -07:00
|
|
|
bool isStub = false;
|
2018-09-12 10:26:21 -07:00
|
|
|
string container = null;
|
|
|
|
string stubType = null;
|
|
|
|
|
2019-05-10 11:37:42 -07:00
|
|
|
if (!isDirectory)
|
2018-09-12 10:26:21 -07:00
|
|
|
{
|
2019-01-18 12:40:08 -07:00
|
|
|
var extension = Path.GetExtension(path);
|
2018-09-12 10:26:21 -07:00
|
|
|
// Check supported extensions
|
|
|
|
if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
|
|
|
|
{
|
2019-01-18 12:40:08 -07:00
|
|
|
var stubResult = StubResolver.ResolveFile(path, _options);
|
2018-09-12 10:26:21 -07:00
|
|
|
|
|
|
|
isStub = stubResult.IsStub;
|
|
|
|
|
|
|
|
// It's not supported. Check stub extensions
|
|
|
|
if (!isStub)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
stubType = stubResult.StubType;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 11:37:42 -07:00
|
|
|
.Parse(path, isDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);
|
2019-01-07 16:27:46 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
return new EpisodeInfo
|
|
|
|
{
|
|
|
|
Path = path,
|
|
|
|
Container = container,
|
|
|
|
IsStub = isStub,
|
|
|
|
EndingEpsiodeNumber = parsingResult.EndingEpsiodeNumber,
|
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|