1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

New: Option to remove illegal characters

Closes #809
This commit is contained in:
Mark McDowall 2015-10-04 13:13:14 -07:00
parent 68cd9ab8c8
commit 192d001b61
13 changed files with 60 additions and 19 deletions

View File

@ -6,6 +6,7 @@ namespace NzbDrone.Api.Config
public class NamingConfigResource : RestResource
{
public bool RenameEpisodes { get; set; }
public bool ReplaceIllegalCharacters { get; set; }
public int MultiEpisodeStyle { get; set; }
public string StandardEpisodeFormat { get; set; }
public string DailyEpisodeFormat { get; set; }

View File

@ -17,7 +17,7 @@ public class BuildFilePathFixture : CoreTest<FileNameBuilder>
[SetUp]
public void Setup()
{
namingConfig = new NamingConfig();
namingConfig = NamingConfig.Default;
Mocker.GetMock<INamingConfigService>()
.Setup(c => c.GetConfig()).Returns(namingConfig);

View File

@ -36,7 +36,7 @@ public void Setup()
_episodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p), ReleaseGroup = "SonarrTest" };
_namingConfig = new NamingConfig();
_namingConfig = NamingConfig.Default;
_namingConfig.RenameEpisodes = true;
Mocker.GetMock<INamingConfigService>()

View File

@ -30,7 +30,7 @@ public void Setup()
.Build();
_namingConfig = new NamingConfig();
_namingConfig = NamingConfig.Default;
_namingConfig.RenameEpisodes = true;

View File

@ -31,7 +31,7 @@ public void Setup()
.Build();
_namingConfig = new NamingConfig();
_namingConfig = NamingConfig.Default;
_namingConfig.RenameEpisodes = true;

View File

@ -33,7 +33,7 @@ public void Setup()
.Build();
_namingConfig = new NamingConfig();
_namingConfig = NamingConfig.Default;
_namingConfig.RenameEpisodes = true;

View File

@ -15,7 +15,7 @@ public class GetSeasonFolderFixture : CoreTest<FileNameBuilder>
[SetUp]
public void Setup()
{
namingConfig = new NamingConfig();
namingConfig = NamingConfig.Default;
Mocker.GetMock<INamingConfigService>()
.Setup(c => c.GetConfig()).Returns(namingConfig);

View File

@ -1,4 +1,3 @@
using System;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Organizer;
@ -16,7 +15,7 @@ public class GetSeriesFolderFixture : CoreTest<FileNameBuilder>
[SetUp]
public void Setup()
{
namingConfig = new NamingConfig();
namingConfig = NamingConfig.Default;
Mocker.GetMock<INamingConfigService>()
.Setup(c => c.GetConfig()).Returns(namingConfig);

View File

@ -0,0 +1,15 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(93)]
public class naming_config_replace_illegal_characters : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("NamingConfig").AddColumn("ReplaceIllegalCharacters").AsBoolean().WithDefaultValue(true);
Update.Table("NamingConfig").Set(new { ReplaceIllegalCharacters = true }).AllRows();
}
}
}

View File

@ -270,6 +270,7 @@
<Compile Include="Datastore\Migration\089_add_on_rename_to_notifcations.cs" />
<Compile Include="Datastore\Migration\090_update_kickass_url.cs" />
<Compile Include="Datastore\Migration\091_added_indexerstatus.cs" />
<Compile Include="Datastore\Migration\093_naming_config_replace_characters.cs" />
<Compile Include="Datastore\Migration\092_add_unverifiedscenenumbering.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />

View File

@ -128,7 +128,7 @@ public string BuildFileName(List<Episode> episodes, Series series, EpisodeFile e
AddQualityTokens(tokenHandlers, series, episodeFile);
AddMediaInfoTokens(tokenHandlers, episodeFile);
var fileName = ReplaceTokens(pattern, tokenHandlers).Trim();
var fileName = ReplaceTokens(pattern, tokenHandlers, namingConfig).Trim();
fileName = FileNameCleanupRegex.Replace(fileName, match => match.Captures[0].Value[0].ToString());
fileName = TrimSeparatorsRegex.Replace(fileName, string.Empty);
@ -224,7 +224,7 @@ public string GetSeriesFolder(Series series, NamingConfig namingConfig = null)
AddSeriesTokens(tokenHandlers, series);
return CleanFolderName(ReplaceTokens(namingConfig.SeriesFolderFormat, tokenHandlers));
return CleanFolderName(ReplaceTokens(namingConfig.SeriesFolderFormat, tokenHandlers, namingConfig));
}
public string GetSeasonFolder(Series series, int seasonNumber, NamingConfig namingConfig = null)
@ -239,7 +239,7 @@ public string GetSeasonFolder(Series series, int seasonNumber, NamingConfig nami
AddSeriesTokens(tokenHandlers, series);
AddSeasonTokens(tokenHandlers, seasonNumber);
return CleanFolderName(ReplaceTokens(namingConfig.SeasonFolderFormat, tokenHandlers));
return CleanFolderName(ReplaceTokens(namingConfig.SeasonFolderFormat, tokenHandlers, namingConfig));
}
public static string CleanTitle(string title)
@ -251,7 +251,7 @@ public static string CleanTitle(string title)
return title;
}
public static string CleanFileName(string name)
public static string CleanFileName(string name, bool replace = true)
{
string result = name;
string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" };
@ -259,7 +259,7 @@ public static string CleanFileName(string name)
for (int i = 0; i < badCharacters.Length; i++)
{
result = result.Replace(badCharacters[i], goodCharacters[i]);
result = result.Replace(badCharacters[i], replace ? goodCharacters[i] : string.Empty);
}
return result.Trim();
@ -551,12 +551,12 @@ private string GetLanguagesToken(string mediaInfoLanguages)
return string.Join("+", tokens.Distinct());
}
private string ReplaceTokens(string pattern, Dictionary<string, Func<TokenMatch, string>> tokenHandlers)
private string ReplaceTokens(string pattern, Dictionary<string, Func<TokenMatch, string>> tokenHandlers, NamingConfig namingConfig)
{
return TitleRegex.Replace(pattern, match => ReplaceToken(match, tokenHandlers));
return TitleRegex.Replace(pattern, match => ReplaceToken(match, tokenHandlers, namingConfig));
}
private string ReplaceToken(Match match, Dictionary<string, Func<TokenMatch, string>> tokenHandlers)
private string ReplaceToken(Match match, Dictionary<string, Func<TokenMatch, string>> tokenHandlers, NamingConfig namingConfig)
{
var tokenMatch = new TokenMatch
{
@ -591,7 +591,7 @@ private string ReplaceToken(Match match, Dictionary<string, Func<TokenMatch, str
replacementText = replacementText.Replace(" ", tokenMatch.Separator);
}
replacementText = CleanFileName(replacementText);
replacementText = CleanFileName(replacementText, namingConfig.ReplaceIllegalCharacters);
if (!replacementText.IsNullOrWhiteSpace())
{

View File

@ -11,6 +11,7 @@ public static NamingConfig Default
return new NamingConfig
{
RenameEpisodes = false,
ReplaceIllegalCharacters = true,
MultiEpisodeStyle = 0,
StandardEpisodeFormat = "{Series Title} - S{season:00}E{episode:00} - {Episode Title} {Quality Full}",
DailyEpisodeFormat = "{Series Title} - {Air-Date} - {Episode Title} {Quality Full}",
@ -22,6 +23,7 @@ public static NamingConfig Default
}
public bool RenameEpisodes { get; set; }
public bool ReplaceIllegalCharacters { get; set; }
public int MultiEpisodeStyle { get; set; }
public string StandardEpisodeFormat { get; set; }
public string DailyEpisodeFormat { get; set; }
@ -29,4 +31,4 @@ public static NamingConfig Default
public string SeriesFolderFormat { get; set; }
public string SeasonFolderFormat { get; set; }
}
}
}

View File

@ -24,6 +24,29 @@
</div>
</div>
<div class="form-group advanced-setting">
<label class="col-sm-3 control-label">Replace Illegal Characters</label>
<div class="col-sm-8">
<div class="input-group">
<label class="checkbox toggle well">
<input type="checkbox" name="replaceIllegalCharacters" />
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
<span class="help-inline-checkbox">
<i class="icon-sonarr-form-info" title="Replace or Remove illegal characters"/>
</span>
</div>
</div>
</div>
<div class="x-naming-options">
<div class="basic-setting x-basic-naming"></div>
@ -184,7 +207,7 @@
<div class="form-group">
<label class="col-sm-3 control-label">Single Episode Example</label>
<div class="col-sm-8">
<p class="form-control-static x-single-episode-example naming-example"></p>
</div>