2019-12-13 19:11:37 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
#pragma warning disable SA1600
|
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2018-09-12 17:26:21 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text.RegularExpressions;
|
2019-01-13 19:17:29 +00:00
|
|
|
using Emby.Naming.Audio;
|
|
|
|
using Emby.Naming.Common;
|
2018-09-12 17:26:21 +00:00
|
|
|
|
|
|
|
namespace Emby.Naming.Video
|
|
|
|
{
|
|
|
|
public class ExtraResolver
|
|
|
|
{
|
|
|
|
private readonly NamingOptions _options;
|
|
|
|
|
|
|
|
public ExtraResolver(NamingOptions options)
|
|
|
|
{
|
|
|
|
_options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ExtraResult GetExtraInfo(string path)
|
|
|
|
{
|
|
|
|
return _options.VideoExtraRules
|
|
|
|
.Select(i => GetExtraInfo(path, i))
|
2019-12-06 19:40:06 +00:00
|
|
|
.FirstOrDefault(i => i.ExtraType != null) ?? new ExtraResult();
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private ExtraResult GetExtraInfo(string path, ExtraRule rule)
|
|
|
|
{
|
|
|
|
var result = new ExtraResult();
|
|
|
|
|
|
|
|
if (rule.MediaType == MediaType.Audio)
|
|
|
|
{
|
|
|
|
if (!new AudioFileParser(_options).IsAudioFile(path))
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rule.MediaType == MediaType.Video)
|
|
|
|
{
|
|
|
|
if (!new VideoResolver(_options).IsVideoFile(path))
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rule.RuleType == ExtraRuleType.Filename)
|
|
|
|
{
|
|
|
|
var filename = Path.GetFileNameWithoutExtension(path);
|
|
|
|
|
|
|
|
if (string.Equals(filename, rule.Token, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
result.ExtraType = rule.ExtraType;
|
|
|
|
result.Rule = rule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rule.RuleType == ExtraRuleType.Suffix)
|
|
|
|
{
|
|
|
|
var filename = Path.GetFileNameWithoutExtension(path);
|
|
|
|
|
|
|
|
if (filename.IndexOf(rule.Token, StringComparison.OrdinalIgnoreCase) > 0)
|
|
|
|
{
|
|
|
|
result.ExtraType = rule.ExtraType;
|
|
|
|
result.Rule = rule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rule.RuleType == ExtraRuleType.Regex)
|
|
|
|
{
|
|
|
|
var filename = Path.GetFileName(path);
|
|
|
|
|
|
|
|
var regex = new Regex(rule.Token, RegexOptions.IgnoreCase);
|
|
|
|
|
|
|
|
if (regex.IsMatch(filename))
|
|
|
|
{
|
|
|
|
result.ExtraType = rule.ExtraType;
|
|
|
|
result.Rule = rule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|