New: Renaming tokens for IMDB ID, TVDB ID and TV Maze ID

Closes #2659
This commit is contained in:
Mark McDowall 2018-09-09 15:07:09 -07:00 committed by Taloth Saldono
parent a550186337
commit ca079a77ce
4 changed files with 88 additions and 3 deletions

View File

@ -337,6 +337,7 @@
<Compile Include="OrganizerTests\FileNameBuilderTests\EpisodeTitleCollapseFixture.cs" /> <Compile Include="OrganizerTests\FileNameBuilderTests\EpisodeTitleCollapseFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\MultiEpisodeFixture.cs" /> <Compile Include="OrganizerTests\FileNameBuilderTests\MultiEpisodeFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleYearFixture.cs" /> <Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleYearFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\IdFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleYearFixture.cs" /> <Compile Include="OrganizerTests\FileNameBuilderTests\TitleYearFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheYearFixture.cs" /> <Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheYearFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheFixture.cs" /> <Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheFixture.cs" />

View File

@ -0,0 +1,65 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NUnit.Framework.Internal;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{
[TestFixture]
public class IdFixture : CoreTest<FileNameBuilder>
{
private Series _series;
private NamingConfig _namingConfig;
[SetUp]
public void Setup()
{
_series = Builder<Series>
.CreateNew()
.With(s => s.Title = "Series Title")
.With(s => s.ImdbId = "tt12345")
.With(s => s.TvdbId = 12345)
.With(s => s.TvRageId = 54321)
.Build();
_namingConfig = NamingConfig.Default;
Mocker.GetMock<INamingConfigService>()
.Setup(c => c.GetConfig()).Returns(_namingConfig);
}
[Test]
public void should_add_imdb_id()
{
_namingConfig.SeriesFolderFormat = "{Series Title} ({ImdbId})";
Subject.GetSeriesFolder(_series)
.Should().Be($"Series Title ({_series.ImdbId})");
}
[Test]
public void should_add_tvdb_id()
{
_namingConfig.SeriesFolderFormat = "{Series Title} ({TvdbId})";
Subject.GetSeriesFolder(_series)
.Should().Be($"Series Title ({_series.TvdbId})");
}
[Test]
public void should_add_tvmaze_id()
{
_namingConfig.SeriesFolderFormat = "{Series Title} ({TvMazeId})";
Subject.GetSeriesFolder(_series)
.Should().Be($"Series Title ({_series.TvMazeId})");
}
}
}

View File

@ -132,6 +132,7 @@ namespace NzbDrone.Core.Organizer
pattern = AddAbsoluteNumberingTokens(pattern, tokenHandlers, series, episodes, namingConfig); pattern = AddAbsoluteNumberingTokens(pattern, tokenHandlers, series, episodes, namingConfig);
AddSeriesTokens(tokenHandlers, series); AddSeriesTokens(tokenHandlers, series);
AddIdTokens(tokenHandlers, series);
AddEpisodeTokens(tokenHandlers, episodes); AddEpisodeTokens(tokenHandlers, episodes);
AddEpisodeFileTokens(tokenHandlers, episodeFile); AddEpisodeFileTokens(tokenHandlers, episodeFile);
AddQualityTokens(tokenHandlers, series, episodeFile); AddQualityTokens(tokenHandlers, series, episodeFile);
@ -232,6 +233,7 @@ namespace NzbDrone.Core.Organizer
var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance); var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance);
AddSeriesTokens(tokenHandlers, series); AddSeriesTokens(tokenHandlers, series);
AddIdTokens(tokenHandlers, series);
return CleanFolderName(ReplaceTokens(namingConfig.SeriesFolderFormat, tokenHandlers, namingConfig)); return CleanFolderName(ReplaceTokens(namingConfig.SeriesFolderFormat, tokenHandlers, namingConfig));
} }
@ -246,6 +248,7 @@ namespace NzbDrone.Core.Organizer
var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance); var tokenHandlers = new Dictionary<string, Func<TokenMatch, string>>(FileNameBuilderTokenEqualityComparer.Instance);
AddSeriesTokens(tokenHandlers, series); AddSeriesTokens(tokenHandlers, series);
AddIdTokens(tokenHandlers, series);
AddSeasonTokens(tokenHandlers, seasonNumber); AddSeasonTokens(tokenHandlers, seasonNumber);
return CleanFolderName(ReplaceTokens(namingConfig.SeasonFolderFormat, tokenHandlers, namingConfig)); return CleanFolderName(ReplaceTokens(namingConfig.SeasonFolderFormat, tokenHandlers, namingConfig));
@ -551,6 +554,13 @@ namespace NzbDrone.Core.Organizer
tokenHandlers["{MediaInfo Full}"] = m => $"{videoCodec} {audioCodec}{mediaInfoAudioLanguages} {mediaInfoSubtitleLanguages}"; tokenHandlers["{MediaInfo Full}"] = m => $"{videoCodec} {audioCodec}{mediaInfoAudioLanguages} {mediaInfoSubtitleLanguages}";
} }
private void AddIdTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Series series)
{
tokenHandlers["{ImdbId}"] = m => series.ImdbId;
tokenHandlers["{TvdbId}"] = m => series.TvdbId.ToString();
tokenHandlers["{TvMazeId}"] = m => series.TvMazeId.ToString();
}
private string GetLanguagesToken(string mediaInfoLanguages) private string GetLanguagesToken(string mediaInfoLanguages)
{ {
List<string> tokens = new List<string>(); List<string> tokens = new List<string>();

View File

@ -42,21 +42,30 @@ namespace NzbDrone.Core.Organizer
{ {
SeriesType = SeriesTypes.Standard, SeriesType = SeriesTypes.Standard,
Title = "The Series Title!", Title = "The Series Title!",
Year = 2010 Year = 2010,
ImdbId = "tt12345",
TvdbId = 12345,
TvMazeId = 54321
}; };
_dailySeries = new Series _dailySeries = new Series
{ {
SeriesType = SeriesTypes.Daily, SeriesType = SeriesTypes.Daily,
Title = "The Series Title!", Title = "The Series Title!",
Year = 2010 Year = 2010,
ImdbId = "tt12345",
TvdbId = 12345,
TvMazeId = 54321
}; };
_animeSeries = new Series _animeSeries = new Series
{ {
SeriesType = SeriesTypes.Anime, SeriesType = SeriesTypes.Anime,
Title = "The Series Title!", Title = "The Series Title!",
Year = 2010 Year = 2010,
ImdbId = "tt12345",
TvdbId = 12345,
TvMazeId = 54321
}; };
_episode1 = new Episode _episode1 = new Episode