Adding Artist Id, Album Id, and Track Artist Id as file name options.

This commit is contained in:
Scott Fridlund 2022-07-27 19:30:34 -05:00 committed by Qstick
parent 8ea54b6a94
commit 8a685be882
4 changed files with 84 additions and 6 deletions

View file

@ -49,7 +49,9 @@ const artistTokens = [
{ token: '{Artist Disambiguation}', example: 'Disambiguation' }, { 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 = [ const albumTokens = [
@ -63,7 +65,9 @@ const albumTokens = [
{ token: '{Album Disambiguation}', example: 'Disambiguation' }, { 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 = [ const mediumTokens = [
@ -92,7 +96,8 @@ const trackTitleTokens = [
const trackArtistTokens = [ const trackArtistTokens = [
{ token: '{Track ArtistName}', example: 'Artist Name' }, { token: '{Track ArtistName}', example: 'Artist Name' },
{ token: '{Track ArtistNameThe}', example: 'Artist Name, The' }, { 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 = [ const qualityTokens = [

View file

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -26,6 +27,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
private AlbumRelease _release; private AlbumRelease _release;
private Track _track1; private Track _track1;
private Track _mixTrack1; private Track _mixTrack1;
private Track _unknownTrack;
private TrackFile _trackFile; private TrackFile _trackFile;
private NamingConfig _namingConfig; private NamingConfig _namingConfig;
@ -41,6 +43,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
Name = "Linkin Park", Name = "Linkin Park",
Genres = new List<string> { "Rock" } Genres = new List<string> { "Rock" }
}) })
.With(s => s.ForeignArtistId = Guid.NewGuid().ToString())
.Build(); .Build();
_variousArtists = Builder<Artist> _variousArtists = Builder<Artist>
@ -50,6 +53,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
{ {
Name = "Various Artists" Name = "Various Artists"
}) })
.With(s => s.ForeignArtistId = null)
.Build(); .Build();
_medium = Builder<Medium> _medium = Builder<Medium>
@ -69,12 +73,14 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
.With(s => s.AlbumType = "Album") .With(s => s.AlbumType = "Album")
.With(s => s.Disambiguation = "The Best Album") .With(s => s.Disambiguation = "The Best Album")
.With(s => s.Genres = new List<string> { "Rock" }) .With(s => s.Genres = new List<string> { "Rock" })
.With(s => s.ForeignAlbumId = Guid.NewGuid().ToString())
.Build(); .Build();
_mixAlbum = Builder<Album> _mixAlbum = Builder<Album>
.CreateNew() .CreateNew()
.With(s => s.Title = "Cool Music") .With(s => s.Title = "Cool Music")
.With(s => s.AlbumType = "Album") .With(s => s.AlbumType = "Album")
.With(s => s.ForeignAlbumId = null)
.Build(); .Build();
_namingConfig = NamingConfig.Default; _namingConfig = NamingConfig.Default;
@ -99,6 +105,13 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
.With(e => e.ArtistMetadata = _artist.Metadata) .With(e => e.ArtistMetadata = _artist.Metadata)
.Build(); .Build();
_unknownTrack = Builder<Track>.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<TrackFile>.CreateNew() _trackFile = Builder<TrackFile>.CreateNew()
.With(e => e.Quality = new QualityModel(Quality.MP3_256)) .With(e => e.Quality = new QualityModel(Quality.MP3_256))
.With(e => e.ReleaseGroup = "LidarrTest") .With(e => e.ReleaseGroup = "LidarrTest")
@ -221,6 +234,24 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
.Should().Be("Rock"); .Should().Be("Rock");
} }
[Test]
public void should_replace_Artist_space_MbId()
{
_namingConfig.StandardTrackFormat = "{Artist MbId}";
Subject.BuildTrackFileName(new List<Track> { _track1 }, _artist, _album, _trackFile)
.Should().Be(_artist.ForeignArtistId);
}
[Test]
public void should_replace_Artist_MbId_null()
{
_namingConfig.StandardTrackFormat = "{Artist MbId}";
Subject.BuildTrackFileName(new List<Track> { _track1 }, _variousArtists, _mixAlbum, _trackFile)
.Should().Be(string.Empty);
}
[Test] [Test]
public void should_replace_Album_space_Title() public void should_replace_Album_space_Title()
{ {
@ -321,6 +352,24 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
.Should().Be("Hybrid.Theory.2000"); .Should().Be("Hybrid.Theory.2000");
} }
[Test]
public void should_replace_Album_space_MbId()
{
_namingConfig.StandardTrackFormat = "{Album MbId}";
Subject.BuildTrackFileName(new List<Track> { _track1 }, _artist, _album, _trackFile)
.Should().Be(_album.ForeignAlbumId);
}
[Test]
public void should_replace_Album_MbId_null()
{
_namingConfig.StandardTrackFormat = "{Album MbId}";
Subject.BuildTrackFileName(new List<Track> { _track1 }, _variousArtists, _mixAlbum, _trackFile)
.Should().Be(string.Empty);
}
[Test] [Test]
public void should_replace_track_title() public void should_replace_track_title()
{ {
@ -359,6 +408,24 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
.Should().Be("01"); .Should().Be("01");
} }
[Test]
public void should_replace_Track_space_Artist_MbId()
{
_namingConfig.StandardTrackFormat = "{Track ArtistMbId}";
Subject.BuildTrackFileName(new List<Track> { _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<Track> { _unknownTrack }, _variousArtists, _mixAlbum, _trackFile)
.Should().Be(string.Empty);
}
[Test] [Test]
public void should_replace_medium_number_with_single_digit() public void should_replace_medium_number_with_single_digit()
{ {

View file

@ -276,6 +276,7 @@ namespace NzbDrone.Core.Organizer
tokenHandlers["{Artist NameThe}"] = m => TitleThe(artist.Name); tokenHandlers["{Artist NameThe}"] = m => TitleThe(artist.Name);
tokenHandlers["{Artist Genre}"] = m => artist.Metadata.Value.Genres?.FirstOrDefault() ?? string.Empty; tokenHandlers["{Artist Genre}"] = m => artist.Metadata.Value.Genres?.FirstOrDefault() ?? string.Empty;
tokenHandlers["{Artist NameFirstCharacter}"] = m => TitleThe(artist.Name).Substring(0, 1).FirstCharToUpper(); 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) if (artist.Metadata.Value.Disambiguation != null)
{ {
@ -290,6 +291,7 @@ namespace NzbDrone.Core.Organizer
tokenHandlers["{Album TitleThe}"] = m => TitleThe(album.Title); tokenHandlers["{Album TitleThe}"] = m => TitleThe(album.Title);
tokenHandlers["{Album Type}"] = m => album.AlbumType; tokenHandlers["{Album Type}"] = m => album.AlbumType;
tokenHandlers["{Album Genre}"] = m => album.Genres.FirstOrDefault() ?? string.Empty; tokenHandlers["{Album Genre}"] = m => album.Genres.FirstOrDefault() ?? string.Empty;
tokenHandlers["{Album MbId}"] = m => album.ForeignAlbumId ?? string.Empty;
if (album.Disambiguation != null) if (album.Disambiguation != null)
{ {
@ -325,6 +327,7 @@ namespace NzbDrone.Core.Organizer
tokenHandlers["{Track ArtistName}"] = m => firstArtist.Name; tokenHandlers["{Track ArtistName}"] = m => firstArtist.Name;
tokenHandlers["{Track ArtistCleanName}"] = m => CleanTitle(firstArtist.Name); tokenHandlers["{Track ArtistCleanName}"] = m => CleanTitle(firstArtist.Name);
tokenHandlers["{Track ArtistNameThe}"] = m => TitleThe(firstArtist.Name); tokenHandlers["{Track ArtistNameThe}"] = m => TitleThe(firstArtist.Name);
tokenHandlers["{Track ArtistMbId}"] = m => firstArtist.ForeignArtistId ?? string.Empty;
} }
} }

View file

@ -34,12 +34,14 @@ namespace NzbDrone.Core.Organizer
{ {
Name = "The Artist Name", Name = "The Artist Name",
Disambiguation = "US Rock Band", Disambiguation = "US Rock Band",
Genres = new List<string> { "Pop" } Genres = new List<string> { "Pop" },
ForeignArtistId = "db92a151-1ac2-438b-bc43-b82e149ddd50"
}; };
_standardArtist = new Artist _standardArtist = new Artist
{ {
Metadata = artistMetadata Metadata = artistMetadata,
ForeignArtistId = artistMetadata.ForeignArtistId,
}; };
_standardAlbum = new Album _standardAlbum = new Album
@ -48,7 +50,8 @@ namespace NzbDrone.Core.Organizer
ReleaseDate = System.DateTime.Today, ReleaseDate = System.DateTime.Today,
AlbumType = "Album", AlbumType = "Album",
Disambiguation = "The Best Album", Disambiguation = "The Best Album",
Genres = new List<string> { "Rock" } Genres = new List<string> { "Rock" },
ForeignAlbumId = "082c6aff-a7cc-36e0-a960-35a578ecd937"
}; };
_singleRelease = new AlbumRelease _singleRelease = new AlbumRelease