mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
parent
dd11f74073
commit
5b7339cd73
92 changed files with 2611 additions and 145 deletions
|
@ -35,6 +35,16 @@ namespace Lidarr.Api.V1.Artist
|
|||
artist.ProfileId = resource.QualityProfileId.Value;
|
||||
}
|
||||
|
||||
if (resource.LanguageProfileId.HasValue)
|
||||
{
|
||||
artist.LanguageProfileId = resource.LanguageProfileId.Value;
|
||||
}
|
||||
|
||||
if (resource.MetadataProfileId.HasValue)
|
||||
{
|
||||
artist.MetadataProfileId = resource.MetadataProfileId.Value;
|
||||
}
|
||||
|
||||
if (resource.AlbumFolder.HasValue)
|
||||
{
|
||||
artist.AlbumFolder = resource.AlbumFolder.Value;
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Lidarr.Api.V1.Artist
|
|||
public bool? Monitored { get; set; }
|
||||
public int? QualityProfileId { get; set; }
|
||||
public int? LanguageProfileId { get; set; }
|
||||
public int? MetadataProfileId { get; set; }
|
||||
//public SeriesTypes? SeriesType { get; set; }
|
||||
public bool? AlbumFolder { get; set; }
|
||||
public string RootFolderPath { get; set; }
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace Lidarr.Api.V1.Artist
|
|||
public string Path { get; set; }
|
||||
public int QualityProfileId { get; set; }
|
||||
public int LanguageProfileId { get; set; }
|
||||
public int MetadataProfileId { get; set; }
|
||||
|
||||
//Editing Only
|
||||
public bool AlbumFolder { get; set; }
|
||||
|
@ -89,9 +90,6 @@ namespace Lidarr.Api.V1.Artist
|
|||
ArtistType = model.ArtistType,
|
||||
Disambiguation = model.Disambiguation,
|
||||
|
||||
PrimaryAlbumTypes = model.PrimaryAlbumTypes,
|
||||
SecondaryAlbumTypes = model.SecondaryAlbumTypes,
|
||||
|
||||
Images = model.Images,
|
||||
|
||||
Albums = model.Albums.ToResource(),
|
||||
|
@ -100,6 +98,7 @@ namespace Lidarr.Api.V1.Artist
|
|||
Path = model.Path,
|
||||
QualityProfileId = model.ProfileId,
|
||||
LanguageProfileId = model.LanguageProfileId,
|
||||
MetadataProfileId = model.MetadataProfileId,
|
||||
Links = model.Links,
|
||||
|
||||
AlbumFolder = model.AlbumFolder,
|
||||
|
@ -146,9 +145,8 @@ namespace Lidarr.Api.V1.Artist
|
|||
Path = resource.Path,
|
||||
ProfileId = resource.QualityProfileId,
|
||||
LanguageProfileId = resource.LanguageProfileId,
|
||||
MetadataProfileId = resource.MetadataProfileId,
|
||||
Links = resource.Links,
|
||||
PrimaryAlbumTypes = resource.PrimaryAlbumTypes,
|
||||
SecondaryAlbumTypes = resource.SecondaryAlbumTypes,
|
||||
|
||||
AlbumFolder = resource.AlbumFolder,
|
||||
Monitored = resource.Monitored,
|
||||
|
|
|
@ -94,6 +94,10 @@
|
|||
<Compile Include="Commands\CommandResource.cs" />
|
||||
<Compile Include="Config\MetadataProviderConfigModule.cs" />
|
||||
<Compile Include="Config\MetadataProviderConfigResource.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfileModule.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfileResource.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfileSchemaModule.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataValidator.cs" />
|
||||
<Compile Include="Profiles\Quality\QualityCutoffValidator.cs" />
|
||||
<Compile Include="Profiles\Quality\QualityItemsValidator.cs" />
|
||||
<Compile Include="TrackFiles\TrackFileListResource.cs" />
|
||||
|
|
57
src/Lidarr.Api.V1/Profiles/Metadata/MetadataProfileModule.cs
Normal file
57
src/Lidarr.Api.V1/Profiles/Metadata/MetadataProfileModule.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System.Collections.Generic;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using Lidarr.Http;
|
||||
|
||||
namespace Lidarr.Api.V1.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfileModule : LidarrRestModule<MetadataProfileResource>
|
||||
{
|
||||
private readonly IMetadataProfileService _profileService;
|
||||
|
||||
public MetadataProfileModule(IMetadataProfileService profileService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.PrimaryAlbumTypes).MustHaveAllowedPrimaryType();
|
||||
SharedValidator.RuleFor(c => c.SecondaryAlbumTypes).MustHaveAllowedSecondaryType();
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
GetResourceById = GetById;
|
||||
UpdateResource = Update;
|
||||
CreateResource = Create;
|
||||
DeleteResource = DeleteProfile;
|
||||
}
|
||||
|
||||
private int Create(MetadataProfileResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
model = _profileService.Add(model);
|
||||
return model.Id;
|
||||
}
|
||||
|
||||
private void DeleteProfile(int id)
|
||||
{
|
||||
_profileService.Delete(id);
|
||||
}
|
||||
|
||||
private void Update(MetadataProfileResource resource)
|
||||
{
|
||||
var model = resource.ToModel();
|
||||
|
||||
_profileService.Update(model);
|
||||
}
|
||||
|
||||
private MetadataProfileResource GetById(int id)
|
||||
{
|
||||
return _profileService.Get(id).ToResource();
|
||||
}
|
||||
|
||||
private List<MetadataProfileResource> GetAll()
|
||||
{
|
||||
var profiles = _profileService.All().ToResource();
|
||||
|
||||
return profiles;
|
||||
}
|
||||
}
|
||||
}
|
110
src/Lidarr.Api.V1/Profiles/Metadata/MetadataProfileResource.cs
Normal file
110
src/Lidarr.Api.V1/Profiles/Metadata/MetadataProfileResource.cs
Normal file
|
@ -0,0 +1,110 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using Lidarr.Http.REST;
|
||||
|
||||
namespace Lidarr.Api.V1.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfileResource : RestResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<ProfilePrimaryAlbumTypeItemResource> PrimaryAlbumTypes { get; set; }
|
||||
public List<ProfileSecondaryAlbumTypeItemResource> SecondaryAlbumTypes { get; set; }
|
||||
}
|
||||
|
||||
public class ProfilePrimaryAlbumTypeItemResource : RestResource
|
||||
{
|
||||
public NzbDrone.Core.Music.PrimaryAlbumType AlbumType { get; set; }
|
||||
public bool Allowed { get; set; }
|
||||
}
|
||||
|
||||
public class ProfileSecondaryAlbumTypeItemResource : RestResource
|
||||
{
|
||||
public NzbDrone.Core.Music.SecondaryAlbumType AlbumType { get; set; }
|
||||
public bool Allowed { get; set; }
|
||||
}
|
||||
|
||||
public static class MetadataProfileResourceMapper
|
||||
{
|
||||
public static MetadataProfileResource ToResource(this MetadataProfile model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new MetadataProfileResource
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
PrimaryAlbumTypes = model.PrimaryAlbumTypes.ConvertAll(ToResource),
|
||||
SecondaryAlbumTypes = model.SecondaryAlbumTypes.ConvertAll(ToResource)
|
||||
};
|
||||
}
|
||||
|
||||
public static ProfilePrimaryAlbumTypeItemResource ToResource(this ProfilePrimaryAlbumTypeItem model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new ProfilePrimaryAlbumTypeItemResource
|
||||
{
|
||||
AlbumType = model.PrimaryAlbumType,
|
||||
Allowed = model.Allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static ProfileSecondaryAlbumTypeItemResource ToResource(this ProfileSecondaryAlbumTypeItem model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ProfileSecondaryAlbumTypeItemResource
|
||||
{
|
||||
AlbumType = model.SecondaryAlbumType,
|
||||
Allowed = model.Allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static MetadataProfile ToModel(this MetadataProfileResource resource)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MetadataProfile
|
||||
{
|
||||
Id = resource.Id,
|
||||
Name = resource.Name,
|
||||
PrimaryAlbumTypes = resource.PrimaryAlbumTypes.ConvertAll(ToModel),
|
||||
SecondaryAlbumTypes = resource.SecondaryAlbumTypes.ConvertAll(ToModel)
|
||||
};
|
||||
}
|
||||
|
||||
public static ProfilePrimaryAlbumTypeItem ToModel(this ProfilePrimaryAlbumTypeItemResource resource)
|
||||
{
|
||||
if (resource == null) return null;
|
||||
|
||||
return new ProfilePrimaryAlbumTypeItem
|
||||
{
|
||||
PrimaryAlbumType = (NzbDrone.Core.Music.PrimaryAlbumType)resource.AlbumType.Id,
|
||||
Allowed = resource.Allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static ProfileSecondaryAlbumTypeItem ToModel(this ProfileSecondaryAlbumTypeItemResource resource)
|
||||
{
|
||||
if (resource == null) return null;
|
||||
|
||||
return new ProfileSecondaryAlbumTypeItem
|
||||
{
|
||||
SecondaryAlbumType = (NzbDrone.Core.Music.SecondaryAlbumType)resource.AlbumType.Id,
|
||||
Allowed = resource.Allowed
|
||||
};
|
||||
}
|
||||
|
||||
public static List<MetadataProfileResource> ToResource(this IEnumerable<MetadataProfile> models)
|
||||
{
|
||||
return models.Select(ToResource).ToList();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
using System.Linq;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using Lidarr.Http;
|
||||
|
||||
namespace Lidarr.Api.V1.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfileSchemaModule : LidarrRestModule<MetadataProfileResource>
|
||||
{
|
||||
|
||||
public MetadataProfileSchemaModule()
|
||||
: base("/metadataprofile/schema")
|
||||
{
|
||||
GetResourceSingle = GetAll;
|
||||
}
|
||||
|
||||
private MetadataProfileResource GetAll()
|
||||
{
|
||||
var orderedPrimTypes = NzbDrone.Core.Music.PrimaryAlbumType.All
|
||||
.OrderByDescending(l => l.Id)
|
||||
.ToList();
|
||||
|
||||
var orderedSecTypes = NzbDrone.Core.Music.SecondaryAlbumType.All
|
||||
.OrderByDescending(l => l.Id)
|
||||
.ToList();
|
||||
|
||||
var primTypes = orderedPrimTypes.Select(v => new ProfilePrimaryAlbumTypeItem {PrimaryAlbumType = v, Allowed = false})
|
||||
.ToList();
|
||||
|
||||
var secTypes = orderedSecTypes.Select(v => new ProfileSecondaryAlbumTypeItem { SecondaryAlbumType = v, Allowed = false })
|
||||
.ToList();
|
||||
|
||||
var profile = new MetadataProfile
|
||||
{
|
||||
PrimaryAlbumTypes = primTypes,
|
||||
SecondaryAlbumTypes = secTypes
|
||||
};
|
||||
|
||||
return profile.ToResource();
|
||||
}
|
||||
}
|
||||
}
|
75
src/Lidarr.Api.V1/Profiles/Metadata/MetadataValidator.cs
Normal file
75
src/Lidarr.Api.V1/Profiles/Metadata/MetadataValidator.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Validators;
|
||||
|
||||
namespace Lidarr.Api.V1.Profiles.Metadata
|
||||
{
|
||||
public static class MetadataValidation
|
||||
{
|
||||
public static IRuleBuilderOptions<T, IList<ProfilePrimaryAlbumTypeItemResource>> MustHaveAllowedPrimaryType<T>(this IRuleBuilder<T, IList<ProfilePrimaryAlbumTypeItemResource>> ruleBuilder)
|
||||
{
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
|
||||
return ruleBuilder.SetValidator(new PrimaryTypeValidator<T>());
|
||||
}
|
||||
|
||||
public static IRuleBuilderOptions<T, IList<ProfileSecondaryAlbumTypeItemResource>> MustHaveAllowedSecondaryType<T>(this IRuleBuilder<T, IList<ProfileSecondaryAlbumTypeItemResource>> ruleBuilder)
|
||||
{
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
|
||||
return ruleBuilder.SetValidator(new SecondaryTypeValidator<T>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class PrimaryTypeValidator<T> : PropertyValidator
|
||||
{
|
||||
public PrimaryTypeValidator()
|
||||
: base("Must have at least one allowed primary type")
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
var list = context.PropertyValue as IList<ProfilePrimaryAlbumTypeItemResource>;
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!list.Any(c => c.Allowed))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class SecondaryTypeValidator<T> : PropertyValidator
|
||||
{
|
||||
public SecondaryTypeValidator()
|
||||
: base("Must have at least one allowed secondary type")
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
var list = context.PropertyValue as IList<ProfileSecondaryAlbumTypeItemResource>;
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!list.Any(c => c.Allowed))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
|||
[TestCase("66c662b6-6e2f-4930-8610-912e24c63ed1", "AC/DC")]
|
||||
public void should_be_able_to_get_artist_detail(string mbId, string name)
|
||||
{
|
||||
var details = Subject.GetArtistInfo(mbId, new List<string> { "Album" }, new List<string> { "Studio" });
|
||||
var details = Subject.GetArtistInfo(mbId, 0);
|
||||
|
||||
ValidateArtist(details.Item1);
|
||||
ValidateAlbums(details.Item2);
|
||||
|
@ -37,13 +37,13 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
|||
[Test]
|
||||
public void getting_details_of_invalid_artist()
|
||||
{
|
||||
Assert.Throws<ArtistNotFoundException>(() => Subject.GetArtistInfo("aaaaaa-aaa-aaaa-aaaa", new List<string> { "Album" }, new List<string> { "Studio" }));
|
||||
Assert.Throws<ArtistNotFoundException>(() => Subject.GetArtistInfo("aaaaaa-aaa-aaaa-aaaa", 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_have_period_at_start_of_name_slug()
|
||||
{
|
||||
var details = Subject.GetArtistInfo("b6db95cd-88d9-492f-bbf6-a34e0e89b2e5", new List<string> { "Album" }, new List<string> { "Studio" });
|
||||
var details = Subject.GetArtistInfo("b6db95cd-88d9-492f-bbf6-a34e0e89b2e5", 0);
|
||||
|
||||
details.Item1.NameSlug.Should().Be("dothack");
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
private void GivenValidArtist(string lidarrId)
|
||||
{
|
||||
Mocker.GetMock<IProvideArtistInfo>()
|
||||
.Setup(s => s.GetArtistInfo(lidarrId, It.IsAny<List<string>>(), It.IsAny<List<string>>()))
|
||||
.Setup(s => s.GetArtistInfo(lidarrId, It.IsAny<int>()))
|
||||
.Returns(new Tuple<Artist, List<Album>>(_fakeArtist, new List<Album>()));
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
};
|
||||
|
||||
Mocker.GetMock<IProvideArtistInfo>()
|
||||
.Setup(s => s.GetArtistInfo(newArtist.ForeignArtistId, newArtist.PrimaryAlbumTypes, newArtist.SecondaryAlbumTypes))
|
||||
.Setup(s => s.GetArtistInfo(newArtist.ForeignArtistId, newArtist.MetadataProfileId))
|
||||
.Throws(new ArtistNotFoundException(newArtist.ForeignArtistId));
|
||||
|
||||
Mocker.GetMock<IAddArtistValidator>()
|
||||
|
|
|
@ -38,14 +38,14 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
.Returns(_artist);
|
||||
|
||||
Mocker.GetMock<IProvideArtistInfo>()
|
||||
.Setup(s => s.GetArtistInfo(It.IsAny<string>(), It.IsAny<List<string>>(), It.IsAny<List<string>>()))
|
||||
.Setup(s => s.GetArtistInfo(It.IsAny<string>(), It.IsAny<int>()))
|
||||
.Callback(() => { throw new ArtistNotFoundException(_artist.ForeignArtistId); });
|
||||
}
|
||||
|
||||
private void GivenNewArtistInfo(Artist artist)
|
||||
{
|
||||
Mocker.GetMock<IProvideArtistInfo>()
|
||||
.Setup(s => s.GetArtistInfo(_artist.ForeignArtistId, _artist.PrimaryAlbumTypes, _artist.SecondaryAlbumTypes))
|
||||
.Setup(s => s.GetArtistInfo(_artist.ForeignArtistId, _artist.MetadataProfileId))
|
||||
.Returns(new Tuple<Artist, List<Album>>(artist, new List<Album>()));
|
||||
}
|
||||
|
||||
|
|
|
@ -280,6 +280,8 @@
|
|||
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheFixture.cs" />
|
||||
<Compile Include="ParserTests\MusicParserFixture.cs" />
|
||||
<Compile Include="Profiles\Delay\DelayProfileServiceFixture.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfileServiceFixture.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfileRepositoryFixture.cs" />
|
||||
<Compile Include="Profiles\Qualities\QualityIndexCompareToFixture.cs" />
|
||||
<Compile Include="Qualities\RevisionComparableFixture.cs" />
|
||||
<Compile Include="QueueTests\QueueServiceFixture.cs" />
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
using FluentAssertions;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
|
||||
namespace NzbDrone.Core.Test.Profiles.Metadata
|
||||
{
|
||||
[TestFixture]
|
||||
public class MetadataProfileRepositoryFixture : DbTest<MetadataProfileRepository, MetadataProfile>
|
||||
{
|
||||
[Test]
|
||||
public void should_be_able_to_read_and_write()
|
||||
{
|
||||
var profile = new MetadataProfile
|
||||
{
|
||||
PrimaryAlbumTypes = PrimaryAlbumType.All.OrderByDescending(l => l.Name).Select(l => new ProfilePrimaryAlbumTypeItem
|
||||
{
|
||||
PrimaryAlbumType = l,
|
||||
Allowed = l == PrimaryAlbumType.Album
|
||||
}).ToList(),
|
||||
|
||||
SecondaryAlbumTypes = SecondaryAlbumType.All.OrderByDescending(l => l.Name).Select(l => new ProfileSecondaryAlbumTypeItem
|
||||
{
|
||||
SecondaryAlbumType = l,
|
||||
Allowed = l == SecondaryAlbumType.Studio
|
||||
}).ToList(),
|
||||
|
||||
Name = "TestProfile"
|
||||
};
|
||||
|
||||
Subject.Insert(profile);
|
||||
|
||||
|
||||
StoredModel.Name.Should().Be(profile.Name);
|
||||
|
||||
StoredModel.PrimaryAlbumTypes.Should().Equal(profile.PrimaryAlbumTypes, (a, b) => a.PrimaryAlbumType == b.PrimaryAlbumType && a.Allowed == b.Allowed);
|
||||
StoredModel.SecondaryAlbumTypes.Should().Equal(profile.SecondaryAlbumTypes, (a, b) => a.SecondaryAlbumType == b.SecondaryAlbumType && a.Allowed == b.Allowed);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
|
||||
namespace NzbDrone.Core.Test.Profiles.Metadata
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class MetadataProfileServiceFixture : CoreTest<MetadataProfileService>
|
||||
{
|
||||
[Test]
|
||||
public void init_should_add_default_profiles()
|
||||
{
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
//This confirms that new profiles are added only if no other profiles exists.
|
||||
//We don't want to keep adding them back if a user deleted them on purpose.
|
||||
public void Init_should_skip_if_any_profiles_already_exist()
|
||||
{
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(Builder<MetadataProfile>.CreateListOfSize(2).Build().ToList());
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Never());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_not_be_able_to_delete_profile_if_assigned_to_artist()
|
||||
{
|
||||
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||
.Random(1)
|
||||
.With(c => c.MetadataProfileId = 2)
|
||||
.Build().ToList();
|
||||
|
||||
|
||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||
|
||||
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(2));
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>().Verify(c => c.Delete(It.IsAny<int>()), Times.Never());
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_delete_profile_if_not_assigned_to_series()
|
||||
{
|
||||
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||
.All()
|
||||
.With(c => c.MetadataProfileId = 2)
|
||||
.Build().ToList();
|
||||
|
||||
|
||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||
|
||||
Subject.Delete(1);
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>().Verify(c => c.Delete(1), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
using Marr.Data.Converters;
|
||||
using Marr.Data.Mapping;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Music;
|
||||
using System;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Converters
|
||||
{
|
||||
public class PrimaryAlbumTypeIntConverter : JsonConverter, IConverter
|
||||
{
|
||||
public object FromDB(ConverterContext context)
|
||||
{
|
||||
if (context.DbValue == DBNull.Value)
|
||||
{
|
||||
return PrimaryAlbumType.Album;
|
||||
}
|
||||
|
||||
var val = Convert.ToInt32(context.DbValue);
|
||||
|
||||
return (PrimaryAlbumType) val;
|
||||
}
|
||||
|
||||
public object FromDB(ColumnMap map, object dbValue)
|
||||
{
|
||||
return FromDB(new ConverterContext {ColumnMap = map, DbValue = dbValue});
|
||||
}
|
||||
|
||||
public object ToDB(object clrValue)
|
||||
{
|
||||
if (clrValue == DBNull.Value)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (clrValue as PrimaryAlbumType == null)
|
||||
{
|
||||
throw new InvalidOperationException("Attempted to save a albumtype that isn't really a albumtype");
|
||||
}
|
||||
|
||||
var language = (PrimaryAlbumType) clrValue;
|
||||
return (int) language;
|
||||
}
|
||||
|
||||
public Type DbType => typeof(int);
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(PrimaryAlbumType);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
var item = reader.Value;
|
||||
return (PrimaryAlbumType) Convert.ToInt32(item);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(ToDB(value));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using Marr.Data.Converters;
|
||||
using Marr.Data.Mapping;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Converters
|
||||
{
|
||||
public class SecondaryAlbumTypeIntConverter : JsonConverter, IConverter
|
||||
{
|
||||
public object FromDB(ConverterContext context)
|
||||
{
|
||||
if (context.DbValue == DBNull.Value)
|
||||
{
|
||||
return SecondaryAlbumType.Studio;
|
||||
}
|
||||
|
||||
var val = Convert.ToInt32(context.DbValue);
|
||||
|
||||
return (SecondaryAlbumType) val;
|
||||
}
|
||||
|
||||
public object FromDB(ColumnMap map, object dbValue)
|
||||
{
|
||||
return FromDB(new ConverterContext {ColumnMap = map, DbValue = dbValue});
|
||||
}
|
||||
|
||||
public object ToDB(object clrValue)
|
||||
{
|
||||
if (clrValue == DBNull.Value)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (clrValue as SecondaryAlbumType == null)
|
||||
{
|
||||
throw new InvalidOperationException("Attempted to save a albumtype that isn't really a albumtype");
|
||||
}
|
||||
|
||||
var language = (SecondaryAlbumType) clrValue;
|
||||
return (int) language;
|
||||
}
|
||||
|
||||
public Type DbType => typeof(int);
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(SecondaryAlbumType);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
var item = reader.Value;
|
||||
return (SecondaryAlbumType) Convert.ToInt32(item);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(ToDB(value));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(5)]
|
||||
public class metadata_profiles : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Create.TableForModel("MetadataProfiles")
|
||||
.WithColumn("Name").AsString().Unique()
|
||||
.WithColumn("PrimaryAlbumTypes").AsString()
|
||||
.WithColumn("SecondaryAlbumTypes").AsString();
|
||||
|
||||
Alter.Table("Artists").AddColumn("MetadataProfileId").AsInt32().WithDefaultValue(1);
|
||||
|
||||
Delete.Column("PrimaryAlbumTypes").FromTable("Artists");
|
||||
Delete.Column("SecondaryAlbumTypes").FromTable("Artists");
|
||||
|
||||
Alter.Table("Albums").AddColumn("SecondaryTypes").AsString().Nullable();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ using NzbDrone.Core.RemotePathMappings;
|
|||
using NzbDrone.Core.Notifications;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Restrictions;
|
||||
|
@ -26,6 +28,7 @@ using NzbDrone.Core.ArtistStats;
|
|||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Authentication;
|
||||
using NzbDrone.Core.Extras.Metadata;
|
||||
using NzbDrone.Core.Extras.Metadata.Files;
|
||||
|
@ -34,7 +37,6 @@ using NzbDrone.Core.Extras.Lyrics;
|
|||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
|
@ -71,13 +73,14 @@ namespace NzbDrone.Core.Datastore
|
|||
.Ignore(d => d.Tags);
|
||||
|
||||
Mapper.Entity<History.History>().RegisterModel("History")
|
||||
.AutoMapChildModels();
|
||||
.AutoMapChildModels();
|
||||
|
||||
Mapper.Entity<Artist>().RegisterModel("Artists")
|
||||
.Ignore(s => s.RootFolderPath)
|
||||
.Relationship()
|
||||
.HasOne(a => a.Profile, a => a.ProfileId)
|
||||
.HasOne(s => s.LanguageProfile, s => s.LanguageProfileId);
|
||||
.Ignore(s => s.RootFolderPath)
|
||||
.Relationship()
|
||||
.HasOne(a => a.Profile, a => a.ProfileId)
|
||||
.HasOne(s => s.LanguageProfile, s => s.LanguageProfileId)
|
||||
.HasOne(s => s.MetadataProfile, s => s.MetadataProfileId);
|
||||
|
||||
Mapper.Entity<Album>().RegisterModel("Albums");
|
||||
|
||||
|
@ -104,6 +107,7 @@ namespace NzbDrone.Core.Datastore
|
|||
|
||||
Mapper.Entity<Profile>().RegisterModel("Profiles");
|
||||
Mapper.Entity<LanguageProfile>().RegisterModel("LanguageProfiles");
|
||||
Mapper.Entity<MetadataProfile>().RegisterModel("MetadataProfiles");
|
||||
Mapper.Entity<Log>().RegisterModel("Logs");
|
||||
Mapper.Entity<NamingConfig>().RegisterModel("NamingConfig");
|
||||
Mapper.Entity<AlbumStatistics>().MapResultSet();
|
||||
|
@ -146,6 +150,8 @@ namespace NzbDrone.Core.Datastore
|
|||
MapRepository.Instance.RegisterTypeConverter(typeof(Language), new LanguageIntConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(List<string>), new EmbeddedDocumentConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfileLanguageItem>), new EmbeddedDocumentConverter(new LanguageIntConverter()));
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfilePrimaryAlbumTypeItem>), new EmbeddedDocumentConverter(new PrimaryAlbumTypeIntConverter()));
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfileSecondaryAlbumTypeItem>), new EmbeddedDocumentConverter(new SecondaryAlbumTypeIntConverter()));
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(ParsedAlbumInfo), new EmbeddedDocumentConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(ParsedTrackInfo), new EmbeddedDocumentConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(ReleaseInfo), new EmbeddedDocumentConverter());
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using NzbDrone.Core.Music;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public interface IProvideArtistInfo
|
||||
{
|
||||
Tuple<Artist, List<Album>> GetArtistInfo(string lidarrId, List<string> primaryAlbumTypes, List<string> secondaryAlbumTypes);
|
||||
Tuple<Artist, List<Album>> GetArtistInfo(string lidarrId, int metadataProfileId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
|||
public List<string> Genres { get; set; }
|
||||
public List<string> Labels { get; set; }
|
||||
public string Type { get; set; }
|
||||
public List<string> SecondaryTypes { get; set; }
|
||||
public List<MediumResource> Media { get; set; }
|
||||
public List<TrackResource> Tracks { get; set; }
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ using NzbDrone.Core.Music;
|
|||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
|
@ -25,39 +26,36 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
private readonly IArtistService _artistService;
|
||||
private readonly IHttpRequestBuilderFactory _requestBuilder;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IMetadataProfileService _metadataProfileService;
|
||||
|
||||
private IHttpRequestBuilderFactory customerRequestBuilder;
|
||||
|
||||
public SkyHookProxy(IHttpClient httpClient, ILidarrCloudRequestBuilder requestBuilder, IArtistService artistService, Logger logger, IConfigService configService)
|
||||
public SkyHookProxy(IHttpClient httpClient, ILidarrCloudRequestBuilder requestBuilder, IArtistService artistService, Logger logger, IConfigService configService, IMetadataProfileService metadataProfileService)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_configService = configService;
|
||||
_metadataProfileService = metadataProfileService;
|
||||
_requestBuilder = requestBuilder.Search;
|
||||
_artistService = artistService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Tuple<Artist, List<Album>> GetArtistInfo(string foreignArtistId, List<string> primaryAlbumTypes, List<string> secondaryAlbumTypes)
|
||||
public Tuple<Artist, List<Album>> GetArtistInfo(string foreignArtistId, int metadataProfileId)
|
||||
{
|
||||
|
||||
_logger.Debug("Getting Artist with LidarrAPI.MetadataID of {0}", foreignArtistId);
|
||||
|
||||
SetCustomProvider();
|
||||
|
||||
if (primaryAlbumTypes == null)
|
||||
{
|
||||
primaryAlbumTypes = new List<string>();
|
||||
}
|
||||
var metadataProfile = _metadataProfileService.Get(metadataProfileId);
|
||||
|
||||
if (secondaryAlbumTypes == null)
|
||||
{
|
||||
secondaryAlbumTypes = new List<string>();
|
||||
}
|
||||
var primaryTypes = metadataProfile.PrimaryAlbumTypes.Where(s => s.Allowed).Select(s => s.PrimaryAlbumType.Name);
|
||||
var secondaryTypes = metadataProfile.SecondaryAlbumTypes.Where(s => s.Allowed).Select(s => s.SecondaryAlbumType.Name);
|
||||
|
||||
var httpRequest = customerRequestBuilder.Create()
|
||||
.SetSegment("route", "artists/" + foreignArtistId)
|
||||
.AddQueryParam("primTypes", string.Join("|",primaryAlbumTypes))
|
||||
.AddQueryParam("secTypes", string.Join("|", secondaryAlbumTypes))
|
||||
.AddQueryParam("primTypes", string.Join("|", primaryTypes))
|
||||
.AddQueryParam("secTypes", string.Join("|", secondaryTypes))
|
||||
.Build();
|
||||
|
||||
httpRequest.AllowAutoRedirect = true;
|
||||
|
@ -102,7 +100,8 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
|
||||
try
|
||||
{
|
||||
return new List<Artist> { GetArtistInfo(slug, new List<string>{"Album"}, new List<string>{"Studio"}).Item1 };
|
||||
var metadataProfile = _metadataProfileService.All().First().Id; //Change this to Use last Used profile?
|
||||
return new List<Artist> { GetArtistInfo(slug, metadataProfile).Item1 };
|
||||
}
|
||||
catch (ArtistNotFoundException)
|
||||
{
|
||||
|
@ -160,6 +159,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
|
||||
album.Media = resource.Media.Select(MapMedium).ToList();
|
||||
album.Tracks = resource.Tracks.Select(MapTrack).ToList();
|
||||
album.SecondaryTypes = resource.SecondaryTypes.Select(MapSecondaryTypes).ToList();
|
||||
|
||||
|
||||
return album;
|
||||
|
@ -297,6 +297,35 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
}
|
||||
}
|
||||
|
||||
private static SecondaryAlbumType MapSecondaryTypes(string albumType)
|
||||
{
|
||||
switch (albumType.ToLowerInvariant())
|
||||
{
|
||||
case "compilation":
|
||||
return SecondaryAlbumType.Compilation;
|
||||
case "soundtrack":
|
||||
return SecondaryAlbumType.Soundtrack;
|
||||
case "spokenword":
|
||||
return SecondaryAlbumType.Spokenword;
|
||||
case "interview":
|
||||
return SecondaryAlbumType.Interview;
|
||||
case "audiobook":
|
||||
return SecondaryAlbumType.Audiobook;
|
||||
case "live":
|
||||
return SecondaryAlbumType.Live;
|
||||
case "remix":
|
||||
return SecondaryAlbumType.Remix;
|
||||
case "dj-mix":
|
||||
return SecondaryAlbumType.DJMix;
|
||||
case "mixtape/street":
|
||||
return SecondaryAlbumType.Mixtape;
|
||||
case "demo":
|
||||
return SecondaryAlbumType.Demo;
|
||||
default:
|
||||
return SecondaryAlbumType.Studio;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCustomProvider()
|
||||
{
|
||||
if (_configService.MetadataSource.IsNotNullOrWhiteSpace())
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
try
|
||||
{
|
||||
tuple = _artistInfo.GetArtistInfo(newArtist.ForeignArtistId, newArtist.PrimaryAlbumTypes, newArtist.SecondaryAlbumTypes);
|
||||
tuple = _artistInfo.GetArtistInfo(newArtist.ForeignArtistId, newArtist.MetadataProfileId);
|
||||
}
|
||||
catch (ArtistNotFoundException)
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace NzbDrone.Core.Music
|
|||
public DateTime? LastDiskSync { get; set; }
|
||||
public DateTime Added { get; set; }
|
||||
public String AlbumType { get; set; }
|
||||
public List<SecondaryAlbumType> SecondaryTypes { get; set; }
|
||||
//public string ArtworkUrl { get; set; }
|
||||
//public string Explicitness { get; set; }
|
||||
public AddArtistOptions AddOptions { get; set; }
|
||||
|
|
|
@ -3,6 +3,7 @@ using NzbDrone.Common.Extensions;
|
|||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Profiles.Languages;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Music;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -36,8 +37,6 @@ namespace NzbDrone.Core.Music
|
|||
public string Overview { get; set; }
|
||||
public string Disambiguation { get; set; }
|
||||
public string ArtistType { get; set; }
|
||||
public List<string> PrimaryAlbumTypes { get; set; }
|
||||
public List<string> SecondaryAlbumTypes { get; set; }
|
||||
public bool Monitored { get; set; }
|
||||
public bool AlbumFolder { get; set; }
|
||||
public DateTime? LastInfoSync { get; set; }
|
||||
|
@ -51,8 +50,10 @@ namespace NzbDrone.Core.Music
|
|||
public DateTime Added { get; set; }
|
||||
public LazyLoaded<Profile> Profile { get; set; }
|
||||
public LazyLoaded<LanguageProfile> LanguageProfile { get; set; }
|
||||
public LazyLoaded<MetadataProfile> MetadataProfile { get; set; }
|
||||
public int ProfileId { get; set; }
|
||||
public int LanguageProfileId { get; set; }
|
||||
public int MetadataProfileId { get; set; }
|
||||
public List<Album> Albums { get; set; }
|
||||
public HashSet<int> Tags { get; set; }
|
||||
public AddArtistOptions AddOptions { get; set; }
|
||||
|
@ -73,10 +74,9 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
Profile = otherArtist.Profile;
|
||||
LanguageProfileId = otherArtist.LanguageProfileId;
|
||||
MetadataProfileId = otherArtist.MetadataProfileId;
|
||||
|
||||
Albums = otherArtist.Albums;
|
||||
PrimaryAlbumTypes = otherArtist.PrimaryAlbumTypes;
|
||||
SecondaryAlbumTypes = otherArtist.SecondaryAlbumTypes;
|
||||
|
||||
ProfileId = otherArtist.ProfileId;
|
||||
Tags = otherArtist.Tags;
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace NzbDrone.Core.Music
|
|||
public void Handle(ArtistEditedEvent message)
|
||||
{
|
||||
// Refresh Artist is we change AlbumType Preferences
|
||||
if (message.Artist.PrimaryAlbumTypes != message.OldArtist.PrimaryAlbumTypes || message.Artist.SecondaryAlbumTypes != message.OldArtist.SecondaryAlbumTypes)
|
||||
if (message.Artist.LanguageProfileId != message.OldArtist.LanguageProfileId)
|
||||
{
|
||||
_commandQueueManager.Push(new RefreshArtistCommand(message.Artist.Id));
|
||||
}
|
||||
|
|
121
src/NzbDrone.Core/Music/PrimaryAlbumType.cs
Normal file
121
src/NzbDrone.Core/Music/PrimaryAlbumType.cs
Normal file
|
@ -0,0 +1,121 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class PrimaryAlbumType : IEmbeddedDocument, IEquatable<PrimaryAlbumType>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public PrimaryAlbumType()
|
||||
{
|
||||
}
|
||||
|
||||
private PrimaryAlbumType(int id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(PrimaryAlbumType other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return Id.Equals(other.Id);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ReferenceEquals(this, obj) || Equals(obj as PrimaryAlbumType);
|
||||
}
|
||||
|
||||
public static bool operator ==(PrimaryAlbumType left, PrimaryAlbumType right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(PrimaryAlbumType left, PrimaryAlbumType right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
|
||||
public static PrimaryAlbumType Album => new PrimaryAlbumType(0, "Album");
|
||||
public static PrimaryAlbumType EP => new PrimaryAlbumType(1, "EP");
|
||||
public static PrimaryAlbumType Single => new PrimaryAlbumType(2, "Single");
|
||||
public static PrimaryAlbumType Broadcast => new PrimaryAlbumType(3, "Broadcast");
|
||||
public static PrimaryAlbumType Other => new PrimaryAlbumType(4, "Other");
|
||||
|
||||
|
||||
public static readonly List<PrimaryAlbumType> All = new List<PrimaryAlbumType>
|
||||
{
|
||||
Album,
|
||||
EP,
|
||||
Single,
|
||||
Broadcast,
|
||||
Other
|
||||
};
|
||||
|
||||
|
||||
public static PrimaryAlbumType FindById(int id)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
return Album;
|
||||
}
|
||||
|
||||
PrimaryAlbumType albumType = All.FirstOrDefault(v => v.Id == id);
|
||||
|
||||
if (albumType == null)
|
||||
{
|
||||
throw new ArgumentException(@"ID does not match a known album type", nameof(id));
|
||||
}
|
||||
|
||||
return albumType;
|
||||
}
|
||||
|
||||
public static explicit operator PrimaryAlbumType(int id)
|
||||
{
|
||||
return FindById(id);
|
||||
}
|
||||
|
||||
public static explicit operator int(PrimaryAlbumType albumType)
|
||||
{
|
||||
return albumType.Id;
|
||||
}
|
||||
|
||||
public static explicit operator PrimaryAlbumType(string type)
|
||||
{
|
||||
var albumType = All.FirstOrDefault(v => v.Name.Equals(type, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (albumType == null)
|
||||
{
|
||||
throw new ArgumentException(@"Type does not match a known album type", nameof(type));
|
||||
}
|
||||
|
||||
return albumType;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,7 +39,6 @@ namespace NzbDrone.Core.Music
|
|||
var failCount = 0;
|
||||
|
||||
var existingAlbums = _albumService.GetAlbumsByArtist(artist.Id);
|
||||
var albums = artist.Albums;
|
||||
|
||||
var updateList = new List<Album>();
|
||||
var newList = new List<Album>();
|
||||
|
@ -79,6 +78,7 @@ namespace NzbDrone.Core.Music
|
|||
albumToUpdate.CleanTitle = Parser.Parser.CleanArtistName(albumToUpdate.Title);
|
||||
albumToUpdate.ArtistId = artist.Id;
|
||||
albumToUpdate.AlbumType = album.AlbumType;
|
||||
albumToUpdate.SecondaryTypes = album.SecondaryTypes;
|
||||
albumToUpdate.Genres = album.Genres;
|
||||
albumToUpdate.Media = album.Media;
|
||||
albumToUpdate.Label = album.Label;
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
try
|
||||
{
|
||||
tuple = _artistInfo.GetArtistInfo(artist.ForeignArtistId, artist.PrimaryAlbumTypes, artist.SecondaryAlbumTypes);
|
||||
tuple = _artistInfo.GetArtistInfo(artist.ForeignArtistId, artist.MetadataProfileId);
|
||||
}
|
||||
catch (ArtistNotFoundException)
|
||||
{
|
||||
|
|
131
src/NzbDrone.Core/Music/SecondaryAlbumType.cs
Normal file
131
src/NzbDrone.Core/Music/SecondaryAlbumType.cs
Normal file
|
@ -0,0 +1,131 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class SecondaryAlbumType : IEmbeddedDocument, IEquatable<SecondaryAlbumType>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public SecondaryAlbumType()
|
||||
{
|
||||
}
|
||||
|
||||
private SecondaryAlbumType(int id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(SecondaryAlbumType other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return Id.Equals(other.Id);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ReferenceEquals(this, obj) || Equals(obj as SecondaryAlbumType);
|
||||
}
|
||||
|
||||
public static bool operator ==(SecondaryAlbumType left, SecondaryAlbumType right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(SecondaryAlbumType left, SecondaryAlbumType right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
|
||||
public static SecondaryAlbumType Studio => new SecondaryAlbumType(0, "Studio");
|
||||
public static SecondaryAlbumType Compilation => new SecondaryAlbumType(1, "Compilation");
|
||||
public static SecondaryAlbumType Soundtrack => new SecondaryAlbumType(2, "Soundtrack");
|
||||
public static SecondaryAlbumType Spokenword => new SecondaryAlbumType(3, "Spokenword");
|
||||
public static SecondaryAlbumType Interview => new SecondaryAlbumType(4, "Interview");
|
||||
public static SecondaryAlbumType Audiobook => new SecondaryAlbumType(5, "Audiobook");
|
||||
public static SecondaryAlbumType Live => new SecondaryAlbumType(6, "Live");
|
||||
public static SecondaryAlbumType Remix => new SecondaryAlbumType(7, "Remix");
|
||||
public static SecondaryAlbumType DJMix => new SecondaryAlbumType(8, "DJ-Mix");
|
||||
public static SecondaryAlbumType Mixtape => new SecondaryAlbumType(9, "Mixtape/Street");
|
||||
public static SecondaryAlbumType Demo => new SecondaryAlbumType(10, "Demo");
|
||||
|
||||
|
||||
public static readonly List<SecondaryAlbumType> All = new List<SecondaryAlbumType>
|
||||
{
|
||||
Studio,
|
||||
Compilation,
|
||||
Soundtrack,
|
||||
Spokenword,
|
||||
Interview,
|
||||
Live,
|
||||
Remix,
|
||||
DJMix,
|
||||
Mixtape
|
||||
};
|
||||
|
||||
|
||||
public static SecondaryAlbumType FindById(int id)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
return Studio;
|
||||
}
|
||||
|
||||
SecondaryAlbumType albumType = All.FirstOrDefault(v => v.Id == id);
|
||||
|
||||
if (albumType == null)
|
||||
{
|
||||
throw new ArgumentException(@"ID does not match a known album type", nameof(id));
|
||||
}
|
||||
|
||||
return albumType;
|
||||
}
|
||||
|
||||
public static explicit operator SecondaryAlbumType(int id)
|
||||
{
|
||||
return FindById(id);
|
||||
}
|
||||
|
||||
public static explicit operator int(SecondaryAlbumType albumType)
|
||||
{
|
||||
return albumType.Id;
|
||||
}
|
||||
|
||||
public static explicit operator SecondaryAlbumType(string type)
|
||||
{
|
||||
var albumType = All.FirstOrDefault(v => v.Name.Equals(type, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (albumType == null)
|
||||
{
|
||||
throw new ArgumentException(@"Type does not match a known album type", nameof(type));
|
||||
}
|
||||
|
||||
return albumType;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -150,6 +150,8 @@
|
|||
<Compile Include="Datastore\Converters\DoubleConverter.cs" />
|
||||
<Compile Include="Datastore\Converters\EmbeddedDocumentConverter.cs" />
|
||||
<Compile Include="Datastore\Converters\EnumIntConverter.cs" />
|
||||
<Compile Include="Datastore\Converters\SecondaryAlbumTypeIntConverter.cs" />
|
||||
<Compile Include="Datastore\Converters\PrimaryAlbumTypeIntConverter.cs" />
|
||||
<Compile Include="Datastore\Converters\LanguageIntConverter.cs" />
|
||||
<Compile Include="Datastore\Converters\TimeSpanConverter.cs" />
|
||||
<Compile Include="Datastore\Converters\Int32Converter.cs" />
|
||||
|
@ -172,6 +174,7 @@
|
|||
<Compile Include="Datastore\LogDatabase.cs" />
|
||||
<Compile Include="Datastore\Migration\001_initial_setup.cs" />
|
||||
<Compile Include="Datastore\Migration\002_add_reason_to_pending_releases.cs" />
|
||||
<Compile Include="Datastore\Migration\005_metadata_profiles.cs" />
|
||||
<Compile Include="Datastore\Migration\004_add_various_qualities_in_profile.cs" />
|
||||
<Compile Include="Datastore\Migration\003_add_medium_support.cs" />
|
||||
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
|
||||
|
@ -745,6 +748,8 @@
|
|||
<Compile Include="Extras\Metadata\MetadataType.cs" />
|
||||
<Compile Include="Music\ArtistStatusType.cs" />
|
||||
<Compile Include="Music\AlbumCutoffService.cs" />
|
||||
<Compile Include="Music\SecondaryAlbumType.cs" />
|
||||
<Compile Include="Music\PrimaryAlbumType.cs" />
|
||||
<Compile Include="Music\Links.cs" />
|
||||
<Compile Include="Music\Commands\MoveArtistCommand.cs" />
|
||||
<Compile Include="Music\Events\ArtistMovedEvent.cs" />
|
||||
|
@ -863,6 +868,12 @@
|
|||
<Compile Include="Profiles\Languages\LanguageProfileRepository.cs" />
|
||||
<Compile Include="Profiles\Languages\LanguageProfileService.cs" />
|
||||
<Compile Include="Profiles\Languages\ProfileLanguageItem.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfileService.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfileInUseException.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfile.cs" />
|
||||
<Compile Include="Profiles\Metadata\MetadataProfileRepository.cs" />
|
||||
<Compile Include="Profiles\Metadata\ProfileSecondaryAlbumTypeItem.cs" />
|
||||
<Compile Include="Profiles\Metadata\ProfilePrimaryAlbumTypeItem.cs" />
|
||||
<Compile Include="Profiles\Quality\ProfileRepository.cs" />
|
||||
<Compile Include="Profiles\Quality\QualityIndex.cs" />
|
||||
<Compile Include="ProgressMessaging\ProgressMessageContext.cs" />
|
||||
|
|
14
src/NzbDrone.Core/Profiles/Metadata/MetadataProfile.cs
Normal file
14
src/NzbDrone.Core/Profiles/Metadata/MetadataProfile.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Indexers;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfile : ModelBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<ProfilePrimaryAlbumTypeItem> PrimaryAlbumTypes { get; set; }
|
||||
public List<ProfileSecondaryAlbumTypeItem> SecondaryAlbumTypes { get; set; }
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using NzbDrone.Common.Exceptions;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public class MetadataProfileInUseException : NzbDroneException
|
||||
{
|
||||
public MetadataProfileInUseException(int profileId)
|
||||
: base("Metadata profile [{0}] is in use.", profileId)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public interface IMetadataProfileRepository : IBasicRepository<MetadataProfile>
|
||||
{
|
||||
bool Exists(int id);
|
||||
}
|
||||
|
||||
public class MetadataProfileRepository : BasicRepository<MetadataProfile>, IMetadataProfileRepository
|
||||
{
|
||||
public MetadataProfileRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||
: base(database, eventAggregator)
|
||||
{
|
||||
}
|
||||
|
||||
public bool Exists(int id)
|
||||
{
|
||||
return DataMapper.Query<MetadataProfile>().Where(p => p.Id == id).GetRowCount() == 1;
|
||||
}
|
||||
}
|
||||
}
|
102
src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs
Normal file
102
src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public interface IMetadataProfileService
|
||||
{
|
||||
MetadataProfile Add(MetadataProfile profile);
|
||||
void Update(MetadataProfile profile);
|
||||
void Delete(int id);
|
||||
List<MetadataProfile> All();
|
||||
MetadataProfile Get(int id);
|
||||
bool Exists(int id);
|
||||
}
|
||||
|
||||
public class MetadataProfileService : IMetadataProfileService, IHandle<ApplicationStartedEvent>
|
||||
{
|
||||
private readonly IMetadataProfileRepository _profileRepository;
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MetadataProfileService(IMetadataProfileRepository profileRepository, IArtistService artistService, Logger logger)
|
||||
{
|
||||
_profileRepository = profileRepository;
|
||||
_artistService = artistService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public MetadataProfile Add(MetadataProfile profile)
|
||||
{
|
||||
return _profileRepository.Insert(profile);
|
||||
}
|
||||
|
||||
public void Update(MetadataProfile profile)
|
||||
{
|
||||
_profileRepository.Update(profile);
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (_artistService.GetAllArtists().Any(c => c.MetadataProfileId == id))
|
||||
{
|
||||
throw new MetadataProfileInUseException(id);
|
||||
}
|
||||
|
||||
_profileRepository.Delete(id);
|
||||
}
|
||||
|
||||
public List<MetadataProfile> All()
|
||||
{
|
||||
return _profileRepository.All().ToList();
|
||||
}
|
||||
|
||||
public MetadataProfile Get(int id)
|
||||
{
|
||||
return _profileRepository.Get(id);
|
||||
}
|
||||
|
||||
public bool Exists(int id)
|
||||
{
|
||||
return _profileRepository.Exists(id);
|
||||
}
|
||||
|
||||
private void AddDefaultProfile(string name, List<PrimaryAlbumType> primAllowed, List<SecondaryAlbumType> secAllowed)
|
||||
{
|
||||
var primaryTypes = PrimaryAlbumType.All
|
||||
.OrderByDescending(l => l.Name)
|
||||
.Select(v => new ProfilePrimaryAlbumTypeItem { PrimaryAlbumType = v, Allowed = primAllowed.Contains(v) })
|
||||
.ToList();
|
||||
|
||||
var secondaryTypes = SecondaryAlbumType.All
|
||||
.OrderByDescending(l => l.Name)
|
||||
.Select(v => new ProfileSecondaryAlbumTypeItem { SecondaryAlbumType = v, Allowed = secAllowed.Contains(v) })
|
||||
.ToList();
|
||||
|
||||
var profile = new MetadataProfile
|
||||
{
|
||||
Name = name,
|
||||
PrimaryAlbumTypes = primaryTypes,
|
||||
SecondaryAlbumTypes = secondaryTypes
|
||||
};
|
||||
|
||||
Add(profile);
|
||||
}
|
||||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
if (All().Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Info("Setting up default metadata profile");
|
||||
|
||||
AddDefaultProfile("Standard", new List<PrimaryAlbumType>{PrimaryAlbumType.Album}, new List<SecondaryAlbumType>{ SecondaryAlbumType.Studio });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public class ProfilePrimaryAlbumTypeItem : IEmbeddedDocument
|
||||
{
|
||||
public PrimaryAlbumType PrimaryAlbumType { get; set; }
|
||||
public bool Allowed { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Music;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
public class ProfileSecondaryAlbumTypeItem : IEmbeddedDocument
|
||||
{
|
||||
public SecondaryAlbumType SecondaryAlbumType { get; set; }
|
||||
public bool Allowed { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue