mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
Multi episode title cleanup #ND-67 Fixed
This commit is contained in:
parent
89c0a7a2f0
commit
d25da21e58
@ -240,7 +240,7 @@ public void GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash()
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile());
|
||||
|
||||
//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]
|
||||
@ -274,7 +274,7 @@ public void GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash()
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("3x23x24 - Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result);
|
||||
Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV]", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -308,7 +308,7 @@ public void GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space()
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile());
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual("3x23x24 Strawberries and Cream (1) + Strawberries and Cream (2) [HDTV]", result);
|
||||
Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV]", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -342,7 +342,7 @@ public void GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period()
|
||||
string result = Mocker.Resolve<MediaFileProvider>().GetNewFilename(new List<Episode> { episodeOne, episodeTwo }, "The Mentalist", QualityTypes.HDTV, false, new EpisodeFile());
|
||||
|
||||
//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]
|
||||
@ -517,7 +517,7 @@ public void GetNewFilename_should_order_multiple_episode_files_in_numerical_orde
|
||||
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! (1) + Hey, Baby, What's Wrong! (2)");
|
||||
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -635,5 +635,69 @@ public void GetNewFilename_UseSceneName_when_sceneName_isNotNull()
|
||||
//Assert
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
@ -83,6 +83,8 @@ public static class Parser
|
||||
RegexOptions.IgnoreCase | RegexOptions.Compiled),
|
||||
};
|
||||
|
||||
private static readonly Regex MultiPartCleanupRegex = new Regex(@"\(\d+\)$", RegexOptions.Compiled);
|
||||
|
||||
internal static EpisodeParseResult ParsePath(string path)
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
@ -496,5 +498,11 @@ internal static string ParseHeader(string 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -96,13 +96,10 @@ public virtual IDownloadClient GetActiveDownloadClient()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual String GetDownloadTitle(EpisodeParseResult parseResult)
|
||||
{
|
||||
|
||||
var seriesTitle = MediaFileProvider.CleanFilename(parseResult.Series.Title);
|
||||
|
||||
|
||||
//Handle Full Naming
|
||||
if (parseResult.FullSeason)
|
||||
{
|
||||
|
@ -16,22 +16,17 @@ public class EpisodeProvider
|
||||
|
||||
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 SeasonProvider _seasonProvider;
|
||||
private readonly IDatabase _database;
|
||||
private readonly SeriesProvider _seriesProvider;
|
||||
|
||||
[Inject]
|
||||
public EpisodeProvider(IDatabase database, SeriesProvider seriesProvider,
|
||||
TvDbProvider tvDbProviderProvider, SeasonProvider seasonProvider)
|
||||
public EpisodeProvider(IDatabase database, TvDbProvider tvDbProviderProvider,
|
||||
SeasonProvider seasonProvider)
|
||||
{
|
||||
_tvDbProvider = tvDbProviderProvider;
|
||||
_seasonProvider = seasonProvider;
|
||||
_database = database;
|
||||
_seriesProvider = seriesProvider;
|
||||
}
|
||||
|
||||
public EpisodeProvider()
|
||||
@ -228,7 +223,7 @@ public virtual IList<Episode> GetEpisodesByParseResult(EpisodeParseResult parseR
|
||||
}
|
||||
else
|
||||
{
|
||||
parseResult.EpisodeTitle = multiPartCleanupRegex.Replace(episodeInfo.Title, string.Empty).Trim();
|
||||
parseResult.EpisodeTitle = Parser.CleanupEpisodeTitle(episodeInfo.Title);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -163,7 +163,9 @@ public virtual string GetNewFilename(IList<Episode> episodes, string seriesTitle
|
||||
var separatorStyle = EpisodeSortingHelper.GetSeparatorStyle(_configProvider.SortingSeparatorStyle);
|
||||
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;
|
||||
|
||||
@ -190,7 +192,7 @@ public virtual string GetNewFilename(IList<Episode> episodes, string seriesTitle
|
||||
}
|
||||
|
||||
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 @@ public virtual string GetNewFilename(IList<Episode> episodes, string seriesTitle
|
||||
|
||||
if (_configProvider.SortingIncludeEpisodeTitle)
|
||||
{
|
||||
episodeNames = episodeNames.TrimEnd(' ', '+');
|
||||
result += separatorStyle.Pattern + episodeNames;
|
||||
if (episodeNames.Distinct().Count() == 1)
|
||||
result += separatorStyle.Pattern + episodeNames.First();
|
||||
|
||||
else
|
||||
result += separatorStyle.Pattern + String.Join(" + ", episodeNames);
|
||||
}
|
||||
|
||||
if (_configProvider.SortingAppendQuality)
|
||||
|
Loading…
Reference in New Issue
Block a user