From f02190c394ad300c00dec4cc4f3b9d42ac6aaca2 Mon Sep 17 00:00:00 2001
From: Michael McElroy <44167199+mcmcelro@users.noreply.github.com>
Date: Thu, 27 Mar 2025 20:18:19 -0400
Subject: Fix for Issue #12142: Fix ExtraRuleResolver filtering out top level
folders (#12170)
* Fix ExtraRuleResolver to stop filtering out libraries where the name of the base folder matches an 'videos extras' rule with an ExtraRuleType of DirectoryName
Currently the ExtraRuleResolver code doesn't know anything about the root folder of the current library. As a result, when we're attempting to add items in a library where the root folder has a name with a match in Emby.Naming.Common.NamingOptions.VideoExtraRules, the entire library is being ignored as a Video Extras folder.
Need to pass in the root folder of the current library to compare to the path of the current item being evaluated, and if we match the current item's folder to the root folder, then we ignore the ExtraRules with a type of DirectoryName and we continue to scan deeper in the library. Filters still apply to subfolders within the library itself.
* Update CONTRIBUTORS.md
* Update Emby.Naming/Video/ExtraRuleResolver.cs
* Update ExtraTests.cs
Add tests for this fix.
Also add missing tests in TestKodiExtras, TestExpandedExtras, and TestSample, and expanded TestDirectories into TestDirectoriesAudioExtras and TestDirectoriesVideoExtras. There were no checks for the theme-music folder name previously.
* Update ExtraTests.cs
Removed unnecessary "using System"
* In MediaBrowser.Model, upgrade System.Text.Json from 8.0.3 (vulnerable - high risk) to 8.0.4
* Update ExtraTests.cs
Remove empty lines in usings
* Revert "In MediaBrowser.Model, upgrade System.Text.Json from 8.0.3 (vulnerable - high risk) to 8.0.4"
---
Emby.Naming/Video/ExtraRuleResolver.cs | 7 +++++--
Emby.Naming/Video/VideoListResolver.cs | 5 +++--
Emby.Naming/Video/VideoResolver.cs | 15 +++++++++------
3 files changed, 17 insertions(+), 10 deletions(-)
(limited to 'Emby.Naming')
diff --git a/Emby.Naming/Video/ExtraRuleResolver.cs b/Emby.Naming/Video/ExtraRuleResolver.cs
index 3219472ef..528906589 100644
--- a/Emby.Naming/Video/ExtraRuleResolver.cs
+++ b/Emby.Naming/Video/ExtraRuleResolver.cs
@@ -18,8 +18,9 @@ namespace Emby.Naming.Video
///
/// Path to file.
/// The naming options.
+ /// Top-level folder for the containing library.
/// Returns object.
- public static ExtraResult GetExtraInfo(string path, NamingOptions namingOptions)
+ public static ExtraResult GetExtraInfo(string path, NamingOptions namingOptions, string? libraryRoot = "")
{
var result = new ExtraResult();
@@ -69,7 +70,9 @@ namespace Emby.Naming.Video
else if (rule.RuleType == ExtraRuleType.DirectoryName)
{
var directoryName = Path.GetFileName(Path.GetDirectoryName(pathSpan));
- if (directoryName.Equals(rule.Token, StringComparison.OrdinalIgnoreCase))
+ string fullDirectory = Path.GetDirectoryName(pathSpan).ToString();
+ if (directoryName.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)
+ && !string.Equals(fullDirectory, libraryRoot, StringComparison.OrdinalIgnoreCase))
{
result.ExtraType = rule.ExtraType;
result.Rule = rule;
diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs
index 12bc22a6a..a3134f3f6 100644
--- a/Emby.Naming/Video/VideoListResolver.cs
+++ b/Emby.Naming/Video/VideoListResolver.cs
@@ -27,8 +27,9 @@ namespace Emby.Naming.Video
/// The naming options.
/// Indication we should consider multi-versions of content.
/// Whether to parse the name or use the filename.
+ /// Top-level folder for the containing library.
/// Returns enumerable of which groups files together when related.
- public static IReadOnlyList Resolve(IReadOnlyList videoInfos, NamingOptions namingOptions, bool supportMultiVersion = true, bool parseName = true)
+ public static IReadOnlyList Resolve(IReadOnlyList videoInfos, NamingOptions namingOptions, bool supportMultiVersion = true, bool parseName = true, string? libraryRoot = "")
{
// Filter out all extras, otherwise they could cause stacks to not be resolved
// See the unit test TestStackedWithTrailer
@@ -65,7 +66,7 @@ namespace Emby.Naming.Video
{
var info = new VideoInfo(stack.Name)
{
- Files = stack.Files.Select(i => VideoResolver.Resolve(i, stack.IsDirectoryStack, namingOptions, parseName))
+ Files = stack.Files.Select(i => VideoResolver.Resolve(i, stack.IsDirectoryStack, namingOptions, parseName, libraryRoot))
.OfType()
.ToList()
};
diff --git a/Emby.Naming/Video/VideoResolver.cs b/Emby.Naming/Video/VideoResolver.cs
index db5bfdbf9..afbf6f8fa 100644
--- a/Emby.Naming/Video/VideoResolver.cs
+++ b/Emby.Naming/Video/VideoResolver.cs
@@ -17,10 +17,11 @@ namespace Emby.Naming.Video
/// The path.
/// The naming options.
/// Whether to parse the name or use the filename.
+ /// Top-level folder for the containing library.
/// VideoFileInfo.
- public static VideoFileInfo? ResolveDirectory(string? path, NamingOptions namingOptions, bool parseName = true)
+ public static VideoFileInfo? ResolveDirectory(string? path, NamingOptions namingOptions, bool parseName = true, string? libraryRoot = "")
{
- return Resolve(path, true, namingOptions, parseName);
+ return Resolve(path, true, namingOptions, parseName, libraryRoot);
}
///
@@ -28,10 +29,11 @@ namespace Emby.Naming.Video
///
/// The path.
/// The naming options.
+ /// Top-level folder for the containing library.
/// VideoFileInfo.
- public static VideoFileInfo? ResolveFile(string? path, NamingOptions namingOptions)
+ public static VideoFileInfo? ResolveFile(string? path, NamingOptions namingOptions, string? libraryRoot = "")
{
- return Resolve(path, false, namingOptions);
+ return Resolve(path, false, namingOptions, libraryRoot: libraryRoot);
}
///
@@ -41,9 +43,10 @@ namespace Emby.Naming.Video
/// if set to true [is folder].
/// The naming options.
/// Whether or not the name should be parsed for info.
+ /// Top-level folder for the containing library.
/// VideoFileInfo.
/// path is null.
- public static VideoFileInfo? Resolve(string? path, bool isDirectory, NamingOptions namingOptions, bool parseName = true)
+ public static VideoFileInfo? Resolve(string? path, bool isDirectory, NamingOptions namingOptions, bool parseName = true, string? libraryRoot = "")
{
if (string.IsNullOrEmpty(path))
{
@@ -75,7 +78,7 @@ namespace Emby.Naming.Video
var format3DResult = Format3DParser.Parse(path, namingOptions);
- var extraResult = ExtraRuleResolver.GetExtraInfo(path, namingOptions);
+ var extraResult = ExtraRuleResolver.GetExtraInfo(path, namingOptions, libraryRoot);
var name = Path.GetFileNameWithoutExtension(path);
--
cgit v1.2.3