The Free Software Media System - Server Backend & API
strip only certain bracket blocks fixes #598
Luis Miguel Almánzar8a0606e9704f
diff --git a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs b/MediaBrowser.Server.Implementations/Library/ResolverHelper.csindex 96057f8b7e..f9b051cd57 100644--- a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs+++ b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs@@ -71,7 +71,7 @@ namespace MediaBrowser.Server.Implementations.Library/// <summary>/// The MB name regex/// </summary>- private static readonly Regex MBNameRegex = new Regex("(\\[.*\\])", RegexOptions.Compiled);+ private static readonly Regex MBNameRegex = new Regex(@"(\[boxset\]|\[tmdbid=\d+\]|\[tvdbid=\d+\])", RegexOptions.Compiled);/// <summary>/// Strip out attribute items and return just the name we will use for items@@ -85,10 +85,15 @@ namespace MediaBrowser.Server.Implementations.Libraryvar 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.csprojindex 95e55fda0c..915b90c8ea 100644--- a/MediaBrowser.Tests/MediaBrowser.Tests.csproj+++ b/MediaBrowser.Tests/MediaBrowser.Tests.csproj@@ -54,6 +54,7 @@<Compile Include="Resolvers\MovieResolverTests.cs" /><Compile Include="Resolvers\TvUtilTests.cs" /><Compile Include="Properties\AssemblyInfo.cs" />+ <Compile Include="Server.Implementations\Library\ResolverHelperTests.cs" /></ItemGroup><ItemGroup><ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj">@@ -68,6 +69,10 @@<Project>{442B5058-DCAF-4263-BB6A-F21E31120A1B}</Project><Name>MediaBrowser.Providers</Name></ProjectReference>+ <ProjectReference Include="..\MediaBrowser.Server.Implementations\MediaBrowser.Server.Implementations.csproj">+ <Project>{2E781478-814D-4A48-9D80-BFF206441A65}</Project>+ <Name>MediaBrowser.Server.Implementations</Name>+ </ProjectReference></ItemGroup><Choose><When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">diff --git a/MediaBrowser.Tests/Server.Implementations/Library/ResolverHelperTests.cs b/MediaBrowser.Tests/Server.Implementations/Library/ResolverHelperTests.csnew file mode 100644index 0000000000..84966d76f9--- /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