diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 53cb10061..99270c8f8 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -337,6 +337,7 @@ + diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/IdFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/IdFixture.cs new file mode 100644 index 000000000..1232c20c5 --- /dev/null +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/IdFixture.cs @@ -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 + { + private Series _series; + private NamingConfig _namingConfig; + + [SetUp] + public void Setup() + { + _series = Builder + .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() + .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})"); + } + } +} diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 26d63a06b..d73319dbe 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -132,6 +132,7 @@ namespace NzbDrone.Core.Organizer pattern = AddAbsoluteNumberingTokens(pattern, tokenHandlers, series, episodes, namingConfig); AddSeriesTokens(tokenHandlers, series); + AddIdTokens(tokenHandlers, series); AddEpisodeTokens(tokenHandlers, episodes); AddEpisodeFileTokens(tokenHandlers, episodeFile); AddQualityTokens(tokenHandlers, series, episodeFile); @@ -232,6 +233,7 @@ namespace NzbDrone.Core.Organizer var tokenHandlers = new Dictionary>(FileNameBuilderTokenEqualityComparer.Instance); AddSeriesTokens(tokenHandlers, series); + AddIdTokens(tokenHandlers, series); return CleanFolderName(ReplaceTokens(namingConfig.SeriesFolderFormat, tokenHandlers, namingConfig)); } @@ -246,6 +248,7 @@ namespace NzbDrone.Core.Organizer var tokenHandlers = new Dictionary>(FileNameBuilderTokenEqualityComparer.Instance); AddSeriesTokens(tokenHandlers, series); + AddIdTokens(tokenHandlers, series); AddSeasonTokens(tokenHandlers, seasonNumber); return CleanFolderName(ReplaceTokens(namingConfig.SeasonFolderFormat, tokenHandlers, namingConfig)); @@ -551,6 +554,13 @@ namespace NzbDrone.Core.Organizer tokenHandlers["{MediaInfo Full}"] = m => $"{videoCodec} {audioCodec}{mediaInfoAudioLanguages} {mediaInfoSubtitleLanguages}"; } + private void AddIdTokens(Dictionary> 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) { List tokens = new List(); diff --git a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs index 78f076b5f..950df08db 100644 --- a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs +++ b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs @@ -42,21 +42,30 @@ namespace NzbDrone.Core.Organizer { SeriesType = SeriesTypes.Standard, Title = "The Series Title!", - Year = 2010 + Year = 2010, + ImdbId = "tt12345", + TvdbId = 12345, + TvMazeId = 54321 }; _dailySeries = new Series { SeriesType = SeriesTypes.Daily, Title = "The Series Title!", - Year = 2010 + Year = 2010, + ImdbId = "tt12345", + TvdbId = 12345, + TvMazeId = 54321 }; _animeSeries = new Series { SeriesType = SeriesTypes.Anime, Title = "The Series Title!", - Year = 2010 + Year = 2010, + ImdbId = "tt12345", + TvdbId = 12345, + TvMazeId = 54321 }; _episode1 = new Episode