diff --git a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs index 96057f8b7..f9b051cd5 100644 --- a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs +++ b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs @@ -71,7 +71,7 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The MB name regex /// - private static readonly Regex MBNameRegex = new Regex("(\\[.*\\])", RegexOptions.Compiled); + private static readonly Regex MBNameRegex = new Regex(@"(\[boxset\]|\[tmdbid=\d+\]|\[tvdbid=\d+\])", RegexOptions.Compiled); /// /// Strip out attribute items and return just the name we will use for items @@ -85,10 +85,15 @@ namespace MediaBrowser.Server.Implementations.Library var fn = isDirectory ? Path.GetFileName(path) : Path.GetFileNameWithoutExtension(path); //now - strip out anything inside brackets - fn = MBNameRegex.Replace(fn, string.Empty); + fn = StripBrackets(fn); return fn; } + public static string StripBrackets(string inputString) { + var output = MBNameRegex.Replace(inputString, string.Empty).Trim(); + return Regex.Replace(output, @"\s+", " "); + } + } } diff --git a/MediaBrowser.Tests/MediaBrowser.Tests.csproj b/MediaBrowser.Tests/MediaBrowser.Tests.csproj index 95e55fda0..915b90c8e 100644 --- a/MediaBrowser.Tests/MediaBrowser.Tests.csproj +++ b/MediaBrowser.Tests/MediaBrowser.Tests.csproj @@ -54,6 +54,7 @@ + @@ -68,6 +69,10 @@ {442B5058-DCAF-4263-BB6A-F21E31120A1B} MediaBrowser.Providers + + {2E781478-814D-4A48-9D80-BFF206441A65} + MediaBrowser.Server.Implementations + diff --git a/MediaBrowser.Tests/Server.Implementations/Library/ResolverHelperTests.cs b/MediaBrowser.Tests/Server.Implementations/Library/ResolverHelperTests.cs new file mode 100644 index 000000000..84966d76f --- /dev/null +++ b/MediaBrowser.Tests/Server.Implementations/Library/ResolverHelperTests.cs @@ -0,0 +1,17 @@ +using MediaBrowser.Server.Implementations.Library; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace MediaBrowser.Tests.Server.Implementations.Library { + [TestClass] + public class ResolverHelperTests + { + [TestMethod] + public void TestStripBrackets() + { + Assert.AreEqual("My Movie [blah blah]", ResolverHelper.StripBrackets("My Movie [boxset] [blah blah]")); + Assert.AreEqual("[tag1] file 01", ResolverHelper.StripBrackets("[tag1] file 01 [tvdbid=12345]")); + Assert.AreEqual("[tag1] file 01", ResolverHelper.StripBrackets("[tag1] file 01 [tmdbid=12345]")); + Assert.AreEqual("[tag1] file 01", ResolverHelper.StripBrackets("[tag1] file [boxset] [tvdbid=12345] 01 [tmdbid=12345]")); + } + } +} \ No newline at end of file