diff --git a/frontend/src/Settings/MediaManagement/Naming/NamingModal.js b/frontend/src/Settings/MediaManagement/Naming/NamingModal.js index 48917c59c..4c7ddf9e6 100644 --- a/frontend/src/Settings/MediaManagement/Naming/NamingModal.js +++ b/frontend/src/Settings/MediaManagement/Naming/NamingModal.js @@ -49,7 +49,9 @@ const artistTokens = [ { token: '{Artist Disambiguation}', example: 'Disambiguation' }, - { token: '{Artist Genre}', example: 'Pop' } + { token: '{Artist Genre}', example: 'Pop' }, + + { token: '{Artist MbId}', example: 'db92a151-1ac2-438b-bc43-b82e149ddd50' } ]; const albumTokens = [ @@ -63,7 +65,9 @@ const albumTokens = [ { token: '{Album Disambiguation}', example: 'Disambiguation' }, - { token: '{Album Genre}', example: 'Rock' } + { token: '{Album Genre}', example: 'Rock' }, + + { token: '{Album MbId}', example: '082c6aff-a7cc-36e0-a960-35a578ecd937' } ]; const mediumTokens = [ @@ -92,7 +96,8 @@ const trackTitleTokens = [ const trackArtistTokens = [ { token: '{Track ArtistName}', example: 'Artist Name' }, { token: '{Track ArtistNameThe}', example: 'Artist Name, The' }, - { token: '{Track ArtistCleanName}', example: 'Artist Name' } + { token: '{Track ArtistCleanName}', example: 'Artist Name' }, + { token: '{Track ArtistMbId}', example: 'db92a151-1ac2-438b-bc43-b82e149ddd50' } ]; const qualityTokens = [ diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs index 0cb0e2f3a..23003ed51 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -26,6 +27,7 @@ public class FileNameBuilderFixture : CoreTest private AlbumRelease _release; private Track _track1; private Track _mixTrack1; + private Track _unknownTrack; private TrackFile _trackFile; private NamingConfig _namingConfig; @@ -41,6 +43,7 @@ public void Setup() Name = "Linkin Park", Genres = new List { "Rock" } }) + .With(s => s.ForeignArtistId = Guid.NewGuid().ToString()) .Build(); _variousArtists = Builder @@ -50,6 +53,7 @@ public void Setup() { Name = "Various Artists" }) + .With(s => s.ForeignArtistId = null) .Build(); _medium = Builder @@ -69,12 +73,14 @@ public void Setup() .With(s => s.AlbumType = "Album") .With(s => s.Disambiguation = "The Best Album") .With(s => s.Genres = new List { "Rock" }) + .With(s => s.ForeignAlbumId = Guid.NewGuid().ToString()) .Build(); _mixAlbum = Builder .CreateNew() .With(s => s.Title = "Cool Music") .With(s => s.AlbumType = "Album") + .With(s => s.ForeignAlbumId = null) .Build(); _namingConfig = NamingConfig.Default; @@ -99,6 +105,13 @@ public void Setup() .With(e => e.ArtistMetadata = _artist.Metadata) .Build(); + _unknownTrack = Builder.CreateNew() + .With(e => e.Title = "(Intermission)") + .With(e => e.AbsoluteTrackNumber = 3) + .With(e => e.AlbumRelease = _release) + .With(e => e.MediumNumber = _medium.Number) + .Build(); + _trackFile = Builder.CreateNew() .With(e => e.Quality = new QualityModel(Quality.MP3_256)) .With(e => e.ReleaseGroup = "LidarrTest") @@ -221,6 +234,24 @@ public void should_replace_artist_genre() .Should().Be("Rock"); } + [Test] + public void should_replace_Artist_space_MbId() + { + _namingConfig.StandardTrackFormat = "{Artist MbId}"; + + Subject.BuildTrackFileName(new List { _track1 }, _artist, _album, _trackFile) + .Should().Be(_artist.ForeignArtistId); + } + + [Test] + public void should_replace_Artist_MbId_null() + { + _namingConfig.StandardTrackFormat = "{Artist MbId}"; + + Subject.BuildTrackFileName(new List { _track1 }, _variousArtists, _mixAlbum, _trackFile) + .Should().Be(string.Empty); + } + [Test] public void should_replace_Album_space_Title() { @@ -321,6 +352,24 @@ public void should_cleanup_Album_Title() .Should().Be("Hybrid.Theory.2000"); } + [Test] + public void should_replace_Album_space_MbId() + { + _namingConfig.StandardTrackFormat = "{Album MbId}"; + + Subject.BuildTrackFileName(new List { _track1 }, _artist, _album, _trackFile) + .Should().Be(_album.ForeignAlbumId); + } + + [Test] + public void should_replace_Album_MbId_null() + { + _namingConfig.StandardTrackFormat = "{Album MbId}"; + + Subject.BuildTrackFileName(new List { _track1 }, _variousArtists, _mixAlbum, _trackFile) + .Should().Be(string.Empty); + } + [Test] public void should_replace_track_title() { @@ -359,6 +408,24 @@ public void should_replace_track00_number_with_two_digits() .Should().Be("01"); } + [Test] + public void should_replace_Track_space_Artist_MbId() + { + _namingConfig.StandardTrackFormat = "{Track ArtistMbId}"; + + Subject.BuildTrackFileName(new List { _track1 }, _artist, _album, _trackFile) + .Should().Be(_track1.ArtistMetadata?.Value?.ForeignArtistId); + } + + [Test] + public void should_replace_Track_Artist_MbId_null() + { + _namingConfig.StandardTrackFormat = "{Track ArtistMbId}"; + + Subject.BuildTrackFileName(new List { _unknownTrack }, _variousArtists, _mixAlbum, _trackFile) + .Should().Be(string.Empty); + } + [Test] public void should_replace_medium_number_with_single_digit() { diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 792f593e7..a576d11a9 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -276,6 +276,7 @@ private void AddArtistTokens(Dictionary> tokenH tokenHandlers["{Artist NameThe}"] = m => TitleThe(artist.Name); tokenHandlers["{Artist Genre}"] = m => artist.Metadata.Value.Genres?.FirstOrDefault() ?? string.Empty; tokenHandlers["{Artist NameFirstCharacter}"] = m => TitleThe(artist.Name).Substring(0, 1).FirstCharToUpper(); + tokenHandlers["{Artist MbId}"] = m => artist.ForeignArtistId ?? string.Empty; if (artist.Metadata.Value.Disambiguation != null) { @@ -290,6 +291,7 @@ private void AddAlbumTokens(Dictionary> tokenHa tokenHandlers["{Album TitleThe}"] = m => TitleThe(album.Title); tokenHandlers["{Album Type}"] = m => album.AlbumType; tokenHandlers["{Album Genre}"] = m => album.Genres.FirstOrDefault() ?? string.Empty; + tokenHandlers["{Album MbId}"] = m => album.ForeignAlbumId ?? string.Empty; if (album.Disambiguation != null) { @@ -325,6 +327,7 @@ private void AddTrackTokens(Dictionary> tokenHa tokenHandlers["{Track ArtistName}"] = m => firstArtist.Name; tokenHandlers["{Track ArtistCleanName}"] = m => CleanTitle(firstArtist.Name); tokenHandlers["{Track ArtistNameThe}"] = m => TitleThe(firstArtist.Name); + tokenHandlers["{Track ArtistMbId}"] = m => firstArtist.ForeignArtistId ?? string.Empty; } } diff --git a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs index c8f8fc5ed..e16d24351 100644 --- a/src/NzbDrone.Core/Organizer/FileNameSampleService.cs +++ b/src/NzbDrone.Core/Organizer/FileNameSampleService.cs @@ -34,12 +34,14 @@ public FileNameSampleService(IBuildFileNames buildFileNames) { Name = "The Artist Name", Disambiguation = "US Rock Band", - Genres = new List { "Pop" } + Genres = new List { "Pop" }, + ForeignArtistId = "db92a151-1ac2-438b-bc43-b82e149ddd50" }; _standardArtist = new Artist { - Metadata = artistMetadata + Metadata = artistMetadata, + ForeignArtistId = artistMetadata.ForeignArtistId, }; _standardAlbum = new Album @@ -48,7 +50,8 @@ public FileNameSampleService(IBuildFileNames buildFileNames) ReleaseDate = System.DateTime.Today, AlbumType = "Album", Disambiguation = "The Best Album", - Genres = new List { "Rock" } + Genres = new List { "Rock" }, + ForeignAlbumId = "082c6aff-a7cc-36e0-a960-35a578ecd937" }; _singleRelease = new AlbumRelease