jellyfin/Emby.Naming/Video/Format3DParser.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

82 lines
2.3 KiB
C#

using Emby.Naming.Common;
using System;
using System.Linq;
namespace Emby.Naming.Video
{
public class Format3DParser
{
private readonly NamingOptions _options;
public Format3DParser(NamingOptions options)
{
_options = options;
}
public Format3DResult Parse(string path)
{
var delimeters = _options.VideoFlagDelimiters.ToList();
delimeters.Add(' ');
return Parse(new FlagParser(_options).GetFlags(path, delimeters.ToArray()));
}
internal Format3DResult Parse(string[] videoFlags)
{
foreach (var rule in _options.Format3DRules)
{
var result = Parse(videoFlags, rule);
if (result.Is3D)
{
return result;
}
}
return new Format3DResult();
}
private static Format3DResult Parse(string[] videoFlags, Format3DRule rule)
{
var result = new Format3DResult();
if (string.IsNullOrEmpty(rule.PreceedingToken))
{
result.Format3D = new[] { rule.Token }.FirstOrDefault(i => videoFlags.Contains(i, StringComparer.OrdinalIgnoreCase));
result.Is3D = !string.IsNullOrEmpty(result.Format3D);
if (result.Is3D)
{
result.Tokens.Add(rule.Token);
}
}
else
{
var foundPrefix = false;
string format = null;
foreach (var flag in videoFlags)
{
if (foundPrefix)
{
result.Tokens.Add(rule.PreceedingToken);
if (string.Equals(rule.Token, flag, StringComparison.OrdinalIgnoreCase))
{
format = flag;
result.Tokens.Add(rule.Token);
}
break;
}
foundPrefix = string.Equals(flag, rule.PreceedingToken, StringComparison.OrdinalIgnoreCase);
}
result.Is3D = foundPrefix && !string.IsNullOrEmpty(format);
result.Format3D = format;
}
return result;
}
}
}