Fix: Episode naming for files with multiple episodes.

pull/4/head
Mark McDowall 13 years ago
parent 659b3dee55
commit 1abeef7239

@ -487,5 +487,37 @@ namespace NzbDrone.Core.Test.ProviderTests.MediaFileProviderTests
//Assert //Assert
result.Should().Be("South Park - S15E06 - City Sushi"); result.Should().Be("South Park - S15E06 - City Sushi");
} }
[Test]
public void GetNewFilename_should_order_multiple_episode_files_in_numerical_order()
{
//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);
//Assert
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong! (1) + Hey, Baby, What's Wrong! (2)");
}
} }
} }

@ -139,10 +139,12 @@ namespace NzbDrone.Core.Providers
public virtual string GetNewFilename(IList<Episode> episodes, string seriesTitle, QualityTypes quality, bool proper) public virtual string GetNewFilename(IList<Episode> episodes, string seriesTitle, QualityTypes quality, bool proper)
{ {
var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber);
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 = episodes[0].Title; string episodeNames = sortedEpisodes.First().Title;
string result = String.Empty; string result = String.Empty;
@ -151,13 +153,13 @@ namespace NzbDrone.Core.Providers
result += seriesTitle + separatorStyle.Pattern; result += seriesTitle + separatorStyle.Pattern;
} }
result += numberStyle.Pattern.Replace("%0e", String.Format("{0:00}", episodes[0].EpisodeNumber)); result += numberStyle.Pattern.Replace("%0e", String.Format("{0:00}", sortedEpisodes.First().EpisodeNumber));
if (episodes.Count > 1) if (episodes.Count > 1)
{ {
var multiEpisodeStyle = EpisodeSortingHelper.GetMultiEpisodeStyle(_configProvider.SortingMultiEpisodeStyle); var multiEpisodeStyle = EpisodeSortingHelper.GetMultiEpisodeStyle(_configProvider.SortingMultiEpisodeStyle);
foreach (var episode in episodes.OrderBy(e => e.EpisodeNumber).Skip(1)) foreach (var episode in sortedEpisodes.Skip(1))
{ {
if (multiEpisodeStyle.Name == "Duplicate") if (multiEpisodeStyle.Name == "Duplicate")
{ {

Loading…
Cancel
Save