jellyfin/Emby.Naming/TV/EpisodeResolver.cs
Erwin de Haan ec1f5dc317 Mayor code cleanup
Add Argument*Exceptions now use proper nameof operators.

Added exception messages to quite a few Argument*Exceptions.

Fixed rethorwing to be proper syntax.

Added a ton of null checkes. (This is only a start, there are about 500 places that need proper null handling)

Added some TODOs to log certain exceptions.

Fix sln again.

Fixed all AssemblyInfo's and added proper copyright (where I could find them)

We live in *current year*.

Fixed the use of braces.

Fixed a ton of properties, and made a fair amount of functions static that should be and can be static.

Made more Methods that should be static static.

You can now use static to find bad functions!

Removed unused variable. And added one more proper XML comment.
2019-01-10 20:38:53 +01:00

77 lines
2.5 KiB
C#

using Emby.Naming.Common;
using Emby.Naming.Video;
using System;
using System.IO;
using System.Linq;
namespace Emby.Naming.TV
{
public class EpisodeResolver
{
private readonly NamingOptions _options;
public EpisodeResolver(NamingOptions options)
{
_options = options;
}
public EpisodeInfo Resolve(string path, bool IsDirectory, bool? isNamed = null, bool? isOptimistic = null, bool? supportsAbsoluteNumbers = null, bool fillExtendedInfo = true)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}
var isStub = false;
string container = null;
string stubType = null;
if (!IsDirectory)
{
var extension = Path.GetExtension(path) ?? string.Empty;
// Check supported extensions
if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
{
var stubResult = new StubResolver(_options).ResolveFile(path);
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)
.Parse(path, IsDirectory, isNamed, isOptimistic, supportsAbsoluteNumbers, fillExtendedInfo);
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
};
}
}
}