mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed: Double periods in filenames will be replaces with a single period
This commit is contained in:
parent
859e36aa6b
commit
6d8b38366f
@ -405,5 +405,35 @@ public void should_trim_question_marks_from_end_of_episode_title()
|
||||
Subject.BuildFilename(new List<Episode> { episode }, new Series { Title = "30 Rock" }, _episodeFile)
|
||||
.Should().Be("30 Rock - S06E06 - Part 1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_replace_double_period_with_single_period()
|
||||
{
|
||||
_namingConfig.StandardEpisodeFormat = "{Series.Title}.S{season:00}E{episode:00}.{Episode.Title}";
|
||||
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.Title = "Part 1")
|
||||
.With(e => e.SeasonNumber = 6)
|
||||
.With(e => e.EpisodeNumber = 6)
|
||||
.Build();
|
||||
|
||||
Subject.BuildFilename(new List<Episode> { episode }, new Series { Title = "Chicago P.D." }, _episodeFile)
|
||||
.Should().Be("Chicago.P.D.S06E06.Part.1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_replace_triple_period_with_single_period()
|
||||
{
|
||||
_namingConfig.StandardEpisodeFormat = "{Series.Title}.S{season:00}E{episode:00}.{Episode.Title}";
|
||||
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.Title = "Part 1")
|
||||
.With(e => e.SeasonNumber = 6)
|
||||
.With(e => e.EpisodeNumber = 6)
|
||||
.Build();
|
||||
|
||||
Subject.BuildFilename(new List<Episode> { episode }, new Series { Title = "Chicago P.D.." }, _episodeFile)
|
||||
.Should().Be("Chicago.P.D.S06E06.Part.1");
|
||||
}
|
||||
}
|
||||
}
|
@ -46,6 +46,8 @@ public class FileNameBuilder : IBuildFileNames
|
||||
public static readonly Regex SeriesTitleRegex = new Regex(@"(?<token>\{(?:Series)(?<separator>\s|\.|-|_)Title\})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex FilenameCleanupRegex = new Regex(@"\.{2,}", RegexOptions.Compiled);
|
||||
|
||||
private static readonly char[] EpisodeTitleTrimCharaters = new[] { ' ', '.', '?' };
|
||||
|
||||
public FileNameBuilder(INamingConfigService namingConfigService,
|
||||
@ -90,6 +92,7 @@ public string BuildFilename(IList<Episode> episodes, Series series, EpisodeFile
|
||||
|
||||
var sortedEpisodes = episodes.OrderBy(e => e.EpisodeNumber).ToList();
|
||||
var pattern = namingConfig.StandardEpisodeFormat;
|
||||
|
||||
var episodeTitles = new List<string>
|
||||
{
|
||||
sortedEpisodes.First().Title.TrimEnd(EpisodeTitleTrimCharaters)
|
||||
@ -153,8 +156,11 @@ public string BuildFilename(IList<Episode> episodes, Series series, EpisodeFile
|
||||
|
||||
tokenValues.Add("{Episode Title}", GetEpisodeTitle(episodeTitles));
|
||||
tokenValues.Add("{Quality Title}", GetQualityTitle(episodeFile.Quality));
|
||||
|
||||
return CleanFilename(ReplaceTokens(pattern, tokenValues).Trim());
|
||||
|
||||
var filename = ReplaceTokens(pattern, tokenValues).Trim();
|
||||
filename = FilenameCleanupRegex.Replace(filename, match => match.Captures[0].Value[0].ToString() );
|
||||
|
||||
return CleanFilename(filename);
|
||||
}
|
||||
|
||||
public string BuildFilePath(Series series, int seasonNumber, string fileName, string extension)
|
||||
|
Loading…
Reference in New Issue
Block a user