mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
Fixed: Better colon replacement logic
Closes #2193 Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
parent
032089b1f9
commit
6af492a0b6
2 changed files with 94 additions and 0 deletions
|
@ -0,0 +1,88 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.CustomFormats;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.Music;
|
||||||
|
using NzbDrone.Core.Organizer;
|
||||||
|
using NzbDrone.Core.Qualities;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ReplaceCharacterFixture : CoreTest<FileNameBuilder>
|
||||||
|
{
|
||||||
|
private Artist _artist;
|
||||||
|
private Album _album;
|
||||||
|
private AlbumRelease _release;
|
||||||
|
private Track _track;
|
||||||
|
private TrackFile _trackFiles;
|
||||||
|
private NamingConfig _namingConfig;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_artist = Builder<Artist>
|
||||||
|
.CreateNew()
|
||||||
|
.With(s => s.Name = "South Park")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_album = Builder<Album>
|
||||||
|
.CreateNew()
|
||||||
|
.With(s => s.Title = "Some Album")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_release = Builder<AlbumRelease>
|
||||||
|
.CreateNew()
|
||||||
|
.With(s => s.Media = new List<Medium> { new Medium { Number = 1 } })
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_track = Builder<Track>.CreateNew()
|
||||||
|
.With(e => e.Title = "City Sushi")
|
||||||
|
.With(e => e.AbsoluteTrackNumber = 15)
|
||||||
|
.With(e => e.AlbumRelease = _release)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_trackFiles = new TrackFile { Quality = new QualityModel(Quality.FLAC), ReleaseGroup = "SonarrTest" };
|
||||||
|
|
||||||
|
_namingConfig = NamingConfig.Default;
|
||||||
|
_namingConfig.RenameTracks = true;
|
||||||
|
|
||||||
|
Mocker.GetMock<INamingConfigService>()
|
||||||
|
.Setup(c => c.GetConfig()).Returns(_namingConfig);
|
||||||
|
|
||||||
|
Mocker.GetMock<IQualityDefinitionService>()
|
||||||
|
.Setup(v => v.Get(Moq.It.IsAny<Quality>()))
|
||||||
|
.Returns<Quality>(v => Quality.DefaultQualityDefinitions.First(c => c.Quality == v));
|
||||||
|
|
||||||
|
Mocker.GetMock<ICustomFormatService>()
|
||||||
|
.Setup(v => v.All())
|
||||||
|
.Returns(new List<CustomFormat>());
|
||||||
|
}
|
||||||
|
|
||||||
|
// { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" };
|
||||||
|
// { "+", "+", "", "", "!", "-", " -", "", "" };
|
||||||
|
[TestCase("CSI: Crime Scene Investigation", "CSI - Crime Scene Investigation")]
|
||||||
|
[TestCase("Code:Breaker", "Code-Breaker")]
|
||||||
|
[TestCase("Back Slash\\", "Back Slash+")]
|
||||||
|
[TestCase("Forward Slash/", "Forward Slash+")]
|
||||||
|
[TestCase("Greater Than>", "Greater Than")]
|
||||||
|
[TestCase("Less Than<", "Less Than")]
|
||||||
|
[TestCase("Question Mark?", "Question Mark!")]
|
||||||
|
[TestCase("Aster*sk", "Aster-sk")]
|
||||||
|
[TestCase("Colon: Two Periods", "Colon - Two Periods")]
|
||||||
|
[TestCase("Pipe|", "Pipe")]
|
||||||
|
[TestCase("Quotes\"", "Quotes")]
|
||||||
|
public void should_replace_illegal_characters(string title, string expected)
|
||||||
|
{
|
||||||
|
_artist.Name = title;
|
||||||
|
_namingConfig.StandardTrackFormat = "{Artist Name}";
|
||||||
|
|
||||||
|
Subject.BuildTrackFileName(new List<Track> { _track }, _artist, _album, _trackFiles)
|
||||||
|
.Should().Be(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -249,6 +249,12 @@ namespace NzbDrone.Core.Organizer
|
||||||
string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" };
|
string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" };
|
||||||
string[] goodCharacters = { "+", "+", "", "", "!", "-", "-", "", "" };
|
string[] goodCharacters = { "+", "+", "", "", "!", "-", "-", "", "" };
|
||||||
|
|
||||||
|
// Replace a colon followed by a space with space dash space for a better appearance
|
||||||
|
if (replace)
|
||||||
|
{
|
||||||
|
result = result.Replace(": ", " - ");
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < badCharacters.Length; i++)
|
for (int i = 0; i < badCharacters.Length; i++)
|
||||||
{
|
{
|
||||||
result = result.Replace(badCharacters[i], replace ? goodCharacters[i] : string.Empty);
|
result = result.Replace(badCharacters[i], replace ? goodCharacters[i] : string.Empty);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue