1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 15:32:31 +01:00

Multi episode title cleanup #ND-67 Fixed

This commit is contained in:
Mark McDowall 2012-10-14 22:52:12 -07:00
parent 89c0a7a2f0
commit d25da21e58
5 changed files with 89 additions and 20 deletions

View File

@ -240,7 +240,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile()); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile());
//Assert //Assert
Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream [HDTV]", result);
} }
[Test] [Test]
@ -274,7 +274,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile()); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile());
//Assert //Assert
Assert.AreEqual("3x23x24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV]", result);
} }
[Test] [Test]
@ -308,7 +308,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile()); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile());
//Assert //Assert
Assert.AreEqual("3x23x24 Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result); Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV]", result);
} }
[Test] [Test]
@ -342,7 +342,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile()); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile());
//Assert //Assert
Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream.(1).+.Strawberries.and.Cream.(2)", result); Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream", result);
} }
[Test] [Test]
@ -517,7 +517,7 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, "30 Rock", QualityTypes.HDTV, false, new EpisodeFile()); string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, "30 Rock", QualityTypes.HDTV, false, new EpisodeFile());
//Assert //Assert
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong! (1) + Hey, Baby, What's Wrong! (2)"); result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
} }
[Test] [Test]
@ -635,5 +635,69 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
//Assert //Assert
result.Should().Be(episodeFile.SceneName); result.Should().Be(episodeFile.SceneName);
} }
[Test]
public void should_only_have_one_episodeTitle_when_episode_titles_are_the_same()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hey, Baby, What's Wrong? (1)")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 6)
.Build();
var episode2 = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hey, Baby, What's Wrong? (2)")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 7)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, "30 Rock", QualityTypes.HDTV, false, new EpisodeFile());
//Assert
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
}
[Test]
public void should_have_two_episodeTitles_when_episode_titles_are_not_the_same()
{
//Setup
var fakeConfig = Mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SortingIncludeSeriesName).Returns(true);
fakeConfig.SetupGet(c => c.SortingIncludeEpisodeTitle).Returns(true);
fakeConfig.SetupGet(c => c.SortingAppendQuality).Returns(false);
fakeConfig.SetupGet(c => c.SortingSeparatorStyle).Returns(0);
fakeConfig.SetupGet(c => c.SortingNumberStyle).Returns(2);
fakeConfig.SetupGet(c => c.SortingReplaceSpaces).Returns(false);
fakeConfig.SetupGet(c => c.SortingMultiEpisodeStyle).Returns(3);
var episode = Builder<Episode>.CreateNew()
.With(e => e.Title = "Hello")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 6)
.Build();
var episode2 = Builder<Episode>.CreateNew()
.With(e => e.Title = "World")
.With(e => e.SeasonNumber = 6)
.With(e => e.EpisodeNumber = 7)
.Build();
//Act
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episode2, episode }, "30 Rock", QualityTypes.HDTV, false, new EpisodeFile());
//Assert
result.Should().Be("30 Rock - S06E06-E07 - Hello + World");
}
} }
} }

View File

@ -83,6 +83,8 @@ namespace NzbDrone.Core
RegexOptions.IgnoreCase | RegexOptions.Compiled), RegexOptions.IgnoreCase | RegexOptions.Compiled),
}; };
private static readonly Regex MultiPartCleanupRegex = new Regex(@"\(\d+\)$", RegexOptions.Compiled);
internal static EpisodeParseResult ParsePath(string path) internal static EpisodeParseResult ParsePath(string path)
{ {
var fileInfo = new FileInfo(path); var fileInfo = new FileInfo(path);
@ -496,5 +498,11 @@ namespace NzbDrone.Core
return header; return header;
} }
internal static string CleanupEpisodeTitle(string title)
{
//this will remove (1),(2) from the end of multi part episodes.
return MultiPartCleanupRegex.Replace(title, string.Empty).Trim();
}
} }
} }

View File

@ -96,13 +96,10 @@ namespace NzbDrone.Core.Providers
} }
} }
public virtual String GetDownloadTitle(EpisodeParseResult parseResult) public virtual String GetDownloadTitle(EpisodeParseResult parseResult)
{ {
var seriesTitle = MediaFileProvider.CleanFilename(parseResult.Series.Title); var seriesTitle = MediaFileProvider.CleanFilename(parseResult.Series.Title);
//Handle Full Naming //Handle Full Naming
if (parseResult.FullSeason) if (parseResult.FullSeason)
{ {

View File

@ -16,22 +16,17 @@ namespace NzbDrone.Core.Providers
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Logger logger = LogManager.GetCurrentClassLogger();
//this will remove (1),(2) from the end of multi part episodes.
private static readonly Regex multiPartCleanupRegex = new Regex(@"\(\d+\)$", RegexOptions.Compiled);
private readonly TvDbProvider _tvDbProvider; private readonly TvDbProvider _tvDbProvider;
private readonly SeasonProvider _seasonProvider; private readonly SeasonProvider _seasonProvider;
private readonly IDatabase _database; private readonly IDatabase _database;
private readonly SeriesProvider _seriesProvider;
[Inject] [Inject]
public EpisodeProvider(IDatabase database, SeriesProvider seriesProvider, public EpisodeProvider(IDatabase database, TvDbProvider tvDbProviderProvider,
TvDbProvider tvDbProviderProvider, SeasonProvider seasonProvider) SeasonProvider seasonProvider)
{ {
_tvDbProvider = tvDbProviderProvider; _tvDbProvider = tvDbProviderProvider;
_seasonProvider = seasonProvider; _seasonProvider = seasonProvider;
_database = database; _database = database;
_seriesProvider = seriesProvider;
} }
public EpisodeProvider() public EpisodeProvider()
@ -228,7 +223,7 @@ namespace NzbDrone.Core.Providers
} }
else else
{ {
parseResult.EpisodeTitle = multiPartCleanupRegex.Replace(episodeInfo.Title, string.Empty).Trim(); parseResult.EpisodeTitle = Parser.CleanupEpisodeTitle(episodeInfo.Title);
} }
} }
else else

View File

@ -163,7 +163,9 @@ namespace NzbDrone.Core.Providers
var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configProvider.SortingSeparatorStyle); var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configProvider.SortingSeparatorStyle);
var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configProvider.SortingNumberStyle); var numberStyle = EpisodeSortingHelper.GetNumberStyle(_configProvider.SortingNumberStyle);
string episodeNames = sortedEpisodes.First().Title; var episodeNames = new List<String>();
episodeNames.Add(Parser.CleanupEpisodeTitle(sortedEpisodes.First().Title));
string result = String.Empty; string result = String.Empty;
@ -190,7 +192,7 @@ namespace NzbDrone.Core.Providers
} }
result = result.Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber)); result = result.Replace("%0e", String.Format("{0:00}", episode.EpisodeNumber));
episodeNames += String.Format(" + {0}", episode.Title); episodeNames.Add(Parser.CleanupEpisodeTitle(episode.Title));
} }
} }
@ -202,8 +204,11 @@ namespace NzbDrone.Core.Providers
if (_configProvider.SortingIncludeEpisodeTitle) if (_configProvider.SortingIncludeEpisodeTitle)
{ {
episodeNames = episodeNames.TrimEnd(' ', '+'); if (episodeNames.Distinct().Count() == 1)
result += separatorStyle.Pattern + episodeNames; result += separatorStyle.Pattern + episodeNames.First();
else
result += separatorStyle.Pattern + String.Join(" + ", episodeNames);
} }
if (_configProvider.SortingAppendQuality) if (_configProvider.SortingAppendQuality)