mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
[UI Work] Settings Naming Page, Other Settings
This commit is contained in:
parent
22d9c5e666
commit
456ead09da
14 changed files with 281 additions and 393 deletions
|
@ -36,9 +36,9 @@ namespace Lidarr.Api.V3.Config
|
|||
Get["/examples"] = x => GetExamples(this.Bind<NamingConfigResource>());
|
||||
|
||||
|
||||
SharedValidator.RuleFor(c => c.StandardTrackFormat).ValidEpisodeFormat();
|
||||
SharedValidator.RuleFor(c => c.ArtistFolderFormat).ValidSeriesFolderFormat();
|
||||
SharedValidator.RuleFor(c => c.AlbumFolderFormat).ValidSeasonFolderFormat();
|
||||
SharedValidator.RuleFor(c => c.StandardTrackFormat).ValidTrackFormat();
|
||||
SharedValidator.RuleFor(c => c.ArtistFolderFormat).ValidArtistFolderFormat();
|
||||
SharedValidator.RuleFor(c => c.AlbumFolderFormat).ValidAlbumFolderFormat();
|
||||
}
|
||||
|
||||
private void UpdateNamingConfig(NamingConfigResource resource)
|
||||
|
@ -99,7 +99,7 @@ namespace Lidarr.Api.V3.Config
|
|||
{
|
||||
var singleTrackSampleResult = _filenameSampleService.GetStandardTrackSample(nameSpec);
|
||||
|
||||
var singleTrackValidationResult = _filenameValidationService.ValidateStandardFilename(singleTrackSampleResult);
|
||||
var singleTrackValidationResult = _filenameValidationService.ValidateTrackFilename(singleTrackSampleResult);
|
||||
|
||||
var validationFailures = new List<ValidationFailure>();
|
||||
|
||||
|
|
|
@ -5,10 +5,6 @@ namespace Lidarr.Api.V3.Config
|
|||
public class NamingExampleResource
|
||||
{
|
||||
public string SingleTrackExample { get; set; }
|
||||
public string MultiEpisodeExample { get; set; }
|
||||
public string DailyEpisodeExample { get; set; }
|
||||
public string AnimeEpisodeExample { get; set; }
|
||||
public string AnimeMultiEpisodeExample { get; set; }
|
||||
public string ArtistFolderExample { get; set; }
|
||||
public string AlbumFolderExample { get; set; }
|
||||
}
|
||||
|
|
|
@ -301,6 +301,7 @@
|
|||
<Compile Include="NotificationTests\NotificationBaseFixture.cs" />
|
||||
<Compile Include="NotificationTests\SynologyIndexerFixture.cs" />
|
||||
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleFixture.cs" />
|
||||
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheFixture.cs" />
|
||||
<Compile Include="ParserTests\MiniSeriesEpisodeParserFixture.cs" />
|
||||
<Compile Include="ParserTests\MusicParserFixture.cs" />
|
||||
<Compile Include="Qualities\RevisionComparableFixture.cs" />
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TitleTheFixture : CoreTest<FileNameBuilder>
|
||||
{
|
||||
private Artist _artist;
|
||||
private Album _album;
|
||||
private Track _track;
|
||||
private TrackFile _trackFile;
|
||||
private NamingConfig _namingConfig;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_artist = Builder<Artist>
|
||||
.CreateNew()
|
||||
.With(s => s.Name = "Alien Ant Farm")
|
||||
.Build();
|
||||
|
||||
_album = Builder<Album>
|
||||
.CreateNew()
|
||||
.With(s => s.Title = "Anthology")
|
||||
.Build();
|
||||
|
||||
_track = Builder<Track>.CreateNew()
|
||||
.With(e => e.Title = "City Sushi")
|
||||
.With(e => e.TrackNumber = 6)
|
||||
.Build();
|
||||
|
||||
_trackFile = new TrackFile { Quality = new QualityModel(Quality.MP3_320), ReleaseGroup = "LidarrTest" };
|
||||
|
||||
_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));
|
||||
}
|
||||
|
||||
[TestCase("The Mist", "Mist, The")]
|
||||
[TestCase("A Place to Call Home", "Place to Call Home, A")]
|
||||
[TestCase("An Adventure in Space and Time", "Adventure in Space and Time, An")]
|
||||
[TestCase("The Flash (2010)", "Flash, The (2010)")]
|
||||
[TestCase("A League Of Their Own (AU)", "League Of Their Own, A (AU)")]
|
||||
[TestCase("The Fixer (ZH) (2015)", "Fixer, The (ZH) (2015)")]
|
||||
[TestCase("The Sixth Sense 2 (Thai)", "Sixth Sense 2, The (Thai)")]
|
||||
[TestCase("The Amazing Race (Latin America)", "Amazing Race, The (Latin America)")]
|
||||
[TestCase("The Rat Pack (A&E)", "Rat Pack, The (A&E)")]
|
||||
[TestCase("The Climax: I (Almost) Got Away With It (2016)", "Climax- I (Almost) Got Away With It, The (2016)")]
|
||||
//[TestCase("", "")]
|
||||
public void should_get_expected_title_back(string name, string expected)
|
||||
{
|
||||
_artist.Name = name;
|
||||
_namingConfig.StandardTrackFormat = "{Artist NameThe}";
|
||||
|
||||
Subject.BuildTrackFileName(new List<Track> { _track }, _artist, _album, _trackFile)
|
||||
.Should().Be(expected);
|
||||
}
|
||||
|
||||
[TestCase("A")]
|
||||
[TestCase("Anne")]
|
||||
[TestCase("Theodore")]
|
||||
[TestCase("3%")]
|
||||
public void should_not_change_title(string name)
|
||||
{
|
||||
_artist.Name = name;
|
||||
_namingConfig.StandardTrackFormat = "{Artist NameThe}";
|
||||
|
||||
Subject.BuildTrackFileName(new List<Track> { _track }, _artist, _album, _trackFile)
|
||||
.Should().Be(name);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -60,10 +60,10 @@ namespace NzbDrone.Core.Organizer
|
|||
public static readonly Regex SeriesTitleRegex = new Regex(@"(?<token>\{(?:Series)(?<separator>[- ._])(Clean)?Title\})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static readonly Regex ArtistNameRegex = new Regex(@"(?<token>\{(?:Artist)(?<separator>[- ._])(Clean)?Name\})",
|
||||
public static readonly Regex ArtistNameRegex = new Regex(@"(?<token>\{(?:Artist)(?<separator>[- ._])(Clean)?Name(The)\})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static readonly Regex AlbumTitleRegex = new Regex(@"(?<token>\{(?:Album)(?<separator>[- ._])(Clean)?Title\})",
|
||||
public static readonly Regex AlbumTitleRegex = new Regex(@"(?<token>\{(?:Album)(?<separator>[- ._])(Clean)?Title(The)\})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex FileNameCleanupRegex = new Regex(@"([- ._])(\1)+", RegexOptions.Compiled);
|
||||
|
@ -77,6 +77,8 @@ namespace NzbDrone.Core.Organizer
|
|||
|
||||
private static readonly char[] EpisodeTitleTrimCharacters = new[] { ' ', '.', '?' };
|
||||
|
||||
private static readonly Regex TitlePrefixRegex = new Regex(@"^(The|An|A) (.*?)((?: *\([^)]+\))*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public FileNameBuilder(INamingConfigService namingConfigService,
|
||||
IQualityDefinitionService qualityDefinitionService,
|
||||
ICacheManager cacheManager,
|
||||
|
@ -110,10 +112,10 @@ namespace NzbDrone.Core.Organizer
|
|||
var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance);
|
||||
|
||||
tracks = tracks.OrderBy(e => e.AlbumId).ThenBy(e => e.TrackNumber).ToList();
|
||||
|
||||
|
||||
pattern = FormatTrackNumberTokens(pattern, "", tracks);
|
||||
//pattern = AddAbsoluteNumberingTokens(pattern, tokenHandlers, series, episodes, namingConfig);
|
||||
|
||||
|
||||
AddArtistTokens(tokenHandlers, artist);
|
||||
AddAlbumTokens(tokenHandlers, album);
|
||||
AddTrackTokens(tokenHandlers, tracks);
|
||||
|
@ -143,13 +145,13 @@ namespace NzbDrone.Core.Organizer
|
|||
|
||||
if (artist.AlbumFolder)
|
||||
{
|
||||
|
||||
|
||||
var albumFolder = GetAlbumFolder(artist, album);
|
||||
|
||||
albumFolder = CleanFileName(albumFolder);
|
||||
|
||||
path = Path.Combine(path, albumFolder);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return path;
|
||||
|
@ -165,9 +167,9 @@ namespace NzbDrone.Core.Organizer
|
|||
}
|
||||
|
||||
var basicNamingConfig = new BasicNamingConfig
|
||||
{
|
||||
Separator = trackFormat.Separator
|
||||
};
|
||||
{
|
||||
Separator = trackFormat.Separator
|
||||
};
|
||||
|
||||
var titleTokens = TitleRegex.Matches(nameSpec.StandardTrackFormat);
|
||||
|
||||
|
@ -238,6 +240,11 @@ namespace NzbDrone.Core.Organizer
|
|||
return title;
|
||||
}
|
||||
|
||||
public static string TitleThe(string title)
|
||||
{
|
||||
return TitlePrefixRegex.Replace(title, "$2, $1$3");
|
||||
}
|
||||
|
||||
public static string CleanFileName(string name, bool replace = true)
|
||||
{
|
||||
string result = name;
|
||||
|
@ -262,12 +269,14 @@ namespace NzbDrone.Core.Organizer
|
|||
{
|
||||
tokenHandlers["{Artist Name}"] = m => artist.Name;
|
||||
tokenHandlers["{Artist CleanName}"] = m => CleanTitle(artist.Name);
|
||||
tokenHandlers["{Artist NameThe}"] = m => TitleThe(artist.Name);
|
||||
}
|
||||
|
||||
private void AddAlbumTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Album album)
|
||||
{
|
||||
tokenHandlers["{Album Title}"] = m => album.Title;
|
||||
tokenHandlers["{Album CleanTitle}"] = m => CleanTitle(album.Title);
|
||||
tokenHandlers["{Album TitleThe}"] = m => TitleThe(album.Title);
|
||||
if (album.ReleaseDate.HasValue)
|
||||
{
|
||||
tokenHandlers["{Release Year}"] = m => album.ReleaseDate.Value.Year.ToString();
|
||||
|
@ -321,7 +330,7 @@ namespace NzbDrone.Core.Organizer
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var audioCodec = MediaInfoFormatter.FormatAudioCodec(trackFile.MediaInfo);
|
||||
var audioChannels = MediaInfoFormatter.FormatAudioChannels(trackFile.MediaInfo);
|
||||
|
||||
|
@ -468,7 +477,7 @@ namespace NzbDrone.Core.Organizer
|
|||
|
||||
private AbsoluteTrackFormat[] GetAbsoluteFormat(string pattern)
|
||||
{
|
||||
return _absoluteTrackFormatCache.Get(pattern, () => AbsoluteEpisodePatternRegex.Matches(pattern).OfType<Match>()
|
||||
return _absoluteTrackFormatCache.Get(pattern, () => AbsoluteEpisodePatternRegex.Matches(pattern).OfType<Match>()
|
||||
.Select(match => new AbsoluteTrackFormat
|
||||
{
|
||||
Separator = match.Groups["separator"].Value.IsNotNullOrWhiteSpace() ? match.Groups["separator"].Value : "-",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Music;
|
||||
|
@ -30,12 +30,12 @@ namespace NzbDrone.Core.Organizer
|
|||
|
||||
_standardArtist = new Artist
|
||||
{
|
||||
Name = "Artist Name"
|
||||
Name = "The Artist Name"
|
||||
};
|
||||
|
||||
_standardAlbum = new Album
|
||||
{
|
||||
Title = "Album Title",
|
||||
Title = "The Album Title",
|
||||
ReleaseDate = System.DateTime.Today
|
||||
};
|
||||
|
||||
|
|
|
@ -1,41 +1,19 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation.Results;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.Organizer
|
||||
{
|
||||
public interface IFilenameValidationService
|
||||
{
|
||||
ValidationFailure ValidateStandardFilename(SampleResult sampleResult);
|
||||
ValidationFailure ValidateTrackFilename(SampleResult sampleResult);
|
||||
ValidationFailure ValidateDailyFilename(SampleResult sampleResult);
|
||||
ValidationFailure ValidateAnimeFilename(SampleResult sampleResult);
|
||||
}
|
||||
|
||||
public class FileNameValidationService : IFilenameValidationService
|
||||
{
|
||||
private const string ERROR_MESSAGE = "Produces invalid file names";
|
||||
|
||||
public ValidationFailure ValidateStandardFilename(SampleResult sampleResult)
|
||||
{
|
||||
var validationFailure = new ValidationFailure("StandardEpisodeFormat", ERROR_MESSAGE);
|
||||
var parsedEpisodeInfo = Parser.Parser.ParseTitle(sampleResult.FileName);
|
||||
|
||||
if (parsedEpisodeInfo == null)
|
||||
{
|
||||
return validationFailure;
|
||||
}
|
||||
|
||||
if (!ValidateSeasonAndEpisodeNumbers(sampleResult.Episodes, parsedEpisodeInfo))
|
||||
{
|
||||
return validationFailure;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ValidationFailure ValidateTrackFilename(SampleResult sampleResult)
|
||||
{
|
||||
var validationFailure = new ValidationFailure("StandardTrackFormat", ERROR_MESSAGE);
|
||||
|
@ -57,71 +35,5 @@ namespace NzbDrone.Core.Organizer
|
|||
return null;
|
||||
}
|
||||
|
||||
public ValidationFailure ValidateDailyFilename(SampleResult sampleResult)
|
||||
{
|
||||
var validationFailure = new ValidationFailure("DailyEpisodeFormat", ERROR_MESSAGE);
|
||||
var parsedEpisodeInfo = Parser.Parser.ParseTitle(sampleResult.FileName);
|
||||
|
||||
if (parsedEpisodeInfo == null)
|
||||
{
|
||||
return validationFailure;
|
||||
}
|
||||
|
||||
if (parsedEpisodeInfo.IsDaily)
|
||||
{
|
||||
if (!parsedEpisodeInfo.AirDate.Equals(sampleResult.Episodes.Single().AirDate))
|
||||
{
|
||||
return validationFailure;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!ValidateSeasonAndEpisodeNumbers(sampleResult.Episodes, parsedEpisodeInfo))
|
||||
{
|
||||
return validationFailure;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ValidationFailure ValidateAnimeFilename(SampleResult sampleResult)
|
||||
{
|
||||
var validationFailure = new ValidationFailure("AnimeEpisodeFormat", ERROR_MESSAGE);
|
||||
var parsedEpisodeInfo = Parser.Parser.ParseTitle(sampleResult.FileName);
|
||||
|
||||
if (parsedEpisodeInfo == null)
|
||||
{
|
||||
return validationFailure;
|
||||
}
|
||||
|
||||
if (parsedEpisodeInfo.AbsoluteEpisodeNumbers.Any())
|
||||
{
|
||||
if (!parsedEpisodeInfo.AbsoluteEpisodeNumbers.First().Equals(sampleResult.Episodes.First().AbsoluteEpisodeNumber))
|
||||
{
|
||||
return validationFailure;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!ValidateSeasonAndEpisodeNumbers(sampleResult.Episodes, parsedEpisodeInfo))
|
||||
{
|
||||
return validationFailure;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool ValidateSeasonAndEpisodeNumbers(List<Episode> episodes, ParsedEpisodeInfo parsedEpisodeInfo)
|
||||
{
|
||||
if (parsedEpisodeInfo.SeasonNumber != episodes.First().SeasonNumber ||
|
||||
!parsedEpisodeInfo.EpisodeNumbers.OrderBy(e => e).SequenceEqual(episodes.Select(e => e.EpisodeNumber).OrderBy(e => e)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue