aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Naming')
-rw-r--r--Emby.Naming/Audio/AlbumParser.cs12
-rw-r--r--Emby.Naming/Audio/AudioFileParser.cs14
-rw-r--r--Emby.Naming/Audio/MultiPartResult.cs26
-rw-r--r--Emby.Naming/AudioBook/AudioBookFileInfo.cs2
-rw-r--r--Emby.Naming/AudioBook/AudioBookFilePathParser.cs1
-rw-r--r--Emby.Naming/AudioBook/AudioBookFilePathParserResult.cs1
-rw-r--r--Emby.Naming/AudioBook/AudioBookListResolver.cs20
-rw-r--r--Emby.Naming/AudioBook/AudioBookResolver.cs1
-rw-r--r--Emby.Naming/Common/EpisodeExpression.cs37
-rw-r--r--Emby.Naming/Common/MediaType.cs1
-rw-r--r--Emby.Naming/Common/NamingOptions.cs130
-rw-r--r--Emby.Naming/Emby.Naming.csproj5
-rw-r--r--Emby.Naming/Subtitles/SubtitleInfo.cs1
-rw-r--r--Emby.Naming/Subtitles/SubtitleParser.cs4
-rw-r--r--Emby.Naming/TV/EpisodeInfo.cs1
-rw-r--r--Emby.Naming/TV/EpisodePathParser.cs8
-rw-r--r--Emby.Naming/TV/EpisodePathParserResult.cs1
-rw-r--r--Emby.Naming/TV/EpisodeResolver.cs21
-rw-r--r--Emby.Naming/TV/SeasonPathParser.cs80
-rw-r--r--Emby.Naming/TV/SeasonPathParserResult.cs1
-rw-r--r--Emby.Naming/Video/CleanDateTimeParser.cs72
-rw-r--r--Emby.Naming/Video/CleanDateTimeResult.cs30
-rw-r--r--Emby.Naming/Video/CleanStringParser.cs44
-rw-r--r--Emby.Naming/Video/CleanStringResult.cs20
-rw-r--r--Emby.Naming/Video/ExtraResolver.cs5
-rw-r--r--Emby.Naming/Video/ExtraResult.cs5
-rw-r--r--Emby.Naming/Video/ExtraRule.cs6
-rw-r--r--Emby.Naming/Video/ExtraRuleType.cs1
-rw-r--r--Emby.Naming/Video/FileStack.cs1
-rw-r--r--Emby.Naming/Video/FlagParser.cs1
-rw-r--r--Emby.Naming/Video/Format3DParser.cs1
-rw-r--r--Emby.Naming/Video/Format3DResult.cs1
-rw-r--r--Emby.Naming/Video/Format3DRule.cs1
-rw-r--r--Emby.Naming/Video/StackResolver.cs26
-rw-r--r--Emby.Naming/Video/StackResult.cs17
-rw-r--r--Emby.Naming/Video/StubResolver.cs21
-rw-r--r--Emby.Naming/Video/StubResult.cs1
-rw-r--r--Emby.Naming/Video/StubTypeRule.cs1
-rw-r--r--Emby.Naming/Video/VideoFileInfo.cs8
-rw-r--r--Emby.Naming/Video/VideoInfo.cs18
-rw-r--r--Emby.Naming/Video/VideoListResolver.cs53
-rw-r--r--Emby.Naming/Video/VideoResolver.cs33
42 files changed, 288 insertions, 445 deletions
diff --git a/Emby.Naming/Audio/AlbumParser.cs b/Emby.Naming/Audio/AlbumParser.cs
index 4975b8e19d..33f4468d9f 100644
--- a/Emby.Naming/Audio/AlbumParser.cs
+++ b/Emby.Naming/Audio/AlbumParser.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Globalization;
@@ -19,15 +18,13 @@ namespace Emby.Naming.Audio
_options = options;
}
- public MultiPartResult ParseMultiPart(string path)
+ public bool IsMultiPart(string path)
{
- var result = new MultiPartResult();
-
var filename = Path.GetFileName(path);
if (string.IsNullOrEmpty(filename))
{
- return result;
+ return false;
}
// TODO: Move this logic into options object
@@ -57,12 +54,11 @@ namespace Emby.Naming.Audio
if (int.TryParse(tmp, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
- result.IsMultiPart = true;
- break;
+ return true;
}
}
- return result;
+ return false;
}
}
}
diff --git a/Emby.Naming/Audio/AudioFileParser.cs b/Emby.Naming/Audio/AudioFileParser.cs
index 9f21e93dc4..25d5f8735e 100644
--- a/Emby.Naming/Audio/AudioFileParser.cs
+++ b/Emby.Naming/Audio/AudioFileParser.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.IO;
@@ -8,19 +7,12 @@ using Emby.Naming.Common;
namespace Emby.Naming.Audio
{
- public class AudioFileParser
+ public static class AudioFileParser
{
- private readonly NamingOptions _options;
-
- public AudioFileParser(NamingOptions options)
- {
- _options = options;
- }
-
- public bool IsAudioFile(string path)
+ public static bool IsAudioFile(string path, NamingOptions options)
{
var extension = Path.GetExtension(path) ?? string.Empty;
- return _options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
+ return options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
}
}
}
diff --git a/Emby.Naming/Audio/MultiPartResult.cs b/Emby.Naming/Audio/MultiPartResult.cs
deleted file mode 100644
index 8f68d97fa8..0000000000
--- a/Emby.Naming/Audio/MultiPartResult.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma warning disable CS1591
-#pragma warning disable SA1600
-
-namespace Emby.Naming.Audio
-{
- public class MultiPartResult
- {
- /// <summary>
- /// Gets or sets the name.
- /// </summary>
- /// <value>The name.</value>
- public string Name { get; set; }
-
- /// <summary>
- /// Gets or sets the part.
- /// </summary>
- /// <value>The part.</value>
- public string Part { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether this instance is multi part.
- /// </summary>
- /// <value><c>true</c> if this instance is multi part; otherwise, <c>false</c>.</value>
- public bool IsMultiPart { get; set; }
- }
-}
diff --git a/Emby.Naming/AudioBook/AudioBookFileInfo.cs b/Emby.Naming/AudioBook/AudioBookFileInfo.cs
index 769e3d7fac..0bc6ec7e40 100644
--- a/Emby.Naming/AudioBook/AudioBookFileInfo.cs
+++ b/Emby.Naming/AudioBook/AudioBookFileInfo.cs
@@ -32,7 +32,7 @@ namespace Emby.Naming.AudioBook
public int? ChapterNumber { get; set; }
/// <summary>
- /// Gets or sets the type.
+ /// Gets or sets a value indicating whether this instance is a directory.
/// </summary>
/// <value>The type.</value>
public bool IsDirectory { get; set; }
diff --git a/Emby.Naming/AudioBook/AudioBookFilePathParser.cs b/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
index 8dc2e1b97c..5494df9d63 100644
--- a/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
+++ b/Emby.Naming/AudioBook/AudioBookFilePathParser.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Globalization;
diff --git a/Emby.Naming/AudioBook/AudioBookFilePathParserResult.cs b/Emby.Naming/AudioBook/AudioBookFilePathParserResult.cs
index 68d6ca4d46..e28a58db78 100644
--- a/Emby.Naming/AudioBook/AudioBookFilePathParserResult.cs
+++ b/Emby.Naming/AudioBook/AudioBookFilePathParserResult.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.AudioBook
{
diff --git a/Emby.Naming/AudioBook/AudioBookListResolver.cs b/Emby.Naming/AudioBook/AudioBookListResolver.cs
index 97f3592857..081510f952 100644
--- a/Emby.Naming/AudioBook/AudioBookListResolver.cs
+++ b/Emby.Naming/AudioBook/AudioBookListResolver.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System.Collections.Generic;
using System.Linq;
@@ -39,9 +38,7 @@ namespace Emby.Naming.AudioBook
var stackResult = new StackResolver(_options)
.ResolveAudioBooks(metadata);
- var list = new List<AudioBookInfo>();
-
- foreach (var stack in stackResult.Stacks)
+ foreach (var stack in stackResult)
{
var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).ToList();
stackFiles.Sort();
@@ -50,20 +47,9 @@ namespace Emby.Naming.AudioBook
Files = stackFiles,
Name = stack.Name
};
- list.Add(info);
- }
-
- // Whatever files are left, just add them
- /*list.AddRange(remainingFiles.Select(i => new AudioBookInfo
- {
- Files = new List<AudioBookFileInfo> { i },
- Name = i.,
- Year = i.Year
- }));*/
-
- var orderedList = list.OrderBy(i => i.Name);
- return orderedList;
+ yield return info;
+ }
}
}
}
diff --git a/Emby.Naming/AudioBook/AudioBookResolver.cs b/Emby.Naming/AudioBook/AudioBookResolver.cs
index 0b0d2035e7..5466b46379 100644
--- a/Emby.Naming/AudioBook/AudioBookResolver.cs
+++ b/Emby.Naming/AudioBook/AudioBookResolver.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.IO;
diff --git a/Emby.Naming/Common/EpisodeExpression.cs b/Emby.Naming/Common/EpisodeExpression.cs
index 30a74fb657..07de728514 100644
--- a/Emby.Naming/Common/EpisodeExpression.cs
+++ b/Emby.Naming/Common/EpisodeExpression.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Text.RegularExpressions;
@@ -11,6 +10,24 @@ namespace Emby.Naming.Common
private string _expression;
private Regex _regex;
+ public EpisodeExpression(string expression, bool byDate)
+ {
+ Expression = expression;
+ IsByDate = byDate;
+ DateTimeFormats = Array.Empty<string>();
+ SupportsAbsoluteEpisodeNumbers = true;
+ }
+
+ public EpisodeExpression(string expression)
+ : this(expression, false)
+ {
+ }
+
+ public EpisodeExpression()
+ : this(null)
+ {
+ }
+
public string Expression
{
get => _expression;
@@ -32,23 +49,5 @@ namespace Emby.Naming.Common
public string[] DateTimeFormats { get; set; }
public Regex Regex => _regex ?? (_regex = new Regex(Expression, RegexOptions.IgnoreCase | RegexOptions.Compiled));
-
- public EpisodeExpression(string expression, bool byDate)
- {
- Expression = expression;
- IsByDate = byDate;
- DateTimeFormats = Array.Empty<string>();
- SupportsAbsoluteEpisodeNumbers = true;
- }
-
- public EpisodeExpression(string expression)
- : this(expression, false)
- {
- }
-
- public EpisodeExpression()
- : this(null)
- {
- }
}
}
diff --git a/Emby.Naming/Common/MediaType.cs b/Emby.Naming/Common/MediaType.cs
index a61f10489c..cc18ce4cdd 100644
--- a/Emby.Naming/Common/MediaType.cs
+++ b/Emby.Naming/Common/MediaType.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.Common
{
diff --git a/Emby.Naming/Common/NamingOptions.cs b/Emby.Naming/Common/NamingOptions.cs
index 69e68660d4..793847f84c 100644
--- a/Emby.Naming/Common/NamingOptions.cs
+++ b/Emby.Naming/Common/NamingOptions.cs
@@ -1,55 +1,15 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Emby.Naming.Video;
+using MediaBrowser.Model.Entities;
namespace Emby.Naming.Common
{
public class NamingOptions
{
- public string[] AudioFileExtensions { get; set; }
-
- public string[] AlbumStackingPrefixes { get; set; }
-
- public string[] SubtitleFileExtensions { get; set; }
-
- public char[] SubtitleFlagDelimiters { get; set; }
-
- public string[] SubtitleForcedFlags { get; set; }
-
- public string[] SubtitleDefaultFlags { get; set; }
-
- public EpisodeExpression[] EpisodeExpressions { get; set; }
-
- public string[] EpisodeWithoutSeasonExpressions { get; set; }
-
- public string[] EpisodeMultiPartExpressions { get; set; }
-
- public string[] VideoFileExtensions { get; set; }
-
- public string[] StubFileExtensions { get; set; }
-
- public string[] AudioBookPartsExpressions { get; set; }
-
- public StubTypeRule[] StubTypes { get; set; }
-
- public char[] VideoFlagDelimiters { get; set; }
-
- public Format3DRule[] Format3DRules { get; set; }
-
- public string[] VideoFileStackingExpressions { get; set; }
-
- public string[] CleanDateTimes { get; set; }
-
- public string[] CleanStrings { get; set; }
-
- public EpisodeExpression[] MultipleEpisodeExpressions { get; set; }
-
- public ExtraRule[] VideoExtraRules { get; set; }
-
public NamingOptions()
{
VideoFileExtensions = new[]
@@ -176,13 +136,12 @@ namespace Emby.Naming.Common
CleanDateTimes = new[]
{
- @"(.+[^ _\,\.\(\)\[\]\-])[ _\.\(\)\[\]\-]+(19[0-9][0-9]|20[0-1][0-9])([ _\,\.\(\)\[\]\-][^0-9]|$)"
+ @"(.+[^_\,\.\(\)\[\]\-])[_\.\(\)\[\]\-](19\d{2}|20\d{2})([ _\,\.\(\)\[\]\-][^0-9]|).*(19\d{2}|20\d{2})*"
};
CleanStrings = new[]
{
- @"[ _\,\.\(\)\[\]\-](ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|cd[1-9]|r3|r5|bd5|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|2160p|hrhd|hrhdtv|hddvd|bluray|x264|h264|xvid|xvidvd|xxx|www.www|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
- @"[ _\,\.\(\)\[\]\-](3d|sbs|tab|hsbs|htab|mvc|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
+ @"[ _\,\.\(\)\[\]\-](3d|sbs|tab|hsbs|htab|mvc|HDR|HDC|UHD|UltraHD|4k|ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|cd[1-9]|r3|r5|bd5|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|2160p|hrhd|hrhdtv|hddvd|bluray|x264|h264|xvid|xvidvd|xxx|www.www|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
@"(\[.*\])"
};
@@ -317,7 +276,7 @@ namespace Emby.Naming.Common
// This isn't a Kodi naming rule, but the expression below causes false positives,
// so we make sure this one gets tested first.
// "Foo Bar 889"
- new EpisodeExpression(@".*[\\\/](?![Ee]pisode)(?<seriesname>[\w\s]+?)\s(?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*[^\\\/]*$")
+ new EpisodeExpression(@".*[\\\/](?![Ee]pisode)(?<seriesname>[\w\s]+?)\s(?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*[^\\\/x]*$")
{
IsNamed = true
},
@@ -339,7 +298,7 @@ namespace Emby.Naming.Common
// *** End Kodi Standard Naming
-                // [bar] Foo - 1 [baz]
+ // [bar] Foo - 1 [baz]
new EpisodeExpression(@".*?(\[.*?\])+.*?(?<seriesname>[\w\s]+?)[-\s_]+(?<epnumber>\d+).*$")
{
IsNamed = true
@@ -423,126 +382,126 @@ namespace Emby.Naming.Common
{
new ExtraRule
{
- ExtraType = "trailer",
+ ExtraType = ExtraType.Trailer,
RuleType = ExtraRuleType.Filename,
Token = "trailer",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "trailer",
+ ExtraType = ExtraType.Trailer,
RuleType = ExtraRuleType.Suffix,
Token = "-trailer",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "trailer",
+ ExtraType = ExtraType.Trailer,
RuleType = ExtraRuleType.Suffix,
Token = ".trailer",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "trailer",
+ ExtraType = ExtraType.Trailer,
RuleType = ExtraRuleType.Suffix,
Token = "_trailer",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "trailer",
+ ExtraType = ExtraType.Trailer,
RuleType = ExtraRuleType.Suffix,
Token = " trailer",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "sample",
+ ExtraType = ExtraType.Sample,
RuleType = ExtraRuleType.Filename,
Token = "sample",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "sample",
+ ExtraType = ExtraType.Sample,
RuleType = ExtraRuleType.Suffix,
Token = "-sample",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "sample",
+ ExtraType = ExtraType.Sample,
RuleType = ExtraRuleType.Suffix,
Token = ".sample",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "sample",
+ ExtraType = ExtraType.Sample,
RuleType = ExtraRuleType.Suffix,
Token = "_sample",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "sample",
+ ExtraType = ExtraType.Sample,
RuleType = ExtraRuleType.Suffix,
Token = " sample",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "themesong",
+ ExtraType = ExtraType.ThemeSong,
RuleType = ExtraRuleType.Filename,
Token = "theme",
MediaType = MediaType.Audio
},
new ExtraRule
{
- ExtraType = "scene",
+ ExtraType = ExtraType.Scene,
RuleType = ExtraRuleType.Suffix,
Token = "-scene",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "clip",
+ ExtraType = ExtraType.Clip,
RuleType = ExtraRuleType.Suffix,
Token = "-clip",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "interview",
+ ExtraType = ExtraType.Interview,
RuleType = ExtraRuleType.Suffix,
Token = "-interview",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "behindthescenes",
+ ExtraType = ExtraType.BehindTheScenes,
RuleType = ExtraRuleType.Suffix,
Token = "-behindthescenes",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "deletedscene",
+ ExtraType = ExtraType.DeletedScene,
RuleType = ExtraRuleType.Suffix,
Token = "-deleted",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "featurette",
+ ExtraType = ExtraType.Clip,
RuleType = ExtraRuleType.Suffix,
Token = "-featurette",
MediaType = MediaType.Video
},
new ExtraRule
{
- ExtraType = "short",
+ ExtraType = ExtraType.Clip,
RuleType = ExtraRuleType.Suffix,
Token = "-short",
MediaType = MediaType.Video
@@ -681,11 +640,54 @@ namespace Emby.Naming.Common
Compile();
}
+ public string[] AudioFileExtensions { get; set; }
+
+ public string[] AlbumStackingPrefixes { get; set; }
+
+ public string[] SubtitleFileExtensions { get; set; }
+
+ public char[] SubtitleFlagDelimiters { get; set; }
+
+ public string[] SubtitleForcedFlags { get; set; }
+
+ public string[] SubtitleDefaultFlags { get; set; }
+
+ public EpisodeExpression[] EpisodeExpressions { get; set; }
+
+ public string[] EpisodeWithoutSeasonExpressions { get; set; }
+
+ public string[] EpisodeMultiPartExpressions { get; set; }
+
+ public string[] VideoFileExtensions { get; set; }
+
+ public string[] StubFileExtensions { get; set; }
+
+ public string[] AudioBookPartsExpressions { get; set; }
+
+ public StubTypeRule[] StubTypes { get; set; }
+
+ public char[] VideoFlagDelimiters { get; set; }
+
+ public Format3DRule[] Format3DRules { get; set; }
+
+ public string[] VideoFileStackingExpressions { get; set; }
+
+ public string[] CleanDateTimes { get; set; }
+
+ public string[] CleanStrings { get; set; }
+
+ public EpisodeExpression[] MultipleEpisodeExpressions { get; set; }
+
+ public ExtraRule[] VideoExtraRules { get; set; }
+
public Regex[] VideoFileStackingRegexes { get; private set; }
+
public Regex[] CleanDateTimeRegexes { get; private set; }
+
public Regex[] CleanStringRegexes { get; private set; }
public Regex[] EpisodeWithoutSeasonRegexes { get; private set; }
+
public Regex[] EpisodeMultiPartRegexes { get; private set; }
public void Compile()
diff --git a/Emby.Naming/Emby.Naming.csproj b/Emby.Naming/Emby.Naming.csproj
index ed1670adf8..4e08170a47 100644
--- a/Emby.Naming/Emby.Naming.csproj
+++ b/Emby.Naming/Emby.Naming.csproj
@@ -4,9 +4,6 @@
<TargetFramework>netstandard2.1</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
@@ -27,7 +24,7 @@
<!-- Code Analyzers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
- <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.7" PrivateAssets="All" />
+ <!-- TODO: <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="All" /> -->
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
diff --git a/Emby.Naming/Subtitles/SubtitleInfo.cs b/Emby.Naming/Subtitles/SubtitleInfo.cs
index fe42846c61..f39c496b7a 100644
--- a/Emby.Naming/Subtitles/SubtitleInfo.cs
+++ b/Emby.Naming/Subtitles/SubtitleInfo.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.Subtitles
{
diff --git a/Emby.Naming/Subtitles/SubtitleParser.cs b/Emby.Naming/Subtitles/SubtitleParser.cs
index 99680c6221..082696da4f 100644
--- a/Emby.Naming/Subtitles/SubtitleParser.cs
+++ b/Emby.Naming/Subtitles/SubtitleParser.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.IO;
@@ -31,7 +30,6 @@ namespace Emby.Naming.Subtitles
}
var flags = GetFlags(path);
-
var info = new SubtitleInfo
{
Path = path,
@@ -45,7 +43,7 @@ namespace Emby.Naming.Subtitles
// Should have a name, language and file extension
if (parts.Count >= 3)
{
- info.Language = parts[parts.Count - 2];
+ info.Language = parts[^2];
}
return info;
diff --git a/Emby.Naming/TV/EpisodeInfo.cs b/Emby.Naming/TV/EpisodeInfo.cs
index 667129a57d..250df4e2d3 100644
--- a/Emby.Naming/TV/EpisodeInfo.cs
+++ b/Emby.Naming/TV/EpisodeInfo.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.TV
{
diff --git a/Emby.Naming/TV/EpisodePathParser.cs b/Emby.Naming/TV/EpisodePathParser.cs
index 4fac543f92..d3a822b173 100644
--- a/Emby.Naming/TV/EpisodePathParser.cs
+++ b/Emby.Naming/TV/EpisodePathParser.cs
@@ -1,5 +1,5 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
+#nullable enable
using System;
using System.Collections.Generic;
@@ -28,7 +28,7 @@ namespace Emby.Naming.TV
path += ".mp4";
}
- EpisodePathParserResult result = null;
+ EpisodePathParserResult? result = null;
foreach (var expression in _options.EpisodeExpressions)
{
@@ -131,12 +131,12 @@ namespace Emby.Naming.TV
var endingNumberGroup = match.Groups["endingepnumber"];
if (endingNumberGroup.Success)
{
- // Will only set EndingEpsiodeNumber if the captured number is not followed by additional numbers
+ // Will only set EndingEpisodeNumber if the captured number is not followed by additional numbers
// or a 'p' or 'i' as what you would get with a pixel resolution specification.
// It avoids erroneous parsing of something like "series-s09e14-1080p.mkv" as a multi-episode from E14 to E108
int nextIndex = endingNumberGroup.Index + endingNumberGroup.Length;
if (nextIndex >= name.Length
- || "0123456789iIpP".IndexOf(name[nextIndex]) == -1)
+ || !"0123456789iIpP".Contains(name[nextIndex], StringComparison.Ordinal))
{
if (int.TryParse(endingNumberGroup.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out num))
{
diff --git a/Emby.Naming/TV/EpisodePathParserResult.cs b/Emby.Naming/TV/EpisodePathParserResult.cs
index 3acbbc101c..05f921edc9 100644
--- a/Emby.Naming/TV/EpisodePathParserResult.cs
+++ b/Emby.Naming/TV/EpisodePathParserResult.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.TV
{
diff --git a/Emby.Naming/TV/EpisodeResolver.cs b/Emby.Naming/TV/EpisodeResolver.cs
index 5e115fc75d..6994f69fc4 100644
--- a/Emby.Naming/TV/EpisodeResolver.cs
+++ b/Emby.Naming/TV/EpisodeResolver.cs
@@ -1,5 +1,5 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
+#nullable enable
using System;
using System.IO;
@@ -18,7 +18,7 @@ namespace Emby.Naming.TV
_options = options;
}
- public EpisodeInfo Resolve(
+ public EpisodeInfo? Resolve(
string path,
bool isDirectory,
bool? isNamed = null,
@@ -26,14 +26,9 @@ namespace Emby.Naming.TV
bool? supportsAbsoluteNumbers = null,
bool fillExtendedInfo = true)
{
- if (string.IsNullOrEmpty(path))
- {
- throw new ArgumentNullException(nameof(path));
- }
-
bool isStub = false;
- string container = null;
- string stubType = null;
+ string? container = null;
+ string? stubType = null;
if (!isDirectory)
{
@@ -41,17 +36,13 @@ namespace Emby.Naming.TV
// Check supported extensions
if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
{
- var stubResult = StubResolver.ResolveFile(path, _options);
-
- isStub = stubResult.IsStub;
-
// It's not supported. Check stub extensions
- if (!isStub)
+ if (!StubResolver.TryResolveFile(path, _options, out stubType))
{
return null;
}
- stubType = stubResult.StubType;
+ isStub = true;
}
container = extension.TrimStart('.');
diff --git a/Emby.Naming/TV/SeasonPathParser.cs b/Emby.Naming/TV/SeasonPathParser.cs
index e5f90e9660..2fa6b43531 100644
--- a/Emby.Naming/TV/SeasonPathParser.cs
+++ b/Emby.Naming/TV/SeasonPathParser.cs
@@ -1,32 +1,13 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Globalization;
using System.IO;
-using System.Linq;
namespace Emby.Naming.TV
{
- public class SeasonPathParser
+ public static class SeasonPathParser
{
- public SeasonPathParserResult Parse(string path, bool supportSpecialAliases, bool supportNumericSeasonFolders)
- {
- var result = new SeasonPathParserResult();
-
- var seasonNumberInfo = GetSeasonNumberFromPath(path, supportSpecialAliases, supportNumericSeasonFolders);
-
- result.SeasonNumber = seasonNumberInfo.seasonNumber;
-
- if (result.SeasonNumber.HasValue)
- {
- result.Success = true;
- result.IsSeasonFolder = seasonNumberInfo.isSeasonFolder;
- }
-
- return result;
- }
-
/// <summary>
/// A season folder must contain one of these somewhere in the name.
/// </summary>
@@ -42,6 +23,23 @@ namespace Emby.Naming.TV
"stagione"
};
+ public static SeasonPathParserResult Parse(string path, bool supportSpecialAliases, bool supportNumericSeasonFolders)
+ {
+ var result = new SeasonPathParserResult();
+
+ var (seasonNumber, isSeasonFolder) = GetSeasonNumberFromPath(path, supportSpecialAliases, supportNumericSeasonFolders);
+
+ result.SeasonNumber = seasonNumber;
+
+ if (result.SeasonNumber.HasValue)
+ {
+ result.Success = true;
+ result.IsSeasonFolder = isSeasonFolder;
+ }
+
+ return result;
+ }
+
/// <summary>
/// Gets the season number from path.
/// </summary>
@@ -90,12 +88,10 @@ namespace Emby.Naming.TV
// Look for one of the season folder names
foreach (var name in _seasonFolderNames)
{
- var index = filename.IndexOf(name, StringComparison.OrdinalIgnoreCase);
-
- if (index != -1)
+ if (filename.Contains(name, StringComparison.OrdinalIgnoreCase))
{
var result = GetSeasonNumberFromPathSubstring(filename.Replace(name, " ", StringComparison.OrdinalIgnoreCase));
- if (result.Item1.HasValue)
+ if (result.seasonNumber.HasValue)
{
return result;
}
@@ -105,25 +101,32 @@ namespace Emby.Naming.TV
}
var parts = filename.Split(new[] { '.', '_', ' ', '-' }, StringSplitOptions.RemoveEmptyEntries);
- var resultNumber = parts.Select(GetSeasonNumberFromPart).FirstOrDefault(i => i.HasValue);
- return (resultNumber, true);
+ for (int i = 0; i < parts.Length; i++)
+ {
+ if (TryGetSeasonNumberFromPart(parts[i], out int seasonNumber))
+ {
+ return (seasonNumber, true);
+ }
+ }
+
+ return (null, true);
}
- private static int? GetSeasonNumberFromPart(string part)
+ private static bool TryGetSeasonNumberFromPart(ReadOnlySpan<char> part, out int seasonNumber)
{
+ seasonNumber = 0;
if (part.Length < 2 || !part.StartsWith("s", StringComparison.OrdinalIgnoreCase))
{
- return null;
+ return false;
}
- part = part.Substring(1);
-
- if (int.TryParse(part, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
+ if (int.TryParse(part.Slice(1), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value))
{
- return value;
+ seasonNumber = value;
+ return true;
}
- return null;
+ return false;
}
/// <summary>
@@ -131,7 +134,7 @@ namespace Emby.Naming.TV
/// </summary>
/// <param name="path">The path.</param>
/// <returns>System.Nullable{System.Int32}.</returns>
- private static (int? seasonNumber, bool isSeasonFolder) GetSeasonNumberFromPathSubstring(string path)
+ private static (int? seasonNumber, bool isSeasonFolder) GetSeasonNumberFromPathSubstring(ReadOnlySpan<char> path)
{
var numericStart = -1;
var length = 0;
@@ -142,7 +145,7 @@ namespace Emby.Naming.TV
// Find out where the numbers start, and then keep going until they end
for (var i = 0; i < path.Length; i++)
{
- if (char.IsNumber(path, i))
+ if (char.IsNumber(path[i]))
{
if (!hasOpenParenth)
{
@@ -150,6 +153,7 @@ namespace Emby.Naming.TV
{
numericStart = i;
}
+
length++;
}
}
@@ -161,11 +165,11 @@ namespace Emby.Naming.TV
}
var currentChar = path[i];
- if (currentChar.Equals('('))
+ if (currentChar == '(')
{
hasOpenParenth = true;
}
- else if (currentChar.Equals(')'))
+ else if (currentChar == ')')
{
hasOpenParenth = false;
}
@@ -176,7 +180,7 @@ namespace Emby.Naming.TV
return (null, isSeasonFolder);
}
- return (int.Parse(path.Substring(numericStart, length), CultureInfo.InvariantCulture), isSeasonFolder);
+ return (int.Parse(path.Slice(numericStart, length), provider: CultureInfo.InvariantCulture), isSeasonFolder);
}
}
}
diff --git a/Emby.Naming/TV/SeasonPathParserResult.cs b/Emby.Naming/TV/SeasonPathParserResult.cs
index 57c2347548..44090c059f 100644
--- a/Emby.Naming/TV/SeasonPathParserResult.cs
+++ b/Emby.Naming/TV/SeasonPathParserResult.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.TV
{
diff --git a/Emby.Naming/Video/CleanDateTimeParser.cs b/Emby.Naming/Video/CleanDateTimeParser.cs
index a9db4ccccd..579c9e91e1 100644
--- a/Emby.Naming/Video/CleanDateTimeParser.cs
+++ b/Emby.Naming/Video/CleanDateTimeParser.cs
@@ -1,89 +1,47 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
+#nullable enable
-using System;
+using System.Collections.Generic;
using System.Globalization;
-using System.IO;
-using System.Linq;
using System.Text.RegularExpressions;
-using Emby.Naming.Common;
namespace Emby.Naming.Video
{
/// <summary>
/// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
/// </summary>
- public class CleanDateTimeParser
+ public static class CleanDateTimeParser
{
- private readonly NamingOptions _options;
-
- public CleanDateTimeParser(NamingOptions options)
+ public static CleanDateTimeResult Clean(string name, IReadOnlyList<Regex> cleanDateTimeRegexes)
{
- _options = options;
- }
-
- public CleanDateTimeResult Clean(string name)
- {
- var originalName = name;
-
- try
+ CleanDateTimeResult result = new CleanDateTimeResult(name);
+ var len = cleanDateTimeRegexes.Count;
+ for (int i = 0; i < len; i++)
{
- var extension = Path.GetExtension(name) ?? string.Empty;
- // Check supported extensions
- if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)
- && !_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
+ if (TryClean(name, cleanDateTimeRegexes[i], ref result))
{
- // Dummy up a file extension because the expressions will fail without one
- // This is tricky because we can't just check Path.GetExtension for empty
- // If the input is "St. Vincent (2014)", it will produce ". Vincent (2014)" as the extension
- name += ".mkv";
+ return result;
}
}
- catch (ArgumentException)
- {
- }
-
- var result = _options.CleanDateTimeRegexes.Select(i => Clean(name, i))
- .FirstOrDefault(i => i.HasChanged) ??
- new CleanDateTimeResult { Name = originalName };
-
- if (result.HasChanged)
- {
- return result;
- }
-
- // Make a second pass, running clean string first
- var cleanStringResult = new CleanStringParser().Clean(name, _options.CleanStringRegexes);
- if (!cleanStringResult.HasChanged)
- {
- return result;
- }
-
- return _options.CleanDateTimeRegexes.Select(i => Clean(cleanStringResult.Name, i))
- .FirstOrDefault(i => i.HasChanged) ??
- result;
+ return result;
}
- private static CleanDateTimeResult Clean(string name, Regex expression)
+ private static bool TryClean(string name, Regex expression, ref CleanDateTimeResult result)
{
- var result = new CleanDateTimeResult();
-
var match = expression.Match(name);
if (match.Success
- && match.Groups.Count == 4
+ && match.Groups.Count == 5
&& match.Groups[1].Success
&& match.Groups[2].Success
&& int.TryParse(match.Groups[2].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var year))
{
- name = match.Groups[1].Value;
- result.Year = year;
- result.HasChanged = true;
+ result = new CleanDateTimeResult(match.Groups[1].Value.TrimEnd(), year);
+ return true;
}
- result.Name = name;
- return result;
+ return false;
}
}
}
diff --git a/Emby.Naming/Video/CleanDateTimeResult.cs b/Emby.Naming/Video/CleanDateTimeResult.cs
index a7581972e4..57eeaa7e32 100644
--- a/Emby.Naming/Video/CleanDateTimeResult.cs
+++ b/Emby.Naming/Video/CleanDateTimeResult.cs
@@ -1,26 +1,32 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
+#nullable enable
namespace Emby.Naming.Video
{
- public class CleanDateTimeResult
+ public readonly struct CleanDateTimeResult
{
+ public CleanDateTimeResult(string name, int? year)
+ {
+ Name = name;
+ Year = year;
+ }
+
+ public CleanDateTimeResult(string name)
+ {
+ Name = name;
+ Year = null;
+ }
+
/// <summary>
- /// Gets or sets the name.
+ /// Gets the name.
/// </summary>
/// <value>The name.</value>
- public string Name { get; set; }
+ public string Name { get; }
/// <summary>
- /// Gets or sets the year.
+ /// Gets the year.
/// </summary>
/// <value>The year.</value>
- public int? Year { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether this instance has changed.
- /// </summary>
- /// <value><c>true</c> if this instance has changed; otherwise, <c>false</c>.</value>
- public bool HasChanged { get; set; }
+ public int? Year { get; }
}
}
diff --git a/Emby.Naming/Video/CleanStringParser.cs b/Emby.Naming/Video/CleanStringParser.cs
index be028c662e..3f584d5847 100644
--- a/Emby.Naming/Video/CleanStringParser.cs
+++ b/Emby.Naming/Video/CleanStringParser.cs
@@ -1,52 +1,44 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
+#nullable enable
+using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Emby.Naming.Video
{
/// <summary>
- /// http://kodi.wiki/view/Advancedsettings.xml#video
+ /// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
/// </summary>
- public class CleanStringParser
+ public static class CleanStringParser
{
- public CleanStringResult Clean(string name, IEnumerable<Regex> expressions)
+ public static bool TryClean(string name, IReadOnlyList<Regex> expressions, out ReadOnlySpan<char> newName)
{
- var hasChanged = false;
-
- foreach (var exp in expressions)
+ var len = expressions.Count;
+ for (int i = 0; i < len; i++)
{
- var result = Clean(name, exp);
-
- if (!string.IsNullOrEmpty(result.Name))
+ if (TryClean(name, expressions[i], out newName))
{
- name = result.Name;
- hasChanged = hasChanged || result.HasChanged;
+ return true;
}
}
- return new CleanStringResult
- {
- Name = name,
- HasChanged = hasChanged
- };
+ newName = ReadOnlySpan<char>.Empty;
+ return false;
}
- private static CleanStringResult Clean(string name, Regex expression)
+ private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName)
{
- var result = new CleanStringResult();
-
var match = expression.Match(name);
-
- if (match.Success)
+ int index = match.Index;
+ if (match.Success && index != 0)
{
- result.HasChanged = true;
- name = name.Substring(0, match.Index);
+ newName = name.AsSpan().Slice(0, match.Index);
+ return true;
}
- result.Name = name;
- return result;
+ newName = string.Empty;
+ return false;
}
}
}
diff --git a/Emby.Naming/Video/CleanStringResult.cs b/Emby.Naming/Video/CleanStringResult.cs
deleted file mode 100644
index 786fe9e028..0000000000
--- a/Emby.Naming/Video/CleanStringResult.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma warning disable CS1591
-#pragma warning disable SA1600
-
-namespace Emby.Naming.Video
-{
- public class CleanStringResult
- {
- /// <summary>
- /// Gets or sets the name.
- /// </summary>
- /// <value>The name.</value>
- public string Name { get; set; }
-
- /// <summary>
- /// Gets or sets a value indicating whether this instance has changed.
- /// </summary>
- /// <value><c>true</c> if this instance has changed; otherwise, <c>false</c>.</value>
- public bool HasChanged { get; set; }
- }
-}
diff --git a/Emby.Naming/Video/ExtraResolver.cs b/Emby.Naming/Video/ExtraResolver.cs
index 989ede206e..42a5c88b31 100644
--- a/Emby.Naming/Video/ExtraResolver.cs
+++ b/Emby.Naming/Video/ExtraResolver.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.IO;
@@ -23,7 +22,7 @@ namespace Emby.Naming.Video
{
return _options.VideoExtraRules
.Select(i => GetExtraInfo(path, i))
- .FirstOrDefault(i => !string.IsNullOrEmpty(i.ExtraType)) ?? new ExtraResult();
+ .FirstOrDefault(i => i.ExtraType != null) ?? new ExtraResult();
}
private ExtraResult GetExtraInfo(string path, ExtraRule rule)
@@ -32,7 +31,7 @@ namespace Emby.Naming.Video
if (rule.MediaType == MediaType.Audio)
{
- if (!new AudioFileParser(_options).IsAudioFile(path))
+ if (!AudioFileParser.IsAudioFile(path, _options))
{
return result;
}
diff --git a/Emby.Naming/Video/ExtraResult.cs b/Emby.Naming/Video/ExtraResult.cs
index 6081a44942..15db32e876 100644
--- a/Emby.Naming/Video/ExtraResult.cs
+++ b/Emby.Naming/Video/ExtraResult.cs
@@ -1,5 +1,6 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
+
+using MediaBrowser.Model.Entities;
namespace Emby.Naming.Video
{
@@ -9,7 +10,7 @@ namespace Emby.Naming.Video
/// Gets or sets the type of the extra.
/// </summary>
/// <value>The type of the extra.</value>
- public string ExtraType { get; set; }
+ public ExtraType? ExtraType { get; set; }
/// <summary>
/// Gets or sets the rule.
diff --git a/Emby.Naming/Video/ExtraRule.cs b/Emby.Naming/Video/ExtraRule.cs
index cfce79fd08..cb58a39347 100644
--- a/Emby.Naming/Video/ExtraRule.cs
+++ b/Emby.Naming/Video/ExtraRule.cs
@@ -1,7 +1,7 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
-using Emby.Naming.Common;
+using MediaBrowser.Model.Entities;
+using MediaType = Emby.Naming.Common.MediaType;
namespace Emby.Naming.Video
{
@@ -17,7 +17,7 @@ namespace Emby.Naming.Video
/// Gets or sets the type of the extra.
/// </summary>
/// <value>The type of the extra.</value>
- public string ExtraType { get; set; }
+ public ExtraType ExtraType { get; set; }
/// <summary>
/// Gets or sets the type of the rule.
diff --git a/Emby.Naming/Video/ExtraRuleType.cs b/Emby.Naming/Video/ExtraRuleType.cs
index 2bf2799ff7..b021a04a31 100644
--- a/Emby.Naming/Video/ExtraRuleType.cs
+++ b/Emby.Naming/Video/ExtraRuleType.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.Video
{
diff --git a/Emby.Naming/Video/FileStack.cs b/Emby.Naming/Video/FileStack.cs
index 56adf6add0..3ef190b865 100644
--- a/Emby.Naming/Video/FileStack.cs
+++ b/Emby.Naming/Video/FileStack.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Collections.Generic;
diff --git a/Emby.Naming/Video/FlagParser.cs b/Emby.Naming/Video/FlagParser.cs
index acf3438c22..a8bd9d5c5d 100644
--- a/Emby.Naming/Video/FlagParser.cs
+++ b/Emby.Naming/Video/FlagParser.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.IO;
diff --git a/Emby.Naming/Video/Format3DParser.cs b/Emby.Naming/Video/Format3DParser.cs
index 25905f33c1..51c26af863 100644
--- a/Emby.Naming/Video/Format3DParser.cs
+++ b/Emby.Naming/Video/Format3DParser.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Linq;
diff --git a/Emby.Naming/Video/Format3DResult.cs b/Emby.Naming/Video/Format3DResult.cs
index 6ebd72f6ba..fa0e9d3b80 100644
--- a/Emby.Naming/Video/Format3DResult.cs
+++ b/Emby.Naming/Video/Format3DResult.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System.Collections.Generic;
diff --git a/Emby.Naming/Video/Format3DRule.cs b/Emby.Naming/Video/Format3DRule.cs
index ae9fb5b19f..310ec84e8f 100644
--- a/Emby.Naming/Video/Format3DRule.cs
+++ b/Emby.Naming/Video/Format3DRule.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.Video
{
diff --git a/Emby.Naming/Video/StackResolver.cs b/Emby.Naming/Video/StackResolver.cs
index e7a769ae6b..ee05904c75 100644
--- a/Emby.Naming/Video/StackResolver.cs
+++ b/Emby.Naming/Video/StackResolver.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Collections.Generic;
@@ -20,7 +19,7 @@ namespace Emby.Naming.Video
_options = options;
}
- public StackResult ResolveDirectories(IEnumerable<string> files)
+ public IEnumerable<FileStack> ResolveDirectories(IEnumerable<string> files)
{
return Resolve(files.Select(i => new FileSystemMetadata
{
@@ -29,7 +28,7 @@ namespace Emby.Naming.Video
}));
}
- public StackResult ResolveFiles(IEnumerable<string> files)
+ public IEnumerable<FileStack> ResolveFiles(IEnumerable<string> files)
{
return Resolve(files.Select(i => new FileSystemMetadata
{
@@ -38,9 +37,8 @@ namespace Emby.Naming.Video
}));
}
- public StackResult ResolveAudioBooks(IEnumerable<FileSystemMetadata> files)
+ public IEnumerable<FileStack> ResolveAudioBooks(IEnumerable<FileSystemMetadata> files)
{
- var result = new StackResult();
foreach (var directory in files.GroupBy(file => file.IsDirectory ? file.FullName : Path.GetDirectoryName(file.FullName)))
{
var stack = new FileStack()
@@ -58,20 +56,16 @@ namespace Emby.Naming.Video
stack.Files.Add(file.FullName);
}
- result.Stacks.Add(stack);
+ yield return stack;
}
-
- return result;
}
- public StackResult Resolve(IEnumerable<FileSystemMetadata> files)
+ public IEnumerable<FileStack> Resolve(IEnumerable<FileSystemMetadata> files)
{
- var result = new StackResult();
-
var resolver = new VideoResolver(_options);
var list = files
- .Where(i => i.IsDirectory || (resolver.IsVideoFile(i.FullName) || resolver.IsStubFile(i.FullName)))
+ .Where(i => i.IsDirectory || resolver.IsVideoFile(i.FullName) || resolver.IsStubFile(i.FullName))
.OrderBy(i => i.FullName)
.ToList();
@@ -191,17 +185,15 @@ namespace Emby.Naming.Video
if (stack.Files.Count > 1)
{
- result.Stacks.Add(stack);
+ yield return stack;
i += stack.Files.Count - 1;
break;
}
}
}
-
- return result;
}
- private string GetRegexInput(FileSystemMetadata file)
+ private static string GetRegexInput(FileSystemMetadata file)
{
// For directories, dummy up an extension otherwise the expressions will fail
var input = !file.IsDirectory
@@ -211,7 +203,7 @@ namespace Emby.Naming.Video
return Path.GetFileName(input);
}
- private Match FindMatch(FileSystemMetadata input, Regex regex, int offset)
+ private static Match FindMatch(FileSystemMetadata input, Regex regex, int offset)
{
var regexInput = GetRegexInput(input);
diff --git a/Emby.Naming/Video/StackResult.cs b/Emby.Naming/Video/StackResult.cs
deleted file mode 100644
index 31ef2d69c5..0000000000
--- a/Emby.Naming/Video/StackResult.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma warning disable CS1591
-#pragma warning disable SA1600
-
-using System.Collections.Generic;
-
-namespace Emby.Naming.Video
-{
- public class StackResult
- {
- public List<FileStack> Stacks { get; set; }
-
- public StackResult()
- {
- Stacks = new List<FileStack>();
- }
- }
-}
diff --git a/Emby.Naming/Video/StubResolver.cs b/Emby.Naming/Video/StubResolver.cs
index bbf399677d..f1b5d7bcca 100644
--- a/Emby.Naming/Video/StubResolver.cs
+++ b/Emby.Naming/Video/StubResolver.cs
@@ -1,5 +1,5 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
+#nullable enable
using System;
using System.IO;
@@ -10,25 +10,22 @@ namespace Emby.Naming.Video
{
public static class StubResolver
{
- public static StubResult ResolveFile(string path, NamingOptions options)
+ public static bool TryResolveFile(string path, NamingOptions options, out string? stubType)
{
+ stubType = default;
+
if (path == null)
{
- return default(StubResult);
+ return false;
}
var extension = Path.GetExtension(path);
if (!options.StubFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
{
- return default(StubResult);
+ return false;
}
- var result = new StubResult()
- {
- IsStub = true
- };
-
path = Path.GetFileNameWithoutExtension(path);
var token = Path.GetExtension(path).TrimStart('.');
@@ -36,12 +33,12 @@ namespace Emby.Naming.Video
{
if (string.Equals(rule.Token, token, StringComparison.OrdinalIgnoreCase))
{
- result.StubType = rule.StubType;
- break;
+ stubType = rule.StubType;
+ return true;
}
}
- return result;
+ return true;
}
}
}
diff --git a/Emby.Naming/Video/StubResult.cs b/Emby.Naming/Video/StubResult.cs
index 5ac85528f5..1b8e99b0dc 100644
--- a/Emby.Naming/Video/StubResult.cs
+++ b/Emby.Naming/Video/StubResult.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.Video
{
diff --git a/Emby.Naming/Video/StubTypeRule.cs b/Emby.Naming/Video/StubTypeRule.cs
index 17c3ef8c5e..8285cb51a3 100644
--- a/Emby.Naming/Video/StubTypeRule.cs
+++ b/Emby.Naming/Video/StubTypeRule.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
namespace Emby.Naming.Video
{
diff --git a/Emby.Naming/Video/VideoFileInfo.cs b/Emby.Naming/Video/VideoFileInfo.cs
index 250a1ec45d..aa4f3a35c3 100644
--- a/Emby.Naming/Video/VideoFileInfo.cs
+++ b/Emby.Naming/Video/VideoFileInfo.cs
@@ -1,3 +1,5 @@
+using MediaBrowser.Model.Entities;
+
namespace Emby.Naming.Video
{
/// <summary>
@@ -30,10 +32,10 @@ namespace Emby.Naming.Video
public int? Year { get; set; }
/// <summary>
- /// Gets or sets the type of the extra, e.g. trailer, theme song, behing the scenes, etc.
+ /// Gets or sets the type of the extra, e.g. trailer, theme song, behind the scenes, etc.
/// </summary>
/// <value>The type of the extra.</value>
- public string ExtraType { get; set; }
+ public ExtraType? ExtraType { get; set; }
/// <summary>
/// Gets or sets the extra rule.
@@ -66,7 +68,7 @@ namespace Emby.Naming.Video
public string StubType { get; set; }
/// <summary>
- /// Gets or sets the type.
+ /// Gets or sets a value indicating whether this instance is a directory.
/// </summary>
/// <value>The type.</value>
public bool IsDirectory { get; set; }
diff --git a/Emby.Naming/Video/VideoInfo.cs b/Emby.Naming/Video/VideoInfo.cs
index a585bb99a2..ea74c40e2a 100644
--- a/Emby.Naming/Video/VideoInfo.cs
+++ b/Emby.Naming/Video/VideoInfo.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
namespace Emby.Naming.Video
@@ -10,11 +11,14 @@ namespace Emby.Naming.Video
/// <summary>
/// Initializes a new instance of the <see cref="VideoInfo" /> class.
/// </summary>
- public VideoInfo()
+ /// <param name="name">The name.</param>
+ public VideoInfo(string name)
{
- Files = new List<VideoFileInfo>();
- Extras = new List<VideoFileInfo>();
- AlternateVersions = new List<VideoFileInfo>();
+ Name = name;
+
+ Files = Array.Empty<VideoFileInfo>();
+ Extras = Array.Empty<VideoFileInfo>();
+ AlternateVersions = Array.Empty<VideoFileInfo>();
}
/// <summary>
@@ -33,18 +37,18 @@ namespace Emby.Naming.Video
/// Gets or sets the files.
/// </summary>
/// <value>The files.</value>
- public List<VideoFileInfo> Files { get; set; }
+ public IReadOnlyList<VideoFileInfo> Files { get; set; }
/// <summary>
/// Gets or sets the extras.
/// </summary>
/// <value>The extras.</value>
- public List<VideoFileInfo> Extras { get; set; }
+ public IReadOnlyList<VideoFileInfo> Extras { get; set; }
/// <summary>
/// Gets or sets the alternate versions.
/// </summary>
/// <value>The alternate versions.</value>
- public List<VideoFileInfo> AlternateVersions { get; set; }
+ public IReadOnlyList<VideoFileInfo> AlternateVersions { get; set; }
}
}
diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs
index 5a32846bf3..d4b02cf2a6 100644
--- a/Emby.Naming/Video/VideoListResolver.cs
+++ b/Emby.Naming/Video/VideoListResolver.cs
@@ -1,5 +1,4 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
using System;
using System.Collections.Generic;
@@ -7,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Emby.Naming.Common;
+using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
namespace Emby.Naming.Video
@@ -32,7 +32,7 @@ namespace Emby.Naming.Video
// Filter out all extras, otherwise they could cause stacks to not be resolved
// See the unit test TestStackedWithTrailer
var nonExtras = videoInfos
- .Where(i => string.IsNullOrEmpty(i.ExtraType))
+ .Where(i => i.ExtraType == null)
.Select(i => new FileSystemMetadata
{
FullName = i.Path,
@@ -40,20 +40,19 @@ namespace Emby.Naming.Video
});
var stackResult = new StackResolver(_options)
- .Resolve(nonExtras);
+ .Resolve(nonExtras).ToList();
var remainingFiles = videoInfos
- .Where(i => !stackResult.Stacks.Any(s => s.ContainsFile(i.Path, i.IsDirectory)))
+ .Where(i => !stackResult.Any(s => s.ContainsFile(i.Path, i.IsDirectory)))
.ToList();
var list = new List<VideoInfo>();
- foreach (var stack in stackResult.Stacks)
+ foreach (var stack in stackResult)
{
- var info = new VideoInfo
+ var info = new VideoInfo(stack.Name)
{
- Files = stack.Files.Select(i => videoResolver.Resolve(i, stack.IsDirectoryStack)).ToList(),
- Name = stack.Name
+ Files = stack.Files.Select(i => videoResolver.Resolve(i, stack.IsDirectoryStack)).ToList()
};
info.Year = info.Files[0].Year;
@@ -79,15 +78,14 @@ namespace Emby.Naming.Video
}
var standaloneMedia = remainingFiles
- .Where(i => string.IsNullOrEmpty(i.ExtraType))
+ .Where(i => i.ExtraType == null)
.ToList();
foreach (var media in standaloneMedia)
{
- var info = new VideoInfo
+ var info = new VideoInfo(media.Name)
{
- Files = new List<VideoFileInfo> { media },
- Name = media.Name
+ Files = new List<VideoFileInfo> { media }
};
info.Year = info.Files[0].Year;
@@ -127,7 +125,8 @@ namespace Emby.Naming.Video
.Except(extras)
.ToList();
- info.Extras.AddRange(extras);
+ extras.AddRange(info.Extras);
+ info.Extras = extras;
}
}
@@ -140,7 +139,8 @@ namespace Emby.Naming.Video
.Except(extrasByFileName)
.ToList();
- info.Extras.AddRange(extrasByFileName);
+ extrasByFileName.AddRange(info.Extras);
+ info.Extras = extrasByFileName;
}
// If there's only one video, accept all trailers
@@ -148,10 +148,11 @@ namespace Emby.Naming.Video
if (list.Count == 1)
{
var trailers = remainingFiles
- .Where(i => string.Equals(i.ExtraType, "trailer", StringComparison.OrdinalIgnoreCase))
+ .Where(i => i.ExtraType == ExtraType.Trailer)
.ToList();
- list[0].Extras.AddRange(trailers);
+ trailers.AddRange(list[0].Extras);
+ list[0].Extras = trailers;
remainingFiles = remainingFiles
.Except(trailers)
@@ -159,14 +160,13 @@ namespace Emby.Naming.Video
}
// Whatever files are left, just add them
- list.AddRange(remainingFiles.Select(i => new VideoInfo
+ list.AddRange(remainingFiles.Select(i => new VideoInfo(i.Name)
{
Files = new List<VideoFileInfo> { i },
- Name = i.Name,
Year = i.Year
}));
- return list.OrderBy(i => i.Name);
+ return list;
}
private IEnumerable<VideoInfo> GetVideosGroupedByVersion(List<VideoInfo> videos)
@@ -190,9 +190,18 @@ namespace Emby.Naming.Video
list.Add(ordered[0]);
- list[0].AlternateVersions = ordered.Skip(1).Select(i => i.Files[0]).ToList();
+ var alternateVersionsLen = ordered.Count - 1;
+ var alternateVersions = new VideoFileInfo[alternateVersionsLen];
+ for (int i = 0; i < alternateVersionsLen; i++)
+ {
+ alternateVersions[i] = ordered[i + 1].Files[0];
+ }
+
+ list[0].AlternateVersions = alternateVersions;
list[0].Name = folderName;
- list[0].Extras.AddRange(ordered.Skip(1).SelectMany(i => i.Extras));
+ var extras = ordered.Skip(1).SelectMany(i => i.Extras).ToList();
+ extras.AddRange(list[0].Extras);
+ list[0].Extras = extras;
return list;
}
@@ -229,7 +238,7 @@ namespace Emby.Naming.Video
}
return remainingFiles
- .Where(i => !string.IsNullOrEmpty(i.ExtraType))
+ .Where(i => i.ExtraType == null)
.Where(i => baseNames.Any(b => i.FileNameWithoutExtension.StartsWith(b, StringComparison.OrdinalIgnoreCase)))
.ToList();
}
diff --git a/Emby.Naming/Video/VideoResolver.cs b/Emby.Naming/Video/VideoResolver.cs
index 5a93e1eafe..0b75a8cce9 100644
--- a/Emby.Naming/Video/VideoResolver.cs
+++ b/Emby.Naming/Video/VideoResolver.cs
@@ -1,5 +1,5 @@
#pragma warning disable CS1591
-#pragma warning disable SA1600
+#nullable enable
using System;
using System.IO;
@@ -22,7 +22,7 @@ namespace Emby.Naming.Video
/// </summary>
/// <param name="path">The path.</param>
/// <returns>VideoFileInfo.</returns>
- public VideoFileInfo ResolveDirectory(string path)
+ public VideoFileInfo? ResolveDirectory(string path)
{
return Resolve(path, true);
}
@@ -32,7 +32,7 @@ namespace Emby.Naming.Video
/// </summary>
/// <param name="path">The path.</param>
/// <returns>VideoFileInfo.</returns>
- public VideoFileInfo ResolveFile(string path)
+ public VideoFileInfo? ResolveFile(string path)
{
return Resolve(path, false);
}
@@ -42,10 +42,10 @@ namespace Emby.Naming.Video
/// </summary>
/// <param name="path">The path.</param>
/// <param name="isDirectory">if set to <c>true</c> [is folder].</param>
- /// <param name="parseName">Whether or not the name should be parsed for info</param>
+ /// <param name="parseName">Whether or not the name should be parsed for info.</param>
/// <returns>VideoFileInfo.</returns>
/// <exception cref="ArgumentNullException"><c>path</c> is <c>null</c>.</exception>
- public VideoFileInfo Resolve(string path, bool isDirectory, bool parseName = true)
+ public VideoFileInfo? Resolve(string path, bool isDirectory, bool parseName = true)
{
if (string.IsNullOrEmpty(path))
{
@@ -53,8 +53,8 @@ namespace Emby.Naming.Video
}
bool isStub = false;
- string container = null;
- string stubType = null;
+ string? container = null;
+ string? stubType = null;
if (!isDirectory)
{
@@ -63,17 +63,13 @@ namespace Emby.Naming.Video
// Check supported extensions
if (!_options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
{
- var stubResult = StubResolver.ResolveFile(path, _options);
-
- isStub = stubResult.IsStub;
-
// It's not supported. Check stub extensions
- if (!isStub)
+ if (!StubResolver.TryResolveFile(path, _options, out stubType))
{
return null;
}
- stubType = stubResult.StubType;
+ isStub = true;
}
container = extension.TrimStart('.');
@@ -94,9 +90,10 @@ namespace Emby.Naming.Video
{
var cleanDateTimeResult = CleanDateTime(name);
- if (string.IsNullOrEmpty(extraResult.ExtraType))
+ if (extraResult.ExtraType == null
+ && TryCleanString(cleanDateTimeResult.Name, out ReadOnlySpan<char> newName))
{
- name = CleanString(cleanDateTimeResult.Name).Name;
+ name = newName.ToString();
}
year = cleanDateTimeResult.Year;
@@ -130,14 +127,14 @@ namespace Emby.Naming.Video
return _options.StubFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
}
- public CleanStringResult CleanString(string name)
+ public bool TryCleanString(string name, out ReadOnlySpan<char> newName)
{
- return new CleanStringParser().Clean(name, _options.CleanStringRegexes);
+ return CleanStringParser.TryClean(name, _options.CleanStringRegexes, out newName);
}
public CleanDateTimeResult CleanDateTime(string name)
{
- return new CleanDateTimeParser(_options).Clean(name);
+ return CleanDateTimeParser.Clean(name, _options.CleanDateTimeRegexes);
}
}
}