strip only certain bracket blocks fixes #598

This commit is contained in:
Luis Miguel Almánzar 2013-11-02 21:19:33 -04:00
parent ab490d7467
commit 8a0606e970
3 changed files with 29 additions and 2 deletions

View File

@ -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.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+", " ");
}
}
}

View File

@ -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'">

View File

@ -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]"));
}
}
}