Clean up some more

pull/2257/head
Bond_009 5 years ago
parent ec0ef2a2c5
commit abf03f7d3a

@ -2,33 +2,24 @@
#pragma warning disable SA1600 #pragma warning disable SA1600
#nullable enable #nullable enable
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Emby.Naming.Common;
namespace Emby.Naming.Video namespace Emby.Naming.Video
{ {
/// <summary> /// <summary>
/// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />. /// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
/// </summary> /// </summary>
public class CleanDateTimeParser public static class CleanDateTimeParser
{ {
private readonly NamingOptions _options; public static CleanDateTimeResult Clean(string name, IReadOnlyList<Regex> cleanDateTimeRegexes)
public CleanDateTimeParser(NamingOptions options)
{ {
_options = options;
}
public CleanDateTimeResult Clean(string name)
{
var regexes = _options.CleanDateTimeRegexes;
var len = regexes.Length;
CleanDateTimeResult result = new CleanDateTimeResult(name); CleanDateTimeResult result = new CleanDateTimeResult(name);
var len = cleanDateTimeRegexes.Count;
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
{ {
if (TryClean(name, regexes[i], ref result)) if (TryClean(name, cleanDateTimeRegexes[i], ref result))
{ {
return result; return result;
} }

@ -138,7 +138,7 @@ namespace Emby.Naming.Video
public CleanDateTimeResult CleanDateTime(string name) public CleanDateTimeResult CleanDateTime(string name)
{ {
return new CleanDateTimeParser(_options).Clean(name); return CleanDateTimeParser.Clean(name, _options.CleanDateTimeRegexes);
} }
} }
} }

@ -36,7 +36,6 @@ using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Library; using MediaBrowser.Model.Library;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
@ -54,6 +53,9 @@ namespace Emby.Server.Implementations.Library
/// </summary> /// </summary>
public class LibraryManager : ILibraryManager public class LibraryManager : ILibraryManager
{ {
private NamingOptions _namingOptions;
private string[] _videoFileExtensions;
/// <summary> /// <summary>
/// Gets or sets the postscan tasks. /// Gets or sets the postscan tasks.
/// </summary> /// </summary>
@ -2508,21 +2510,11 @@ namespace Emby.Server.Implementations.Library
} }
public NamingOptions GetNamingOptions() public NamingOptions GetNamingOptions()
{
return GetNamingOptionsInternal();
}
private NamingOptions _namingOptions;
private string[] _videoFileExtensions;
private NamingOptions GetNamingOptionsInternal()
{ {
if (_namingOptions == null) if (_namingOptions == null)
{ {
var options = new NamingOptions(); _namingOptions = new NamingOptions();
_videoFileExtensions = _namingOptions.VideoFileExtensions;
_namingOptions = options;
_videoFileExtensions = _namingOptions.VideoFileExtensions.ToArray();
} }
return _namingOptions; return _namingOptions;
@ -2533,11 +2525,10 @@ namespace Emby.Server.Implementations.Library
var resolver = new VideoResolver(GetNamingOptions()); var resolver = new VideoResolver(GetNamingOptions());
var result = resolver.CleanDateTime(name); var result = resolver.CleanDateTime(name);
var cleanName = resolver.CleanString(result.Name);
return new ItemLookupInfo return new ItemLookupInfo
{ {
Name = cleanName.Name, Name = resolver.TryCleanString(result.Name, out var newName) ? newName.ToString() : result.Name,
Year = result.Year Year = result.Year
}; };
} }

Loading…
Cancel
Save