1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-25 17:27:18 +00:00

Fixed: Parser no longer chokes on titles with a file extension and invalid path characters such as :.

This commit is contained in:
Taloth Saldono 2014-10-21 23:51:38 +02:00
parent 8a86b8acdc
commit 10b45f769e
2 changed files with 20 additions and 7 deletions

View file

@ -52,6 +52,12 @@ namespace NzbDrone.Core.Test.ParserTests
title.CleanSeriesTitle().Should().Be("carnivale"); title.CleanSeriesTitle().Should().Be("carnivale");
} }
[TestCase("Discovery TV - Gold Rush : 02 Road From Hell [S04].mp4")]
public void should_clean_up_invalid_path_characters(String postTitle)
{
Parser.Parser.ParseTitle(postTitle);
}
[TestCase("[scnzbefnet][509103] 2.Broke.Girls.S03E18.720p.HDTV.X264-DIMENSION", "2 Broke Girls")] [TestCase("[scnzbefnet][509103] 2.Broke.Girls.S03E18.720p.HDTV.X264-DIMENSION", "2 Broke Girls")]
public void should_remove_request_info_from_title(String postTitle, String title) public void should_remove_request_info_from_title(String postTitle, String title)
{ {

View file

@ -138,6 +138,9 @@ namespace NzbDrone.Core.Parser
private static readonly Regex NormalizeRegex = new Regex(@"((?:\b|_)(?<!^)(a|an|the|and|or|of)(?:\b|_))|\W|_", private static readonly Regex NormalizeRegex = new Regex(@"((?:\b|_)(?<!^)(a|an|the|and|or|of)(?:\b|_))|\W|_",
RegexOptions.IgnoreCase | RegexOptions.Compiled); RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex FileExtensionRegex = new Regex(@"\.[a-z0-9]{2,4}$",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex SimpleTitleRegex = new Regex(@"480[i|p]|720[i|p]|1080[i|p]|[xh][\W_]?264|DD\W?5\W1|\<|\>|\?|\*|\:|\||848x480|1280x720|1920x1080|8bit|10bit", private static readonly Regex SimpleTitleRegex = new Regex(@"480[i|p]|720[i|p]|1080[i|p]|[xh][\W_]?264|DD\W?5\W1|\<|\>|\?|\*|\:|\||848x480|1280x720|1920x1080|8bit|10bit",
RegexOptions.IgnoreCase | RegexOptions.Compiled); RegexOptions.IgnoreCase | RegexOptions.Compiled);
@ -371,14 +374,18 @@ namespace NzbDrone.Core.Parser
public static string RemoveFileExtension(string title) public static string RemoveFileExtension(string title)
{ {
if (!title.ContainsInvalidPathChars()) title = FileExtensionRegex.Replace(title, m =>
{
var extension = Path.GetExtension(title).ToLower();
if (MediaFiles.MediaFileExtensions.Extensions.Contains(extension) || new [] { ".par2", ".nzb" }.Contains(extension))
{ {
title = Path.Combine(Path.GetDirectoryName(title), Path.GetFileNameWithoutExtension(title)); var extension = m.Value.ToLower();
} if (MediaFiles.MediaFileExtensions.Extensions.Contains(extension) || new[] { ".par2", ".nzb" }.Contains(extension))
} {
return String.Empty;
}
else
{
return m.Value;
}
});
return title; return title;
} }