mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
New: Add/remove individual albums
This commit is contained in:
parent
8da53ae6aa
commit
0bde5fd9e5
128 changed files with 2796 additions and 743 deletions
|
@ -14,31 +14,51 @@ using NzbDrone.Core.Music.Events;
|
|||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Validation.Paths;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace Lidarr.Api.V1.Albums
|
||||
{
|
||||
public class AlbumModule : AlbumModuleWithSignalR,
|
||||
IHandle<AlbumGrabbedEvent>,
|
||||
IHandle<AlbumEditedEvent>,
|
||||
IHandle<AlbumUpdatedEvent>,
|
||||
IHandle<AlbumImportedEvent>,
|
||||
IHandle<TrackImportedEvent>,
|
||||
IHandle<TrackFileDeletedEvent>
|
||||
|
||||
{
|
||||
protected readonly IReleaseService _releaseService;
|
||||
protected readonly IAddAlbumService _addAlbumService;
|
||||
|
||||
public AlbumModule(IAlbumService albumService,
|
||||
IAddAlbumService addAlbumService,
|
||||
IReleaseService releaseService,
|
||||
IArtistStatisticsService artistStatisticsService,
|
||||
IMapCoversToLocal coverMapper,
|
||||
IUpgradableSpecification upgradableSpecification,
|
||||
IBroadcastSignalRMessage signalRBroadcaster)
|
||||
IBroadcastSignalRMessage signalRBroadcaster,
|
||||
ProfileExistsValidator profileExistsValidator,
|
||||
MetadataProfileExistsValidator metadataProfileExistsValidator)
|
||||
|
||||
: base(albumService, artistStatisticsService, coverMapper, upgradableSpecification, signalRBroadcaster)
|
||||
{
|
||||
_releaseService = releaseService;
|
||||
_addAlbumService = addAlbumService;
|
||||
|
||||
GetResourceAll = GetAlbums;
|
||||
CreateResource = AddAlbum;
|
||||
UpdateResource = UpdateAlbum;
|
||||
DeleteResource = DeleteAlbum;
|
||||
Put("/monitor", x => SetAlbumsMonitored());
|
||||
|
||||
PostValidator.RuleFor(s => s.ForeignAlbumId).NotEmpty();
|
||||
PostValidator.RuleFor(s => s.Artist.QualityProfileId).SetValidator(profileExistsValidator);
|
||||
PostValidator.RuleFor(s => s.Artist.MetadataProfileId).SetValidator(metadataProfileExistsValidator);
|
||||
PostValidator.RuleFor(s => s.Artist.RootFolderPath).IsValidPath().When(s => s.Artist.Path.IsNullOrWhiteSpace());
|
||||
PostValidator.RuleFor(s => s.Artist.ForeignArtistId).NotEmpty();
|
||||
}
|
||||
|
||||
private List<AlbumResource> GetAlbums()
|
||||
|
@ -66,6 +86,11 @@ namespace Lidarr.Api.V1.Albums
|
|||
|
||||
var album = _albumService.FindById(foreignAlbumId);
|
||||
|
||||
if (album == null)
|
||||
{
|
||||
return MapToResource(new List<Album>(), false);
|
||||
}
|
||||
|
||||
if (includeAllArtistAlbumsQuery.HasValue && Convert.ToBoolean(includeAllArtistAlbumsQuery.Value))
|
||||
{
|
||||
return MapToResource(_albumService.GetAlbumsByArtist(album.ArtistId), false);
|
||||
|
@ -85,6 +110,13 @@ namespace Lidarr.Api.V1.Albums
|
|||
return MapToResource(_albumService.GetAlbums(albumIds), false);
|
||||
}
|
||||
|
||||
private int AddAlbum(AlbumResource albumResource)
|
||||
{
|
||||
var album = _addAlbumService.AddAlbum(albumResource.ToModel());
|
||||
|
||||
return album.Id;
|
||||
}
|
||||
|
||||
private void UpdateAlbum(AlbumResource albumResource)
|
||||
{
|
||||
var album = _albumService.GetAlbum(albumResource.Id);
|
||||
|
@ -97,6 +129,14 @@ namespace Lidarr.Api.V1.Albums
|
|||
BroadcastResourceChange(ModelAction.Updated, model.Id);
|
||||
}
|
||||
|
||||
private void DeleteAlbum(int id)
|
||||
{
|
||||
var deleteFiles = Request.GetBooleanQueryParameter("deleteFiles");
|
||||
var addImportListExclusion = Request.GetBooleanQueryParameter("addImportListExclusion");
|
||||
|
||||
_albumService.DeleteAlbum(id, deleteFiles, addImportListExclusion);
|
||||
}
|
||||
|
||||
private object SetAlbumsMonitored()
|
||||
{
|
||||
var resource = Request.Body.FromJson<AlbumsMonitoredResource>();
|
||||
|
@ -122,6 +162,16 @@ namespace Lidarr.Api.V1.Albums
|
|||
BroadcastResourceChange(ModelAction.Updated, MapToResource(message.Album, true));
|
||||
}
|
||||
|
||||
public void Handle(AlbumUpdatedEvent message)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Updated, MapToResource(message.Album, true));
|
||||
}
|
||||
|
||||
public void Handle(AlbumDeletedEvent message)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Deleted, message.Album.ToResource());
|
||||
}
|
||||
|
||||
public void Handle(AlbumImportedEvent message)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Updated, MapToResource(message.Album, true));
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace Lidarr.Api.V1.Albums
|
|||
public List<MediaCover> Images { get; set; }
|
||||
public List<Links> Links { get; set; }
|
||||
public AlbumStatisticsResource Statistics { get; set; }
|
||||
|
||||
public AddAlbumOptions AddOptions { get; set; }
|
||||
public string RemoteCover { get; set; }
|
||||
|
||||
//Hiding this so people don't think its usable (only used to set the initial state)
|
||||
|
@ -88,6 +88,8 @@ namespace Lidarr.Api.V1.Albums
|
|||
{
|
||||
if (resource == null) return null;
|
||||
|
||||
var artist = resource.Artist?.ToModel() ?? new NzbDrone.Core.Music.Artist();
|
||||
|
||||
return new Album
|
||||
{
|
||||
Id = resource.Id,
|
||||
|
@ -96,9 +98,13 @@ namespace Lidarr.Api.V1.Albums
|
|||
Disambiguation = resource.Disambiguation,
|
||||
Overview = resource.Overview,
|
||||
Images = resource.Images,
|
||||
AlbumType = resource.AlbumType,
|
||||
Monitored = resource.Monitored,
|
||||
AnyReleaseOk = resource.AnyReleaseOk,
|
||||
AlbumReleases = resource.Releases.ToModel()
|
||||
AlbumReleases = resource.Releases.ToModel(),
|
||||
AddOptions = resource.AddOptions,
|
||||
Artist = artist,
|
||||
ArtistMetadata = artist.Metadata.Value
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Lidarr.Api.V1.Profiles.Metadata
|
|||
public MetadataProfileModule(IMetadataProfileService profileService)
|
||||
{
|
||||
_profileService = profileService;
|
||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.Name).NotEqual("None").WithMessage("'None' is a reserved profile name").NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.PrimaryAlbumTypes).MustHaveAllowedPrimaryType();
|
||||
SharedValidator.RuleFor(c => c.SecondaryAlbumTypes).MustHaveAllowedSecondaryType();
|
||||
SharedValidator.RuleFor(c => c.ReleaseStatuses).MustHaveAllowedReleaseStatus();
|
||||
|
|
71
src/Lidarr.Api.V1/Search/SearchModule.cs
Normal file
71
src/Lidarr.Api.V1/Search/SearchModule.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using Lidarr.Http;
|
||||
using Lidarr.Api.V1.Artist;
|
||||
using Lidarr.Api.V1.Albums;
|
||||
using System;
|
||||
|
||||
namespace Lidarr.Api.V1.Search
|
||||
{
|
||||
public class SearchModule : LidarrRestModule<SearchResource>
|
||||
{
|
||||
private readonly ISearchForNewEntity _searchProxy;
|
||||
|
||||
public SearchModule(ISearchForNewEntity searchProxy)
|
||||
: base("/search")
|
||||
{
|
||||
_searchProxy = searchProxy;
|
||||
Get("/", x => Search());
|
||||
}
|
||||
|
||||
private object Search()
|
||||
{
|
||||
var searchResults = _searchProxy.SearchForNewEntity((string)Request.Query.term);
|
||||
return MapToResource(searchResults).ToList();
|
||||
}
|
||||
|
||||
private static IEnumerable<SearchResource> MapToResource(IEnumerable<Object> results)
|
||||
{
|
||||
int id = 1;
|
||||
foreach (var result in results)
|
||||
{
|
||||
var resource = new SearchResource();
|
||||
resource.Id = id++;
|
||||
|
||||
if (result is NzbDrone.Core.Music.Artist)
|
||||
{
|
||||
var artist = (NzbDrone.Core.Music.Artist) result;
|
||||
resource.Artist = artist.ToResource();
|
||||
resource.ForeignId = artist.ForeignArtistId;
|
||||
|
||||
var poster = artist.Metadata.Value.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster);
|
||||
if (poster != null)
|
||||
{
|
||||
resource.Artist.RemotePoster = poster.Url;
|
||||
}
|
||||
}
|
||||
else if (result is NzbDrone.Core.Music.Album)
|
||||
{
|
||||
var album = (NzbDrone.Core.Music.Album) result;
|
||||
resource.Album = album.ToResource();
|
||||
resource.ForeignId = album.ForeignAlbumId;
|
||||
|
||||
var cover = album.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Cover);
|
||||
if (cover != null)
|
||||
{
|
||||
resource.Album.RemoteCover = cover.Url;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException("Bad response from search all proxy");
|
||||
}
|
||||
|
||||
yield return resource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14
src/Lidarr.Api.V1/Search/SearchResource.cs
Normal file
14
src/Lidarr.Api.V1/Search/SearchResource.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using Lidarr.Http.REST;
|
||||
using Lidarr.Api.V1.Artist;
|
||||
using Lidarr.Api.V1.Albums;
|
||||
|
||||
namespace Lidarr.Api.V1.Search
|
||||
{
|
||||
public class
|
||||
SearchResource : RestResource
|
||||
{
|
||||
public string ForeignId { get; set; }
|
||||
public ArtistResource Artist { get; set; }
|
||||
public AlbumResource Album { get; set; }
|
||||
}
|
||||
}
|
|
@ -73,7 +73,7 @@ namespace NzbDrone.Automation.Test
|
|||
|
||||
page.WaitForNoSpinner();
|
||||
|
||||
page.Find(By.CssSelector("input[class*='AddNewArtist-searchInput']")).Should().NotBeNull();
|
||||
page.Find(By.CssSelector("input[class*='AddNewItem-searchInput']")).Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
|
|||
.Returns(default(RemoteAlbum));
|
||||
|
||||
// handle deletion event
|
||||
Subject.Handle(new AlbumDeletedEvent(remoteAlbum.Albums.First(), false));
|
||||
Subject.Handle(new AlbumDeletedEvent(remoteAlbum.Albums.First(), false, false));
|
||||
|
||||
// verify download has null remote album
|
||||
var trackedDownloads = Subject.GetTrackedDownloads();
|
||||
|
|
|
@ -72,6 +72,13 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
.Returns(new Artist{ForeignArtistId = _importListReports.First().ArtistMusicBrainzId });
|
||||
}
|
||||
|
||||
private void WithExistingAlbum()
|
||||
{
|
||||
Mocker.GetMock<IAlbumService>()
|
||||
.Setup(v => v.FindById(_importListReports.First().AlbumMusicBrainzId))
|
||||
.Returns(new Album{ForeignAlbumId = _importListReports.First().AlbumMusicBrainzId });
|
||||
}
|
||||
|
||||
private void WithExcludedArtist()
|
||||
{
|
||||
Mocker.GetMock<IImportListExclusionService>()
|
||||
|
@ -83,6 +90,17 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
});
|
||||
}
|
||||
|
||||
private void WithExcludedAlbum()
|
||||
{
|
||||
Mocker.GetMock<IImportListExclusionService>()
|
||||
.Setup(v => v.All())
|
||||
.Returns(new List<ImportListExclusion> {
|
||||
new ImportListExclusion {
|
||||
ForeignId = "09474d62-17dd-3a4f-98fb-04c65f38a479"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void WithMonitorType(ImportListMonitorType monitor)
|
||||
{
|
||||
Mocker.GetMock<IImportListFactory>()
|
||||
|
@ -120,17 +138,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_search_with_lidarr_id_if_album_id_and_no_artist_id()
|
||||
{
|
||||
WithAlbumId();
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<ISearchForNewAlbum>()
|
||||
.Verify(v => v.SearchForNewAlbum($"lidarr:{_importListReports.First().AlbumMusicBrainzId}", null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_search_if_album_id_and_artist_id()
|
||||
public void should_not_search_if_album_title_and_album_id()
|
||||
{
|
||||
WithArtistId();
|
||||
WithAlbumId();
|
||||
|
@ -159,8 +167,6 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
public void should_not_add_if_existing_artist()
|
||||
{
|
||||
WithArtistId();
|
||||
WithAlbum();
|
||||
WithAlbumId();
|
||||
WithExistingArtist();
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
@ -169,14 +175,37 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t=>t.Count == 0)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_add_if_existing_album()
|
||||
{
|
||||
WithAlbumId();
|
||||
WithExistingAlbum();
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddArtistService>()
|
||||
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t=>t.Count == 0)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_add_if_existing_artist_but_new_album()
|
||||
{
|
||||
WithAlbumId();
|
||||
WithExistingArtist();
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t=>t.Count == 1)));
|
||||
}
|
||||
|
||||
|
||||
[TestCase(ImportListMonitorType.None, false)]
|
||||
[TestCase(ImportListMonitorType.SpecificAlbum, true)]
|
||||
[TestCase(ImportListMonitorType.EntireArtist, true)]
|
||||
public void should_add_if_not_existing_artist(ImportListMonitorType monitor, bool expectedArtistMonitored)
|
||||
{
|
||||
WithArtistId();
|
||||
WithAlbum();
|
||||
WithAlbumId();
|
||||
WithMonitorType(monitor);
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
@ -185,12 +214,24 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 1 && t.First().Monitored == expectedArtistMonitored)));
|
||||
}
|
||||
|
||||
[TestCase(ImportListMonitorType.None, false)]
|
||||
[TestCase(ImportListMonitorType.SpecificAlbum, true)]
|
||||
[TestCase(ImportListMonitorType.EntireArtist, true)]
|
||||
public void should_add_if_not_existing_album(ImportListMonitorType monitor, bool expectedAlbumMonitored)
|
||||
{
|
||||
WithAlbumId();
|
||||
WithMonitorType(monitor);
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 1 && t.First().Monitored == expectedAlbumMonitored)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_add_if_excluded_artist()
|
||||
public void should_not_add_artist_if_excluded_artist()
|
||||
{
|
||||
WithArtistId();
|
||||
WithAlbum();
|
||||
WithAlbumId();
|
||||
WithExcludedArtist();
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
@ -200,42 +241,28 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_mark_album_for_monitor_if_album_id_and_specific_monitor_selected()
|
||||
public void should_not_add_album_if_excluded_album()
|
||||
{
|
||||
WithArtistId();
|
||||
WithAlbum();
|
||||
WithAlbumId();
|
||||
WithMonitorType(ImportListMonitorType.SpecificAlbum);
|
||||
WithExcludedAlbum();
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddArtistService>()
|
||||
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 1 && t.First().AddOptions.AlbumsToMonitor.Contains("09474d62-17dd-3a4f-98fb-04c65f38a479"))));
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_mark_album_for_monitor_if_album_id_and_monitor_all_selected()
|
||||
public void should_not_add_album_if_excluded_artist()
|
||||
{
|
||||
WithArtistId();
|
||||
WithAlbum();
|
||||
WithAlbumId();
|
||||
WithMonitorType(ImportListMonitorType.EntireArtist);
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddArtistService>()
|
||||
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 1 && !t.First().AddOptions.AlbumsToMonitor.Any())));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_mark_album_for_monitor_if_no_album_id()
|
||||
{
|
||||
WithArtistId();
|
||||
WithExcludedArtist();
|
||||
|
||||
Subject.Execute(new ImportListSyncCommand());
|
||||
|
||||
Mocker.GetMock<IAddArtistService>()
|
||||
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 1 && t.First().AddOptions.AlbumsToMonitor.Count == 0)));
|
||||
Mocker.GetMock<IAddAlbumService>()
|
||||
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ using NzbDrone.Core.MetadataSource.SkyHook.Resource;
|
|||
namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
{
|
||||
[TestFixture]
|
||||
[IntegrationTest]
|
||||
public class SkyHookProxyFixture : CoreTest<SkyHookProxy>
|
||||
{
|
||||
private MetadataProfile _metadataProfile;
|
||||
|
|
|
@ -3,16 +3,15 @@ using NUnit.Framework;
|
|||
using NzbDrone.Core.MetadataSource.SkyHook;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.Categories;
|
||||
using Moq;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using NzbDrone.Core.Music;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
||||
{
|
||||
[TestFixture]
|
||||
[IntegrationTest]
|
||||
public class SkyHookProxySearchFixture : CoreTest<SkyHookProxy>
|
||||
{
|
||||
[SetUp]
|
||||
|
@ -107,5 +106,28 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook
|
|||
|
||||
ExceptionVerification.IgnoreWarns();
|
||||
}
|
||||
|
||||
[TestCase("Eminem", 0, typeof(Artist), "Eminem")]
|
||||
[TestCase("Eminem Kamikaze", 0, typeof(Artist), "Eminem")]
|
||||
[TestCase("Eminem Kamikaze", 1, typeof(Album), "Kamikaze")]
|
||||
public void successful_combined_search(string query, int position, Type resultType, string expected)
|
||||
{
|
||||
var result = Subject.SearchForNewEntity(query);
|
||||
result.Should().NotBeEmpty();
|
||||
result[position].GetType().Should().Be(resultType);
|
||||
|
||||
if (resultType == typeof(Artist))
|
||||
{
|
||||
var cast = result[position] as Artist;
|
||||
cast.Should().NotBeNull();
|
||||
cast.Name.Should().Be(expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cast = result[position] as Album;
|
||||
cast.Should().NotBeNull();
|
||||
cast.Title.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
96
src/NzbDrone.Core.Test/MusicTests/AddAlbumFixture.cs
Normal file
96
src/NzbDrone.Core.Test/MusicTests/AddAlbumFixture.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using FluentValidation;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using System;
|
||||
|
||||
namespace NzbDrone.Core.Test.MusicTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class AddAlbumFixture : CoreTest<AddAlbumService>
|
||||
{
|
||||
private Artist _fakeArtist;
|
||||
private Album _fakeAlbum;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_fakeAlbum = Builder<Album>
|
||||
.CreateNew()
|
||||
.Build();
|
||||
|
||||
_fakeArtist = Builder<Artist>
|
||||
.CreateNew()
|
||||
.With(s => s.Path = null)
|
||||
.With(s => s.Metadata = Builder<ArtistMetadata>.CreateNew().Build())
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void GivenValidAlbum(string lidarrId)
|
||||
{
|
||||
Mocker.GetMock<IProvideAlbumInfo>()
|
||||
.Setup(s => s.GetAlbumInfo(lidarrId))
|
||||
.Returns(Tuple.Create(_fakeArtist.Metadata.Value.ForeignArtistId,
|
||||
_fakeAlbum,
|
||||
new List<ArtistMetadata> { _fakeArtist.Metadata.Value }));
|
||||
|
||||
Mocker.GetMock<IAddArtistService>()
|
||||
.Setup(s => s.AddArtist(It.IsAny<Artist>(), It.IsAny<bool>()))
|
||||
.Returns(_fakeArtist);
|
||||
}
|
||||
|
||||
private void GivenValidPath()
|
||||
{
|
||||
Mocker.GetMock<IBuildFileNames>()
|
||||
.Setup(s => s.GetArtistFolder(It.IsAny<Artist>(), null))
|
||||
.Returns<Artist, NamingConfig>((c, n) => c.Name);
|
||||
}
|
||||
|
||||
private Album AlbumToAdd(string albumId, string artistId)
|
||||
{
|
||||
return new Album
|
||||
{
|
||||
ForeignAlbumId = albumId,
|
||||
ArtistMetadata = new ArtistMetadata
|
||||
{
|
||||
ForeignArtistId = artistId
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_add_a_album_without_passing_in_name()
|
||||
{
|
||||
var newAlbum = AlbumToAdd("5537624c-3d2f-4f5c-8099-df916082c85c", "cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493");
|
||||
|
||||
GivenValidAlbum(newAlbum.ForeignAlbumId);
|
||||
GivenValidPath();
|
||||
|
||||
var album = Subject.AddAlbum(newAlbum);
|
||||
|
||||
album.Title.Should().Be(_fakeAlbum.Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_album_cannot_be_found()
|
||||
{
|
||||
var newAlbum = AlbumToAdd("5537624c-3d2f-4f5c-8099-df916082c85c", "cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493");
|
||||
|
||||
Mocker.GetMock<IProvideAlbumInfo>()
|
||||
.Setup(s => s.GetAlbumInfo(newAlbum.ForeignAlbumId))
|
||||
.Throws(new AlbumNotFoundException(newAlbum.ForeignAlbumId));
|
||||
|
||||
Assert.Throws<ValidationException>(() => Subject.AddAlbum(newAlbum));
|
||||
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FizzWare.NBuilder;
|
||||
|
|
|
@ -172,7 +172,7 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
Subject.RefreshAlbumInfo(album, null, false);
|
||||
|
||||
Mocker.GetMock<IAlbumService>()
|
||||
.Verify(x => x.DeleteAlbum(album.Id, true),
|
||||
.Verify(x => x.DeleteAlbum(album.Id, true, false),
|
||||
Times.Once());
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
@ -14,6 +12,7 @@ using NzbDrone.Test.Common;
|
|||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
using NzbDrone.Core.ImportLists.Exclusions;
|
||||
|
||||
namespace NzbDrone.Core.Test.MusicTests
|
||||
{
|
||||
|
@ -24,6 +23,7 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
private Album _album1;
|
||||
private Album _album2;
|
||||
private List<Album> _albums;
|
||||
private List<Album> _remoteAlbums;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
|
@ -38,6 +38,9 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
|
||||
_albums = new List<Album> {_album1, _album2};
|
||||
|
||||
_remoteAlbums = _albums.JsonClone();
|
||||
_remoteAlbums.ForEach(x => x.Id = 0);
|
||||
|
||||
var metadata = Builder<ArtistMetadata>.CreateNew().Build();
|
||||
|
||||
_artist = Builder<Artist>.CreateNew()
|
||||
|
@ -62,6 +65,10 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(x => x.GetByArtist(It.IsAny<int>(), It.IsAny<HistoryEventType?>()))
|
||||
.Returns(new List<History.History>());
|
||||
|
||||
Mocker.GetMock<IImportListExclusionService>()
|
||||
.Setup(x => x.FindByForeignId(It.IsAny<List<string>>()))
|
||||
.Returns(new List<ImportListExclusion>());
|
||||
}
|
||||
|
||||
private void GivenNewArtistInfo(Artist artist)
|
||||
|
@ -78,11 +85,11 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
.Returns(Builder<TrackFile>.CreateListOfSize(1).BuildList());
|
||||
}
|
||||
|
||||
private void GivenAlbumsForRefresh()
|
||||
private void GivenAlbumsForRefresh(List<Album> albums)
|
||||
{
|
||||
Mocker.GetMock<IAlbumService>(MockBehavior.Strict)
|
||||
.Setup(s => s.GetAlbumsForRefresh(It.IsAny<int>(), It.IsAny<IEnumerable<string>>()))
|
||||
.Returns(new List<Album>());
|
||||
.Returns(albums);
|
||||
}
|
||||
|
||||
private void AllowArtistUpdate()
|
||||
|
@ -97,10 +104,10 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
newArtistInfo.Metadata = _artist.Metadata.Value.JsonClone();
|
||||
newArtistInfo.Albums = _albums;
|
||||
newArtistInfo.Albums = _remoteAlbums;
|
||||
|
||||
GivenNewArtistInfo(newArtistInfo);
|
||||
GivenAlbumsForRefresh();
|
||||
GivenAlbumsForRefresh(_albums);
|
||||
AllowArtistUpdate();
|
||||
|
||||
Subject.Execute(new RefreshArtistCommand(_artist.Id));
|
||||
|
@ -117,10 +124,10 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
newArtistInfo.Metadata.Value.Images = new List<MediaCover.MediaCover> {
|
||||
new MediaCover.MediaCover(MediaCover.MediaCoverTypes.Logo, "dummy")
|
||||
};
|
||||
newArtistInfo.Albums = _albums;
|
||||
newArtistInfo.Albums = _remoteAlbums;
|
||||
|
||||
GivenNewArtistInfo(newArtistInfo);
|
||||
GivenAlbumsForRefresh();
|
||||
GivenAlbumsForRefresh(new List<Album>());
|
||||
AllowArtistUpdate();
|
||||
|
||||
Subject.Execute(new RefreshArtistCommand(_artist.Id));
|
||||
|
@ -151,7 +158,7 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
public void should_log_error_but_not_delete_if_musicbrainz_id_not_found_and_artist_has_files()
|
||||
{
|
||||
GivenArtistFiles();
|
||||
GivenAlbumsForRefresh();
|
||||
GivenAlbumsForRefresh(new List<Album>());
|
||||
|
||||
Subject.Execute(new RefreshArtistCommand(_artist.Id));
|
||||
|
||||
|
@ -169,7 +176,7 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
newArtistInfo.Metadata = _artist.Metadata.Value.JsonClone();
|
||||
newArtistInfo.Albums = _albums;
|
||||
newArtistInfo.Albums = _remoteAlbums;
|
||||
newArtistInfo.ForeignArtistId = _artist.ForeignArtistId + 1;
|
||||
newArtistInfo.Metadata.Value.Id = 100;
|
||||
|
||||
|
@ -222,8 +229,7 @@ namespace NzbDrone.Core.Test.MusicTests
|
|||
|
||||
var newArtistInfo = clash.JsonClone();
|
||||
newArtistInfo.Metadata = clash.Metadata.Value.JsonClone();
|
||||
newArtistInfo.Albums = _albums.JsonClone();
|
||||
newArtistInfo.Albums.Value.ForEach(x => x.Id = 0);
|
||||
newArtistInfo.Albums = _remoteAlbums;
|
||||
|
||||
GivenNewArtistInfo(newArtistInfo);
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@ using FizzWare.NBuilder;
|
|||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.ImportLists;
|
||||
using NzbDrone.Core.ImportLists.HeadphonesImport;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Profiles.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace NzbDrone.Core.Test.Profiles.Metadata
|
||||
{
|
||||
|
@ -21,7 +22,7 @@ namespace NzbDrone.Core.Test.Profiles.Metadata
|
|||
Subject.Handle(new ApplicationStartedEvent());
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Once());
|
||||
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -36,9 +37,72 @@ namespace NzbDrone.Core.Test.Profiles.Metadata
|
|||
Subject.Handle(new ApplicationStartedEvent());
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Verify(v => v.Insert(It.IsAny<MetadataProfile>()), Times.Never());
|
||||
.Verify(v => v.Insert(It.Is<MetadataProfile>(x => x.Name == "Standard")), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void init_should_add_none_profile_if_it_doesnt_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.Is<MetadataProfile>(x => x.Name == "None")), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void init_should_move_existing_none_profile()
|
||||
{
|
||||
var profiles = Builder<MetadataProfile>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(x => x.Name = MetadataProfileService.NONE_PROFILE_NAME)
|
||||
.With(x => x.PrimaryAlbumTypes = new List<ProfilePrimaryAlbumTypeItem>
|
||||
{
|
||||
new ProfilePrimaryAlbumTypeItem
|
||||
{
|
||||
PrimaryAlbumType = PrimaryAlbumType.Album,
|
||||
Allowed = true
|
||||
}
|
||||
})
|
||||
.BuildList();
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Setup(s => s.All())
|
||||
.Returns(profiles);
|
||||
|
||||
Subject.Handle(new ApplicationStartedEvent());
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Verify(v => v.Update(It.Is<MetadataProfile>(x => x.Id == profiles.First().Id && x.Name == "None.1")), Times.Once());
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>()
|
||||
.Verify(v => v.Insert(It.Is<MetadataProfile>(x => x.Name == "None")), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_able_to_edit_none_profile()
|
||||
{
|
||||
var profile = Builder<MetadataProfile>.CreateNew()
|
||||
.With(p => p.Name = MetadataProfileService.NONE_PROFILE_NAME)
|
||||
.Build();
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => Subject.Update(profile));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_able_to_delete_none_profile()
|
||||
{
|
||||
var profile = Builder<MetadataProfile>.CreateNew()
|
||||
.With(p => p.Name = MetadataProfileService.NONE_PROFILE_NAME)
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IMetadataProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
||||
|
||||
Assert.Throws<MetadataProfileInUseException>(() => Subject.Delete(profile.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_able_to_delete_profile_if_assigned_to_artist()
|
||||
|
@ -94,10 +158,13 @@ namespace NzbDrone.Core.Test.Profiles.Metadata
|
|||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_delete_profile_if_not_assigned_to_artist_or_import_list()
|
||||
{
|
||||
var profile = Builder<MetadataProfile>.CreateNew()
|
||||
.With(p => p.Id = 1)
|
||||
.Build();
|
||||
|
||||
var artistList = Builder<Artist>.CreateListOfSize(3)
|
||||
.All()
|
||||
.With(c => c.MetadataProfileId = 2)
|
||||
|
@ -110,6 +177,7 @@ namespace NzbDrone.Core.Test.Profiles.Metadata
|
|||
|
||||
Mocker.GetMock<IArtistService>().Setup(c => c.GetAllArtists()).Returns(artistList);
|
||||
Mocker.GetMock<IImportListFactory>().Setup(c => c.All()).Returns(importLists);
|
||||
Mocker.GetMock<IMetadataProfileRepository>().Setup(c => c.Get(profile.Id)).Returns(profile);
|
||||
|
||||
Subject.Delete(1);
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ namespace NzbDrone.Core.ArtistStats
|
|||
public class ArtistStatisticsService : IArtistStatisticsService,
|
||||
IHandle<ArtistUpdatedEvent>,
|
||||
IHandle<ArtistDeletedEvent>,
|
||||
IHandle<AlbumAddedEvent>,
|
||||
IHandle<AlbumDeletedEvent>,
|
||||
IHandle<AlbumImportedEvent>,
|
||||
IHandle<AlbumEditedEvent>,
|
||||
IHandle<TrackFileDeletedEvent>
|
||||
|
@ -77,6 +79,20 @@ namespace NzbDrone.Core.ArtistStats
|
|||
_cache.Remove(message.Artist.Id.ToString());
|
||||
}
|
||||
|
||||
[EventHandleOrder(EventHandleOrder.First)]
|
||||
public void Handle(AlbumAddedEvent message)
|
||||
{
|
||||
_cache.Remove("AllArtists");
|
||||
_cache.Remove(message.Album.ArtistId.ToString());
|
||||
}
|
||||
|
||||
[EventHandleOrder(EventHandleOrder.First)]
|
||||
public void Handle(AlbumDeletedEvent message)
|
||||
{
|
||||
_cache.Remove("AllArtists");
|
||||
_cache.Remove(message.Album.ArtistId.ToString());
|
||||
}
|
||||
|
||||
[EventHandleOrder(EventHandleOrder.First)]
|
||||
public void Handle(AlbumImportedEvent message)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.Exclusions
|
||||
|
@ -7,6 +8,7 @@ namespace NzbDrone.Core.ImportLists.Exclusions
|
|||
public interface IImportListExclusionRepository : IBasicRepository<ImportListExclusion>
|
||||
{
|
||||
ImportListExclusion FindByForeignId(string foreignId);
|
||||
List<ImportListExclusion> FindByForeignId(List<string> ids);
|
||||
}
|
||||
|
||||
public class ImportListExclusionRepository : BasicRepository<ImportListExclusion>, IImportListExclusionRepository
|
||||
|
@ -20,5 +22,10 @@ namespace NzbDrone.Core.ImportLists.Exclusions
|
|||
{
|
||||
return Query.Where<ImportListExclusion>(m => m.ForeignId == foreignId).SingleOrDefault();
|
||||
}
|
||||
|
||||
public List<ImportListExclusion> FindByForeignId(List<string> ids)
|
||||
{
|
||||
return Query.Where($"[ForeignId] IN ('{string.Join("', '", ids)}')").ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,16 @@ namespace NzbDrone.Core.ImportLists.Exclusions
|
|||
ImportListExclusion Add(ImportListExclusion importListExclusion);
|
||||
List<ImportListExclusion> All();
|
||||
void Delete(int id);
|
||||
void Delete(string foreignId);
|
||||
ImportListExclusion Get(int id);
|
||||
ImportListExclusion FindByForeignId(string foreignId);
|
||||
List<ImportListExclusion> FindByForeignId(List<string> foreignIds);
|
||||
ImportListExclusion Update(ImportListExclusion importListExclusion);
|
||||
}
|
||||
|
||||
public class ImportListExclusionService : IImportListExclusionService, IHandleAsync<ArtistDeletedEvent>
|
||||
public class ImportListExclusionService : IImportListExclusionService,
|
||||
IHandleAsync<ArtistDeletedEvent>,
|
||||
IHandleAsync<AlbumDeletedEvent>
|
||||
{
|
||||
private readonly IImportListExclusionRepository _repo;
|
||||
|
||||
|
@ -39,6 +43,15 @@ namespace NzbDrone.Core.ImportLists.Exclusions
|
|||
_repo.Delete(id);
|
||||
}
|
||||
|
||||
public void Delete(string foreignId)
|
||||
{
|
||||
var exclusion = FindByForeignId(foreignId);
|
||||
if (exclusion != null)
|
||||
{
|
||||
Delete(exclusion.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public ImportListExclusion Get(int id)
|
||||
{
|
||||
return _repo.Get(id);
|
||||
|
@ -49,6 +62,11 @@ namespace NzbDrone.Core.ImportLists.Exclusions
|
|||
return _repo.FindByForeignId(foreignId);
|
||||
}
|
||||
|
||||
public List<ImportListExclusion> FindByForeignId(List<string> foreignIds)
|
||||
{
|
||||
return _repo.FindByForeignId(foreignIds);
|
||||
}
|
||||
|
||||
public List<ImportListExclusion> All()
|
||||
{
|
||||
return _repo.All().ToList();
|
||||
|
@ -76,5 +94,28 @@ namespace NzbDrone.Core.ImportLists.Exclusions
|
|||
|
||||
_repo.Insert(importExclusion);
|
||||
}
|
||||
|
||||
public void HandleAsync(AlbumDeletedEvent message)
|
||||
{
|
||||
if (!message.AddImportListExclusion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var existingExclusion = _repo.FindByForeignId(message.Album.ForeignAlbumId);
|
||||
|
||||
if (existingExclusion != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var importExclusion = new ImportListExclusion
|
||||
{
|
||||
ForeignId = message.Album.ForeignAlbumId,
|
||||
Name = $"{message.Album.ArtistMetadata.Value.Name} - {message.Album.Title}"
|
||||
};
|
||||
|
||||
_repo.Insert(importExclusion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,19 +20,23 @@ namespace NzbDrone.Core.ImportLists
|
|||
private readonly ISearchForNewAlbum _albumSearchService;
|
||||
private readonly ISearchForNewArtist _artistSearchService;
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly IAlbumService _albumService;
|
||||
private readonly IAddArtistService _addArtistService;
|
||||
private readonly IAddAlbumService _addAlbumService;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ImportListSyncService(IImportListFactory importListFactory,
|
||||
IImportListExclusionService importListExclusionService,
|
||||
IFetchAndParseImportList listFetcherAndParser,
|
||||
ISearchForNewAlbum albumSearchService,
|
||||
ISearchForNewArtist artistSearchService,
|
||||
IArtistService artistService,
|
||||
IAddArtistService addArtistService,
|
||||
IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
IImportListExclusionService importListExclusionService,
|
||||
IFetchAndParseImportList listFetcherAndParser,
|
||||
ISearchForNewAlbum albumSearchService,
|
||||
ISearchForNewArtist artistSearchService,
|
||||
IArtistService artistService,
|
||||
IAlbumService albumService,
|
||||
IAddArtistService addArtistService,
|
||||
IAddAlbumService addAlbumService,
|
||||
IEventAggregator eventAggregator,
|
||||
Logger logger)
|
||||
{
|
||||
_importListFactory = importListFactory;
|
||||
_importListExclusionService = importListExclusionService;
|
||||
|
@ -40,7 +44,9 @@ namespace NzbDrone.Core.ImportLists
|
|||
_albumSearchService = albumSearchService;
|
||||
_artistSearchService = artistSearchService;
|
||||
_artistService = artistService;
|
||||
_albumService = albumService;
|
||||
_addArtistService = addArtistService;
|
||||
_addAlbumService = addAlbumService;
|
||||
_eventAggregator = eventAggregator;
|
||||
_logger = logger;
|
||||
}
|
||||
|
@ -74,6 +80,7 @@ namespace NzbDrone.Core.ImportLists
|
|||
{
|
||||
var processed = new List<Album>();
|
||||
var artistsToAdd = new List<Artist>();
|
||||
var albumsToAdd = new List<Album>();
|
||||
|
||||
_logger.ProgressInfo("Processing {0} list items", reports.Count);
|
||||
|
||||
|
@ -89,68 +96,156 @@ namespace NzbDrone.Core.ImportLists
|
|||
|
||||
var importList = _importListFactory.Get(report.ImportListId);
|
||||
|
||||
// Map MBid if we only have an album title
|
||||
if (report.AlbumMusicBrainzId.IsNullOrWhiteSpace() && report.Album.IsNotNullOrWhiteSpace())
|
||||
if (report.Album.IsNotNullOrWhiteSpace() || report.AlbumMusicBrainzId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
var mappedAlbum = _albumSearchService.SearchForNewAlbum(report.Album, report.Artist)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (mappedAlbum == null) continue; // Break if we are looking for an album and cant find it. This will avoid us from adding the artist and possibly getting it wrong.
|
||||
|
||||
report.AlbumMusicBrainzId = mappedAlbum.ForeignAlbumId;
|
||||
report.Album = mappedAlbum.Title;
|
||||
report.Artist = mappedAlbum.ArtistMetadata?.Value?.Name;
|
||||
report.ArtistMusicBrainzId = mappedAlbum?.ArtistMetadata?.Value?.ForeignArtistId;
|
||||
if (report.AlbumMusicBrainzId.IsNullOrWhiteSpace() || report.ArtistMusicBrainzId.IsNullOrWhiteSpace())
|
||||
{
|
||||
MapAlbumReport(report);
|
||||
}
|
||||
|
||||
ProcessAlbumReport(importList, report, listExclusions, albumsToAdd);
|
||||
}
|
||||
|
||||
// Map artist ID if we only have album ID
|
||||
if (report.AlbumMusicBrainzId.IsNotNullOrWhiteSpace() && report.ArtistMusicBrainzId.IsNullOrWhiteSpace())
|
||||
else if (report.Artist.IsNotNullOrWhiteSpace() || report.ArtistMusicBrainzId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
var mappedAlbum = _albumSearchService.SearchForNewAlbum($"lidarr:{report.AlbumMusicBrainzId}", null)
|
||||
.FirstOrDefault();
|
||||
if (report.ArtistMusicBrainzId.IsNullOrWhiteSpace())
|
||||
{
|
||||
MapArtistReport(report);
|
||||
}
|
||||
|
||||
if (mappedAlbum == null) continue;
|
||||
|
||||
report.Artist = mappedAlbum.ArtistMetadata?.Value?.Name;
|
||||
report.ArtistMusicBrainzId = mappedAlbum?.ArtistMetadata?.Value?.ForeignArtistId;
|
||||
ProcessArtistReport(importList, report, listExclusions, artistsToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
// Map MBid if we only have a artist name
|
||||
if (report.ArtistMusicBrainzId.IsNullOrWhiteSpace() && report.Artist.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
var mappedArtist = _artistSearchService.SearchForNewArtist(report.Artist)
|
||||
.FirstOrDefault();
|
||||
report.ArtistMusicBrainzId = mappedArtist?.Metadata.Value?.ForeignArtistId;
|
||||
report.Artist = mappedArtist?.Metadata.Value?.Name;
|
||||
}
|
||||
_addArtistService.AddArtists(artistsToAdd);
|
||||
_addAlbumService.AddAlbums(albumsToAdd);
|
||||
|
||||
// Check to see if artist in DB
|
||||
var existingArtist = _artistService.FindById(report.ArtistMusicBrainzId);
|
||||
var message = string.Format($"Import List Sync Completed. Items found: {reports.Count}, Artists added: {artistsToAdd.Count}, Albums added: {albumsToAdd.Count}");
|
||||
|
||||
// TODO: Rework this for albums when we can add albums seperate from Artists
|
||||
// (If list contains albums we should not break for an existing artist, we should add new albums that are not in DB)
|
||||
if (existingArtist != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected, Artist Exists in DB", report.ArtistMusicBrainzId, report.Artist);
|
||||
continue;
|
||||
}
|
||||
_logger.ProgressInfo(message);
|
||||
|
||||
// Check to see if artist excluded
|
||||
var excludedArtist = listExclusions.Where(s => s.ForeignId == report.ArtistMusicBrainzId).SingleOrDefault();
|
||||
return processed;
|
||||
}
|
||||
|
||||
if (excludedArtist != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.ArtistMusicBrainzId, report.Artist);
|
||||
continue;
|
||||
}
|
||||
private void MapAlbumReport(ImportListItemInfo report)
|
||||
{
|
||||
var albumQuery = report.AlbumMusicBrainzId.IsNotNullOrWhiteSpace() ? $"lidarr:{report.AlbumMusicBrainzId}" : report.Album;
|
||||
var mappedAlbum = _albumSearchService.SearchForNewAlbum(albumQuery, report.Artist)
|
||||
.FirstOrDefault();
|
||||
|
||||
// Append Artist if not already in DB or already on add list
|
||||
if (artistsToAdd.All(s => s.Metadata.Value.ForeignArtistId != report.ArtistMusicBrainzId))
|
||||
{
|
||||
var monitored = importList.ShouldMonitor != ImportListMonitorType.None;
|
||||
// Break if we are looking for an album and cant find it. This will avoid us from adding the artist and possibly getting it wrong.
|
||||
if (mappedAlbum == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
artistsToAdd.Add(new Artist
|
||||
report.AlbumMusicBrainzId = mappedAlbum.ForeignAlbumId;
|
||||
report.Album = mappedAlbum.Title;
|
||||
report.Artist = mappedAlbum.ArtistMetadata?.Value?.Name;
|
||||
report.ArtistMusicBrainzId = mappedAlbum.ArtistMetadata?.Value?.ForeignArtistId;
|
||||
}
|
||||
|
||||
private void ProcessAlbumReport(ImportListDefinition importList, ImportListItemInfo report, List<ImportListExclusion> listExclusions, List<Album> albumsToAdd)
|
||||
{
|
||||
if (report.AlbumMusicBrainzId == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if album in DB
|
||||
var existingAlbum = _albumService.FindById(report.AlbumMusicBrainzId);
|
||||
|
||||
if (existingAlbum != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected, Album Exists in DB", report.AlbumMusicBrainzId, report.Album);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if album excluded
|
||||
var excludedAlbum = listExclusions.SingleOrDefault(s => s.ForeignId == report.AlbumMusicBrainzId);
|
||||
|
||||
if (excludedAlbum != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.AlbumMusicBrainzId, report.Album);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if artist excluded
|
||||
var excludedArtist = listExclusions.SingleOrDefault(s => s.ForeignId == report.ArtistMusicBrainzId);
|
||||
|
||||
if (excludedArtist != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected due to list exlcusion for parent artist", report.AlbumMusicBrainzId, report.Album);
|
||||
return;
|
||||
}
|
||||
|
||||
// Append Album if not already in DB or already on add list
|
||||
if (albumsToAdd.All(s => s.ForeignAlbumId != report.AlbumMusicBrainzId))
|
||||
{
|
||||
var monitored = importList.ShouldMonitor != ImportListMonitorType.None;
|
||||
|
||||
albumsToAdd.Add(new Album
|
||||
{
|
||||
ForeignAlbumId = report.AlbumMusicBrainzId,
|
||||
Monitored = monitored,
|
||||
Artist = new Artist
|
||||
{
|
||||
Monitored = monitored,
|
||||
RootFolderPath = importList.RootFolderPath,
|
||||
QualityProfileId = importList.ProfileId,
|
||||
MetadataProfileId = importList.MetadataProfileId,
|
||||
Tags = importList.Tags,
|
||||
AlbumFolder = true,
|
||||
AddOptions = new AddArtistOptions
|
||||
{
|
||||
SearchForMissingAlbums = monitored,
|
||||
Monitored = monitored,
|
||||
Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void MapArtistReport(ImportListItemInfo report)
|
||||
{
|
||||
var mappedArtist = _artistSearchService.SearchForNewArtist(report.Artist)
|
||||
.FirstOrDefault();
|
||||
report.ArtistMusicBrainzId = mappedArtist?.Metadata.Value?.ForeignArtistId;
|
||||
report.Artist = mappedArtist?.Metadata.Value?.Name;
|
||||
}
|
||||
|
||||
private void ProcessArtistReport(ImportListDefinition importList, ImportListItemInfo report, List<ImportListExclusion> listExclusions, List<Artist> artistsToAdd)
|
||||
{
|
||||
if (report.ArtistMusicBrainzId == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if artist in DB
|
||||
var existingArtist = _artistService.FindById(report.ArtistMusicBrainzId);
|
||||
|
||||
if (existingArtist != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected, Artist Exists in DB", report.ArtistMusicBrainzId, report.Artist);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if artist excluded
|
||||
var excludedArtist = listExclusions.Where(s => s.ForeignId == report.ArtistMusicBrainzId).SingleOrDefault();
|
||||
|
||||
if (excludedArtist != null)
|
||||
{
|
||||
_logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.ArtistMusicBrainzId, report.Artist);
|
||||
return;
|
||||
}
|
||||
|
||||
// Append Artist if not already in DB or already on add list
|
||||
if (artistsToAdd.All(s => s.Metadata.Value.ForeignArtistId != report.ArtistMusicBrainzId))
|
||||
{
|
||||
var monitored = importList.ShouldMonitor != ImportListMonitorType.None;
|
||||
|
||||
artistsToAdd.Add(new Artist
|
||||
{
|
||||
Metadata = new ArtistMetadata
|
||||
{
|
||||
|
@ -170,22 +265,7 @@ namespace NzbDrone.Core.ImportLists
|
|||
Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add Album so we know what to monitor
|
||||
if (report.AlbumMusicBrainzId.IsNotNullOrWhiteSpace() && artistsToAdd.Any(s => s.Metadata.Value.ForeignArtistId == report.ArtistMusicBrainzId) && importList.ShouldMonitor == ImportListMonitorType.SpecificAlbum)
|
||||
{
|
||||
artistsToAdd.Find(s => s.Metadata.Value.ForeignArtistId == report.ArtistMusicBrainzId).AddOptions.AlbumsToMonitor.Add(report.AlbumMusicBrainzId);
|
||||
}
|
||||
}
|
||||
|
||||
_addArtistService.AddArtists(artistsToAdd);
|
||||
|
||||
var message = string.Format("Import List Sync Completed. Items found: {0}, Artists added: {1}", reports.Count, artistsToAdd.Count);
|
||||
|
||||
_logger.ProgressInfo(message);
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
public void Execute(ImportListSyncCommand message)
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace NzbDrone.Core.MediaCover
|
|||
public class MediaCoverService :
|
||||
IHandleAsync<ArtistRefreshCompleteEvent>,
|
||||
IHandleAsync<ArtistDeletedEvent>,
|
||||
IHandleAsync<AlbumDeletedEvent>,
|
||||
IMapCoversToLocal
|
||||
{
|
||||
private readonly IImageResizer _resizer;
|
||||
|
@ -292,5 +293,13 @@ namespace NzbDrone.Core.MediaCover
|
|||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(AlbumDeletedEvent message)
|
||||
{
|
||||
var path = GetAlbumCoverPath(message.Album.Id);
|
||||
if (_diskProvider.FolderExists(path))
|
||||
{
|
||||
_diskProvider.DeleteFolder(path, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
public class MediaFileDeletionService : IDeleteMediaFiles,
|
||||
IHandleAsync<ArtistDeletedEvent>,
|
||||
IHandleAsync<AlbumDeletedEvent>,
|
||||
IHandle<TrackFileDeletedEvent>
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
|
@ -128,6 +129,18 @@ namespace NzbDrone.Core.MediaFiles
|
|||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(AlbumDeletedEvent message)
|
||||
{
|
||||
if (message.DeleteFiles)
|
||||
{
|
||||
var files = _mediaFileService.GetFilesByAlbum(message.Album.Id);
|
||||
foreach (var file in files)
|
||||
{
|
||||
_recycleBinProvider.DeleteFile(file.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[EventHandleOrder(EventHandleOrder.Last)]
|
||||
public void Handle(TrackFileDeletedEvent message)
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
List<TrackFile> GetFilesWithBasePath(string path);
|
||||
TrackFile GetFileWithPath(string path);
|
||||
void DeleteFilesByAlbum(int albumId);
|
||||
void UnlinkFilesByAlbum(int albumId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,6 +71,13 @@ namespace NzbDrone.Core.MediaFiles
|
|||
DeleteMany(ids);
|
||||
}
|
||||
|
||||
public void UnlinkFilesByAlbum(int albumId)
|
||||
{
|
||||
var files = DataMapper.Query<TrackFile>().Where(x => x.AlbumId == albumId).ToList();
|
||||
files.ForEach(x => x.AlbumId = 0);
|
||||
SetFields(files, f => f.AlbumId);
|
||||
}
|
||||
|
||||
public List<TrackFile> GetFilesByRelease(int releaseId)
|
||||
{
|
||||
return Query
|
||||
|
|
|
@ -160,7 +160,14 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
public void HandleAsync(AlbumDeletedEvent message)
|
||||
{
|
||||
_mediaFileRepository.DeleteFilesByAlbum(message.Album.Id);
|
||||
if (message.DeleteFiles)
|
||||
{
|
||||
_mediaFileRepository.DeleteFilesByAlbum(message.Album.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mediaFileRepository.UnlinkFilesByAlbum(message.Album.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public List<TrackFile> GetFilesByArtist(int artistId)
|
||||
|
|
10
src/NzbDrone.Core/MetadataSource/ISearchForNewEntity.cs
Normal file
10
src/NzbDrone.Core/MetadataSource/ISearchForNewEntity.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource
|
||||
{
|
||||
public interface ISearchForNewEntity
|
||||
{
|
||||
List<Object> SearchForNewEntity(string title);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class EntityResource
|
||||
{
|
||||
public int Score { get; set; }
|
||||
public ArtistResource Artist { get; set; }
|
||||
public AlbumResource Album { get; set; }
|
||||
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Net;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cloud;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
|
@ -15,7 +14,7 @@ using NzbDrone.Core.Profiles.Metadata;
|
|||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||
{
|
||||
public class SkyHookProxy : IProvideArtistInfo, ISearchForNewArtist, IProvideAlbumInfo, ISearchForNewAlbum
|
||||
public class SkyHookProxy : IProvideArtistInfo, ISearchForNewArtist, IProvideAlbumInfo, ISearchForNewAlbum, ISearchForNewEntity
|
||||
{
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly Logger _logger;
|
||||
|
@ -247,6 +246,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
.AddQueryParam("type", "album")
|
||||
.AddQueryParam("query", title.ToLower().Trim())
|
||||
.AddQueryParam("artist", artist.IsNotNullOrWhiteSpace() ? artist.ToLower().Trim() : string.Empty)
|
||||
.AddQueryParam("includeTracks", "1")
|
||||
.Build();
|
||||
|
||||
|
||||
|
@ -266,6 +266,31 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
}
|
||||
}
|
||||
|
||||
public List<Object> SearchForNewEntity(string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
var httpRequest = _requestBuilder.GetRequestBuilder().Create()
|
||||
.SetSegment("route", "search")
|
||||
.AddQueryParam("type", "all")
|
||||
.AddQueryParam("query", title.ToLower().Trim())
|
||||
.Build();
|
||||
|
||||
var httpResponse = _httpClient.Get<List<EntityResource>>(httpRequest);
|
||||
|
||||
return httpResponse.Resource.SelectList(MapSearchResult);
|
||||
}
|
||||
catch (HttpException)
|
||||
{
|
||||
throw new SkyHookException("Search for '{0}' failed. Unable to communicate with LidarrAPI.", title);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, ex.Message);
|
||||
throw new SkyHookException("Search for '{0}' failed. Invalid response received from LidarrAPI.", title);
|
||||
}
|
||||
}
|
||||
|
||||
private Artist MapSearchResult(ArtistResource resource)
|
||||
{
|
||||
var artist = _artistService.FindById(resource.Id);
|
||||
|
@ -280,20 +305,34 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
|||
|
||||
private Album MapSearchResult(AlbumResource resource)
|
||||
{
|
||||
var album = _albumService.FindById(resource.Id) ?? MapAlbum(resource, null);
|
||||
var artists = resource.Artists.Select(MapArtistMetadata).ToDictionary(x => x.ForeignArtistId, x => x);
|
||||
|
||||
var artist = _artistService.FindById(resource.ArtistId);
|
||||
if (artist == null)
|
||||
{
|
||||
artist = new Artist();
|
||||
artist.Metadata = MapArtistMetadata(resource.Artists.Single(x => x.Id == resource.ArtistId));
|
||||
artist.Metadata = artists[resource.ArtistId];
|
||||
}
|
||||
|
||||
var album = _albumService.FindById(resource.Id) ?? MapAlbum(resource, artists);
|
||||
album.Artist = artist;
|
||||
album.ArtistMetadata = artist.Metadata;
|
||||
album.ArtistMetadata = artist.Metadata.Value;
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
private Object MapSearchResult(EntityResource resource)
|
||||
{
|
||||
if (resource.Artist != null)
|
||||
{
|
||||
return MapSearchResult(resource.Artist);
|
||||
}
|
||||
else
|
||||
{
|
||||
return MapSearchResult(resource.Album);
|
||||
}
|
||||
}
|
||||
|
||||
private static Album MapAlbum(AlbumResource resource, Dictionary<string, ArtistMetadata> artistDict)
|
||||
{
|
||||
Album album = new Album();
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
|
||||
public static class ArtistNameNormalizer
|
||||
{
|
||||
private readonly static Dictionary<string, string> PreComputedTitles = new Dictionary<string, string>
|
||||
{
|
||||
{ "281588", "a to z" },
|
||||
{ "266757", "ad trials triumph early church" },
|
||||
{ "289260", "ad bible continues"}
|
||||
};
|
||||
|
||||
public static string Normalize(string title, string mbID)
|
||||
{
|
||||
if (PreComputedTitles.ContainsKey(mbID))
|
||||
{
|
||||
return PreComputedTitles[mbID];
|
||||
}
|
||||
|
||||
return Parser.Parser.NormalizeTitle(title).ToLower();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,4 @@
|
|||
using NzbDrone.Common.Messaging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Music.Events
|
||||
{
|
||||
|
|
|
@ -10,11 +10,13 @@ namespace NzbDrone.Core.Music.Events
|
|||
{
|
||||
public Album Album { get; private set; }
|
||||
public bool DeleteFiles { get; private set; }
|
||||
public bool AddImportListExclusion { get; private set; }
|
||||
|
||||
public AlbumDeletedEvent(Album album, bool deleteFiles)
|
||||
public AlbumDeletedEvent(Album album, bool deleteFiles, bool addImportListExclusion)
|
||||
{
|
||||
Album = album;
|
||||
DeleteFiles = deleteFiles;
|
||||
AddImportListExclusion = addImportListExclusion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
src/NzbDrone.Core/Music/Events/AlbumUpdatedEvent.cs
Normal file
14
src/NzbDrone.Core/Music/Events/AlbumUpdatedEvent.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.Music.Events
|
||||
{
|
||||
public class AlbumUpdatedEvent : IEvent
|
||||
{
|
||||
public Album Album { get; private set; }
|
||||
|
||||
public AlbumUpdatedEvent(Album album)
|
||||
{
|
||||
Album = album;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,16 @@
|
|||
using NzbDrone.Common.Messaging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Music.Events
|
||||
{
|
||||
public class ArtistAddedEvent : IEvent
|
||||
{
|
||||
public Artist Artist { get; private set; }
|
||||
public bool DoRefresh { get; private set; }
|
||||
|
||||
public ArtistAddedEvent(Artist artist)
|
||||
public ArtistAddedEvent(Artist artist, bool doRefresh = true)
|
||||
{
|
||||
Artist = artist;
|
||||
DoRefresh = doRefresh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/NzbDrone.Core/Music/Handlers/AlbumAddedHandler.cs
Normal file
22
src/NzbDrone.Core/Music/Handlers/AlbumAddedHandler.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music.Commands;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class AlbumAddedHandler : IHandle<AlbumAddedEvent>
|
||||
{
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
|
||||
public AlbumAddedHandler(IManageCommandQueue commandQueueManager)
|
||||
{
|
||||
_commandQueueManager = commandQueueManager;
|
||||
}
|
||||
|
||||
public void Handle(AlbumAddedEvent message)
|
||||
{
|
||||
_commandQueueManager.Push(new RefreshArtistCommand(message.Album.Artist.Value.Id));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,10 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
public void Handle(ArtistAddedEvent message)
|
||||
{
|
||||
_commandQueueManager.Push(new RefreshArtistCommand(message.Artist.Id, true));
|
||||
if (message.DoRefresh)
|
||||
{
|
||||
_commandQueueManager.Push(new RefreshArtistCommand(message.Artist.Id, true));
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ArtistsImportedEvent message)
|
|
@ -12,41 +12,40 @@ namespace NzbDrone.Core.Music
|
|||
private readonly IAlbumMonitoredService _albumMonitoredService;
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
//private readonly IEpisodeAddedService _episodeAddedService;
|
||||
private readonly IAlbumAddedService _albumAddedService;
|
||||
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ArtistScannedHandler(IAlbumMonitoredService albumMonitoredService,
|
||||
IArtistService artistService,
|
||||
IManageCommandQueue commandQueueManager,
|
||||
//IEpisodeAddedService episodeAddedService,
|
||||
IAlbumAddedService albumAddedService,
|
||||
Logger logger)
|
||||
{
|
||||
_albumMonitoredService = albumMonitoredService;
|
||||
_artistService = artistService;
|
||||
_commandQueueManager = commandQueueManager;
|
||||
//_episodeAddedService = episodeAddedService;
|
||||
_albumAddedService = albumAddedService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private void HandleScanEvents(Artist artist)
|
||||
{
|
||||
if (artist.AddOptions == null)
|
||||
if (artist.AddOptions != null)
|
||||
{
|
||||
//_episodeAddedService.SearchForRecentlyAdded(series.Id);
|
||||
return;
|
||||
_logger.Info("[{0}] was recently added, performing post-add actions", artist.Name);
|
||||
_albumMonitoredService.SetAlbumMonitoredStatus(artist, artist.AddOptions);
|
||||
|
||||
if (artist.AddOptions.SearchForMissingAlbums)
|
||||
{
|
||||
_commandQueueManager.Push(new MissingAlbumSearchCommand(artist.Id));
|
||||
}
|
||||
|
||||
artist.AddOptions = null;
|
||||
_artistService.RemoveAddOptions(artist);
|
||||
}
|
||||
|
||||
_logger.Info("[{0}] was recently added, performing post-add actions", artist.Name);
|
||||
_albumMonitoredService.SetAlbumMonitoredStatus(artist, artist.AddOptions);
|
||||
|
||||
if (artist.AddOptions.SearchForMissingAlbums)
|
||||
{
|
||||
_commandQueueManager.Push(new MissingAlbumSearchCommand(artist.Id));
|
||||
}
|
||||
|
||||
artist.AddOptions = null;
|
||||
_artistService.RemoveAddOptions(artist);
|
||||
_albumAddedService.SearchForRecentlyAdded(artist.Id);
|
||||
}
|
||||
|
||||
public void Handle(ArtistScannedEvent message)
|
22
src/NzbDrone.Core/Music/Model/AddAlbumOptions.cs
Normal file
22
src/NzbDrone.Core/Music/Model/AddAlbumOptions.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class AddAlbumOptions : IEmbeddedDocument
|
||||
{
|
||||
public AddAlbumOptions()
|
||||
{
|
||||
// default in case not set in db
|
||||
AddType = AlbumAddType.Automatic;
|
||||
}
|
||||
|
||||
public AlbumAddType AddType { get; set; }
|
||||
public bool SearchForNewAlbum { get; set; }
|
||||
}
|
||||
|
||||
public enum AlbumAddType
|
||||
{
|
||||
Automatic,
|
||||
Manual
|
||||
}
|
||||
}
|
|
@ -1,8 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class AddArtistOptions : MonitoringOptions
|
|
@ -12,14 +12,14 @@ namespace NzbDrone.Core.Music
|
|||
public Album()
|
||||
{
|
||||
OldForeignAlbumIds = new List<string>();
|
||||
|
||||
Overview = string.Empty;
|
||||
Images = new List<MediaCover.MediaCover>();
|
||||
Links = new List<Links>();
|
||||
Genres = new List<string>();
|
||||
SecondaryTypes = new List<SecondaryAlbumType>();
|
||||
Ratings = new Ratings();
|
||||
Artist = new Artist();
|
||||
|
||||
AddOptions = new AddAlbumOptions();
|
||||
}
|
||||
|
||||
// These correspond to columns in the Albums table
|
||||
|
@ -34,7 +34,7 @@ namespace NzbDrone.Core.Music
|
|||
public List<MediaCover.MediaCover> Images { get; set; }
|
||||
public List<Links> Links { get; set; }
|
||||
public List<string> Genres { get; set; }
|
||||
public String AlbumType { get; set; }
|
||||
public string AlbumType { get; set; }
|
||||
public List<SecondaryAlbumType> SecondaryTypes { get; set; }
|
||||
public Ratings Ratings { get; set; }
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace NzbDrone.Core.Music
|
|||
public DateTime? LastInfoSync { get; set; }
|
||||
public DateTime Added { get; set; }
|
||||
[MemberwiseEqualityIgnore]
|
||||
public AddArtistOptions AddOptions { get; set; }
|
||||
public AddAlbumOptions AddOptions { get; set; }
|
||||
|
||||
// These are dynamically queried from other tables
|
||||
[MemberwiseEqualityIgnore]
|
||||
|
@ -94,13 +94,13 @@ namespace NzbDrone.Core.Music
|
|||
AddOptions = other.AddOptions;
|
||||
}
|
||||
|
||||
public override void ApplyChanges(Album otherAlbum)
|
||||
public override void ApplyChanges(Album other)
|
||||
{
|
||||
ForeignAlbumId = otherAlbum.ForeignAlbumId;
|
||||
ProfileId = otherAlbum.ProfileId;
|
||||
AddOptions = otherAlbum.AddOptions;
|
||||
Monitored = otherAlbum.Monitored;
|
||||
AnyReleaseOk = otherAlbum.AnyReleaseOk;
|
||||
ForeignAlbumId = other.ForeignAlbumId;
|
||||
ProfileId = other.ProfileId;
|
||||
AddOptions = other.AddOptions;
|
||||
Monitored = other.Monitored;
|
||||
AnyReleaseOk = other.AnyReleaseOk;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,22 +75,20 @@ namespace NzbDrone.Core.Music
|
|||
AddOptions = other.AddOptions;
|
||||
}
|
||||
|
||||
public override void ApplyChanges(Artist otherArtist)
|
||||
public override void ApplyChanges(Artist other)
|
||||
{
|
||||
Path = other.Path;
|
||||
QualityProfileId = other.QualityProfileId;
|
||||
QualityProfile = other.QualityProfile;
|
||||
MetadataProfileId = other.MetadataProfileId;
|
||||
MetadataProfile = other.MetadataProfile;
|
||||
|
||||
Path = otherArtist.Path;
|
||||
QualityProfileId = otherArtist.QualityProfileId;
|
||||
QualityProfile = otherArtist.QualityProfile;
|
||||
MetadataProfileId = otherArtist.MetadataProfileId;
|
||||
MetadataProfile = otherArtist.MetadataProfile;
|
||||
|
||||
Albums = otherArtist.Albums;
|
||||
Tags = otherArtist.Tags;
|
||||
AddOptions = otherArtist.AddOptions;
|
||||
RootFolderPath = otherArtist.RootFolderPath;
|
||||
Monitored = otherArtist.Monitored;
|
||||
AlbumFolder = otherArtist.AlbumFolder;
|
||||
|
||||
Albums = other.Albums;
|
||||
Tags = other.Tags;
|
||||
AddOptions = other.AddOptions;
|
||||
RootFolderPath = other.RootFolderPath;
|
||||
Monitored = other.Monitored;
|
||||
AlbumFolder = other.AlbumFolder;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Marr.Data.QGen;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Datastore.Extensions;
|
||||
|
@ -17,9 +16,9 @@ namespace NzbDrone.Core.Music
|
|||
List<Album> GetLastAlbums(IEnumerable<int> artistMetadataIds);
|
||||
List<Album> GetNextAlbums(IEnumerable<int> artistMetadataIds);
|
||||
List<Album> GetAlbumsByArtistMetadataId(int artistMetadataId);
|
||||
List<Album> GetAlbumsForRefresh(int artistId, IEnumerable<string> foreignIds);
|
||||
List<Album> GetAlbumsForRefresh(int artistMetadataId, IEnumerable<string> foreignIds);
|
||||
Album FindByTitle(int artistMetadataId, string title);
|
||||
Album FindById(string foreignId);
|
||||
Album FindById(string foreignAlbumId);
|
||||
PagingSpec<Album> AlbumsWithoutFiles(PagingSpec<Album> pagingSpec);
|
||||
PagingSpec<Album> AlbumsWhereCutoffUnmet(PagingSpec<Album> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff);
|
||||
List<Album> AlbumsBetweenDates(DateTime startDate, DateTime endDate, bool includeUnmonitored);
|
||||
|
@ -34,13 +33,11 @@ namespace NzbDrone.Core.Music
|
|||
public class AlbumRepository : BasicRepository<Album>, IAlbumRepository
|
||||
{
|
||||
private readonly IMainDatabase _database;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public AlbumRepository(IMainDatabase database, IEventAggregator eventAggregator, Logger logger)
|
||||
public AlbumRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||
: base(database, eventAggregator)
|
||||
{
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<Album> GetAlbums(int artistId)
|
|
@ -9,7 +9,7 @@ namespace NzbDrone.Core.Music
|
|||
public interface IArtistMetadataRepository : IBasicRepository<ArtistMetadata>
|
||||
{
|
||||
List<ArtistMetadata> FindById(List<string> foreignIds);
|
||||
bool UpsertMany(List<ArtistMetadata> artists);
|
||||
bool UpsertMany(List<ArtistMetadata> data);
|
||||
}
|
||||
|
||||
public class ArtistMetadataRepository : BasicRepository<ArtistMetadata>, IArtistMetadataRepository
|
|
@ -9,7 +9,7 @@ namespace NzbDrone.Core.Music
|
|||
public interface IArtistRepository : IBasicRepository<Artist>
|
||||
{
|
||||
bool ArtistPathExists(string path);
|
||||
Artist FindByName(string cleanTitle);
|
||||
Artist FindByName(string cleanName);
|
||||
Artist FindById(string foreignArtistId);
|
||||
Artist GetArtistByMetadataId(int artistMetadataId);
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
using NzbDrone.Core.Datastore;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
|
@ -10,7 +9,7 @@ namespace NzbDrone.Core.Music
|
|||
List<Track> GetTracks(int artistId);
|
||||
List<Track> GetTracksByAlbum(int albumId);
|
||||
List<Track> GetTracksByRelease(int albumReleaseId);
|
||||
List<Track> GetTracksByReleases(List<int> albumReleaseId);
|
||||
List<Track> GetTracksByReleases(List<int> albumReleaseIds);
|
||||
List<Track> GetTracksForRefresh(int albumReleaseId, IEnumerable<string> foreignTrackIds);
|
||||
List<Track> GetTracksByFileId(int fileId);
|
||||
List<Track> GetTracksByFileId(IEnumerable<int> ids);
|
||||
|
@ -22,14 +21,9 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
public class TrackRepository : BasicRepository<Track>, ITrackRepository
|
||||
{
|
||||
private readonly IMainDatabase _database;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public TrackRepository(IMainDatabase database, IEventAggregator eventAggregator, Logger logger)
|
||||
public TrackRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||
: base(database, eventAggregator)
|
||||
{
|
||||
_database = database;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<Track> GetTracks(int artistId)
|
113
src/NzbDrone.Core/Music/Services/AddAlbumService.cs
Normal file
113
src/NzbDrone.Core/Music/Services/AddAlbumService.cs
Normal file
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.ImportLists.Exclusions;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public interface IAddAlbumService
|
||||
{
|
||||
Album AddAlbum(Album album);
|
||||
List<Album> AddAlbums(List<Album> albums);
|
||||
}
|
||||
|
||||
public class AddAlbumService : IAddAlbumService
|
||||
{
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly IAddArtistService _addArtistService;
|
||||
private readonly IAlbumService _albumService;
|
||||
private readonly IProvideAlbumInfo _albumInfo;
|
||||
private readonly IImportListExclusionService _importListExclusionService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public AddAlbumService(IArtistService artistService,
|
||||
IAddArtistService addArtistService,
|
||||
IAlbumService albumService,
|
||||
IProvideAlbumInfo albumInfo,
|
||||
IImportListExclusionService importListExclusionService,
|
||||
Logger logger)
|
||||
{
|
||||
_artistService = artistService;
|
||||
_addArtistService = addArtistService;
|
||||
_albumService = albumService;
|
||||
_albumInfo = albumInfo;
|
||||
_importListExclusionService = importListExclusionService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Album AddAlbum(Album album)
|
||||
{
|
||||
_logger.Debug($"Adding album {album}");
|
||||
|
||||
album = AddSkyhookData(album);
|
||||
|
||||
// Remove any import list exclusions preventing addition
|
||||
_importListExclusionService.Delete(album.ForeignAlbumId);
|
||||
_importListExclusionService.Delete(album.ArtistMetadata.Value.ForeignArtistId);
|
||||
|
||||
// Note it's a manual addition so it's not deleted on next refresh
|
||||
album.AddOptions.AddType = AlbumAddType.Manual;
|
||||
|
||||
// Add the artist if necessary
|
||||
var dbArtist = _artistService.FindById(album.ArtistMetadata.Value.ForeignArtistId);
|
||||
if (dbArtist == null)
|
||||
{
|
||||
var artist = album.Artist.Value;
|
||||
|
||||
artist.Metadata.Value.ForeignArtistId = album.ArtistMetadata.Value.ForeignArtistId;
|
||||
|
||||
dbArtist = _addArtistService.AddArtist(artist, false);
|
||||
}
|
||||
|
||||
album.ArtistMetadataId = dbArtist.ArtistMetadataId;
|
||||
_albumService.AddAlbum(album);
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
public List<Album> AddAlbums(List<Album> albums)
|
||||
{
|
||||
var added = DateTime.UtcNow;
|
||||
var addedAlbums = new List<Album>();
|
||||
|
||||
foreach (var a in albums)
|
||||
{
|
||||
a.Added = added;
|
||||
addedAlbums.Add(AddAlbum(a));
|
||||
}
|
||||
|
||||
return addedAlbums;
|
||||
}
|
||||
|
||||
private Album AddSkyhookData(Album newAlbum)
|
||||
{
|
||||
Tuple<string, Album, List<ArtistMetadata>> tuple = null;
|
||||
try
|
||||
{
|
||||
tuple = _albumInfo.GetAlbumInfo(newAlbum.ForeignAlbumId);
|
||||
}
|
||||
catch (AlbumNotFoundException)
|
||||
{
|
||||
_logger.Error("Album with MusicBrainz Id {0} was not found, it may have been removed from Musicbrainz.", newAlbum.ForeignAlbumId);
|
||||
|
||||
throw new ValidationException(new List<ValidationFailure>
|
||||
{
|
||||
new ValidationFailure("MusicbrainzId", "An album with this ID was not found", newAlbum.ForeignAlbumId)
|
||||
});
|
||||
}
|
||||
|
||||
newAlbum.UseMetadataFrom(tuple.Item2);
|
||||
newAlbum.Added = DateTime.UtcNow;
|
||||
|
||||
var metadata = tuple.Item3.Single(x => x.ForeignArtistId == tuple.Item1);
|
||||
newAlbum.ArtistMetadata = metadata;
|
||||
|
||||
return newAlbum;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
public interface IAddArtistService
|
||||
{
|
||||
Artist AddArtist(Artist newArtist);
|
||||
Artist AddArtist(Artist newArtist, bool doRefresh = true);
|
||||
List<Artist> AddArtists(List<Artist> newArtists);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace NzbDrone.Core.Music
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
public Artist AddArtist(Artist newArtist)
|
||||
public Artist AddArtist(Artist newArtist, bool doRefresh = true)
|
||||
{
|
||||
Ensure.That(newArtist, () => newArtist).IsNotNull();
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace NzbDrone.Core.Music
|
|||
newArtist.ArtistMetadataId = newArtist.Metadata.Value.Id;
|
||||
|
||||
// add the artist itself
|
||||
_artistService.AddArtist(newArtist);
|
||||
_artistService.AddArtist(newArtist, doRefresh);
|
||||
|
||||
return newArtist;
|
||||
}
|
||||
|
@ -69,7 +69,6 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
foreach (var s in newArtists)
|
||||
{
|
||||
// TODO: Verify if adding skyhook data will be slow
|
||||
try
|
||||
{
|
||||
var artist = AddSkyhookData(s);
|
||||
|
@ -102,20 +101,14 @@ namespace NzbDrone.Core.Music
|
|||
}
|
||||
catch (ArtistNotFoundException)
|
||||
{
|
||||
_logger.Error("LidarrId {0} was not found, it may have been removed from Lidarr.", newArtist.Metadata.Value.ForeignArtistId);
|
||||
_logger.Error("LidarrId {0} was not found, it may have been removed from Musicbrainz.", newArtist.Metadata.Value.ForeignArtistId);
|
||||
|
||||
throw new ValidationException(new List<ValidationFailure>
|
||||
{
|
||||
new ValidationFailure("SpotifyId", "An artist with this ID was not found", newArtist.Metadata.Value.ForeignArtistId)
|
||||
new ValidationFailure("MusicbrainzId", "An artist with this ID was not found", newArtist.Metadata.Value.ForeignArtistId)
|
||||
});
|
||||
}
|
||||
|
||||
// If albums were passed in on the new artist use them, otherwise use the albums from Skyhook
|
||||
if (newArtist.Albums == null || newArtist.Albums.Value == null || !newArtist.Albums.Value.Any())
|
||||
{
|
||||
newArtist.Albums = artist.Albums.Value;
|
||||
}
|
||||
|
||||
artist.ApplyChanges(newArtist);
|
||||
|
||||
return artist;
|
||||
|
@ -130,7 +123,7 @@ namespace NzbDrone.Core.Music
|
|||
}
|
||||
|
||||
newArtist.CleanName = newArtist.Metadata.Value.Name.CleanArtistName();
|
||||
newArtist.SortName = ArtistNameNormalizer.Normalize(newArtist.Metadata.Value.Name, newArtist.Metadata.Value.ForeignArtistId);
|
||||
newArtist.SortName = Parser.Parser.NormalizeTitle(newArtist.Metadata.Value.Name).ToLower();
|
||||
newArtist.Added = DateTime.UtcNow;
|
||||
|
||||
if (newArtist.AddOptions != null && newArtist.AddOptions.Monitor == MonitorTypes.None)
|
|
@ -36,16 +36,25 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
public void SearchForRecentlyAdded(int artistId)
|
||||
{
|
||||
var previouslyReleased = _addedAlbumsCache.Find(artistId.ToString());
|
||||
var allAlbums = _albumService.GetAlbumsByArtist(artistId);
|
||||
var toSearch = allAlbums.Where(x => x.AddOptions.SearchForNewAlbum).ToList();
|
||||
|
||||
if (previouslyReleased != null && previouslyReleased.Any())
|
||||
if (toSearch.Any())
|
||||
{
|
||||
var missing = previouslyReleased.Select(e => _albumService.GetAlbum(e)).ToList();
|
||||
toSearch.ForEach(x => x.AddOptions.SearchForNewAlbum = false);
|
||||
|
||||
if (missing.Any())
|
||||
{
|
||||
_commandQueueManager.Push(new AlbumSearchCommand(missing.Select(e => e.Id).ToList()));
|
||||
}
|
||||
_albumService.SetAddOptions(toSearch);
|
||||
}
|
||||
|
||||
var recentlyAddedIds = _addedAlbumsCache.Find(artistId.ToString());
|
||||
if (recentlyAddedIds != null)
|
||||
{
|
||||
toSearch.AddRange(allAlbums.Where(x => recentlyAddedIds.Contains(x.Id)));
|
||||
}
|
||||
|
||||
if (toSearch.Any())
|
||||
{
|
||||
_commandQueueManager.Push(new AlbumSearchCommand(toSearch.Select(e => e.Id).ToList()));
|
||||
}
|
||||
|
||||
_addedAlbumsCache.Remove(artistId.ToString());
|
|
@ -1,6 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
@ -16,13 +15,11 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
private readonly IAlbumRepository _albumRepository;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public AlbumCutoffService(IAlbumRepository albumRepository, IProfileService profileService, Logger logger)
|
||||
public AlbumCutoffService(IAlbumRepository albumRepository, IProfileService profileService)
|
||||
{
|
||||
_albumRepository = albumRepository;
|
||||
_profileService = profileService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public PagingSpec<Album> AlbumsWhereCutoffUnmet(PagingSpec<Album> pagingSpec)
|
|
@ -1,10 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ namespace NzbDrone.Core.Music
|
|||
var new_monitored = new HashSet<int>(message.Album.AlbumReleases.Value.Where(x => x.Monitored).Select(x => x.Id));
|
||||
var old_monitored = new HashSet<int>(message.OldAlbum.AlbumReleases.Value.Where(x => x.Monitored).Select(x => x.Id));
|
||||
if (!new_monitored.SetEquals(old_monitored) ||
|
||||
(message.OldAlbum.AnyReleaseOk == false && message.Album.AnyReleaseOk == true))
|
||||
(!message.OldAlbum.AnyReleaseOk && message.Album.AnyReleaseOk))
|
||||
{
|
||||
// Unlink any old track files
|
||||
var tracks = _trackService.GetTracksByAlbum(message.Album.Id);
|
|
@ -1,11 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Net.Sockets;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
|
@ -18,14 +14,12 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly IAlbumService _albumService;
|
||||
private readonly ITrackService _trackService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public AlbumMonitoredService(IArtistService artistService, IAlbumService albumService, ITrackService trackService, Logger logger)
|
||||
public AlbumMonitoredService(IArtistService artistService, IAlbumService albumService, Logger logger)
|
||||
{
|
||||
_artistService = artistService;
|
||||
_albumService = albumService;
|
||||
_trackService = trackService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
|
@ -23,8 +23,8 @@ namespace NzbDrone.Core.Music
|
|||
Album FindById(string foreignId);
|
||||
Album FindByTitle(int artistMetadataId, string title);
|
||||
Album FindByTitleInexact(int artistMetadataId, string title);
|
||||
List<Album> GetCandidates(int artistId, string title);
|
||||
void DeleteAlbum(int albumId, bool deleteFiles);
|
||||
List<Album> GetCandidates(int artistMetadataId, string title);
|
||||
void DeleteAlbum(int albumId, bool deleteFiles, bool addImportListExclusion = false);
|
||||
List<Album> GetAllAlbums();
|
||||
Album UpdateAlbum(Album album);
|
||||
void SetAlbumMonitored(int albumId, bool monitored);
|
||||
|
@ -35,7 +35,7 @@ namespace NzbDrone.Core.Music
|
|||
void InsertMany(List<Album> albums);
|
||||
void UpdateMany(List<Album> albums);
|
||||
void DeleteMany(List<Album> albums);
|
||||
void RemoveAddOptions(Album album);
|
||||
void SetAddOptions(IEnumerable<Album> albums);
|
||||
Album FindAlbumByRelease(string albumReleaseId);
|
||||
Album FindAlbumByTrackId(int trackId);
|
||||
List<Album> GetArtistAlbumsWithFiles(Artist artist);
|
||||
|
@ -61,21 +61,22 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
_albumRepository.Insert(newAlbum);
|
||||
|
||||
//_eventAggregator.PublishEvent(new AlbumAddedEvent(GetAlbum(newAlbum.Id)));
|
||||
_eventAggregator.PublishEvent(new AlbumAddedEvent(GetAlbum(newAlbum.Id)));
|
||||
|
||||
return newAlbum;
|
||||
}
|
||||
|
||||
public void DeleteAlbum(int albumId, bool deleteFiles)
|
||||
public void DeleteAlbum(int albumId, bool deleteFiles, bool addImportListExclusion = false)
|
||||
{
|
||||
var album = _albumRepository.Get(albumId);
|
||||
album.Artist.LazyLoad();
|
||||
_albumRepository.Delete(albumId);
|
||||
_eventAggregator.PublishEvent(new AlbumDeletedEvent(album, deleteFiles));
|
||||
_eventAggregator.PublishEvent(new AlbumDeletedEvent(album, deleteFiles, addImportListExclusion));
|
||||
}
|
||||
|
||||
public Album FindById(string lidarrId)
|
||||
public Album FindById(string foreignId)
|
||||
{
|
||||
return _albumRepository.FindById(lidarrId);
|
||||
return _albumRepository.FindById(foreignId);
|
||||
}
|
||||
|
||||
public Album FindByTitle(int artistMetadataId, string title)
|
||||
|
@ -146,7 +147,7 @@ namespace NzbDrone.Core.Music
|
|||
title,
|
||||
string.Join("\n", sortedAlbums.Select(x => $"[{x.Album.Title}] {x.Album.CleanTitle}: {x.MatchProb}")));
|
||||
|
||||
return sortedAlbums.TakeWhile((x, i) => i == 0 ? true : sortedAlbums[i - 1].MatchProb - x.MatchProb < fuzzGap)
|
||||
return sortedAlbums.TakeWhile((x, i) => i == 0 || sortedAlbums[i - 1].MatchProb - x.MatchProb < fuzzGap)
|
||||
.TakeWhile((x, i) => x.MatchProb > fuzzThreshold || (i > 0 && sortedAlbums[i - 1].MatchProb > fuzzThreshold))
|
||||
.Select(x => x.Album)
|
||||
.ToList();
|
||||
|
@ -187,9 +188,9 @@ namespace NzbDrone.Core.Music
|
|||
return _albumRepository.GetAlbumsByArtistMetadataId(artistMetadataId).ToList();
|
||||
}
|
||||
|
||||
public List<Album> GetAlbumsForRefresh(int artistId, IEnumerable<string> foreignIds)
|
||||
public List<Album> GetAlbumsForRefresh(int artistMetadataId, IEnumerable<string> foreignIds)
|
||||
{
|
||||
return _albumRepository.GetAlbumsForRefresh(artistId, foreignIds);
|
||||
return _albumRepository.GetAlbumsForRefresh(artistMetadataId, foreignIds);
|
||||
}
|
||||
|
||||
public Album FindAlbumByRelease(string albumReleaseId)
|
||||
|
@ -202,10 +203,9 @@ namespace NzbDrone.Core.Music
|
|||
return _albumRepository.FindAlbumByTrack(trackId);
|
||||
}
|
||||
|
||||
public void RemoveAddOptions(Album album)
|
||||
public void SetAddOptions(IEnumerable<Album> albums)
|
||||
{
|
||||
var rg = _albumRepository.Get(album.Id);
|
||||
_albumRepository.SetFields(rg, s => s.AddOptions);
|
||||
_albumRepository.SetFields(albums, s => s.AddOptions);
|
||||
}
|
||||
|
||||
public PagingSpec<Album> AlbumsWithoutFiles(PagingSpec<Album> pagingSpec)
|
||||
|
@ -250,7 +250,7 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
foreach (var album in albums)
|
||||
{
|
||||
_eventAggregator.PublishEvent(new AlbumDeletedEvent(album, false));
|
||||
_eventAggregator.PublishEvent(new AlbumDeletedEvent(album, false, false));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
using NLog;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
|
@ -12,13 +11,10 @@ namespace NzbDrone.Core.Music
|
|||
public class ArtistMetadataService : IArtistMetadataService
|
||||
{
|
||||
private readonly IArtistMetadataRepository _artistMetadataRepository;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ArtistMetadataService(IArtistMetadataRepository artistMetadataRepository,
|
||||
Logger logger)
|
||||
public ArtistMetadataService(IArtistMetadataRepository artistMetadataRepository)
|
||||
{
|
||||
_artistMetadataRepository = artistMetadataRepository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool Upsert(ArtistMetadata artist)
|
|
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Core.ImportLists.Exclusions;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
|
@ -16,7 +15,7 @@ namespace NzbDrone.Core.Music
|
|||
Artist GetArtist(int artistId);
|
||||
Artist GetArtistByMetadataId(int artistMetadataId);
|
||||
List<Artist> GetArtists(IEnumerable<int> artistIds);
|
||||
Artist AddArtist(Artist newArtist);
|
||||
Artist AddArtist(Artist newArtist, bool doRefresh);
|
||||
List<Artist> AddArtists(List<Artist> newArtists);
|
||||
Artist FindById(string foreignArtistId);
|
||||
Artist FindByName(string title);
|
||||
|
@ -35,34 +34,28 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
private readonly IArtistRepository _artistRepository;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly ITrackService _trackService;
|
||||
private readonly IImportListExclusionService _importListExclusionService;
|
||||
private readonly IBuildArtistPaths _artistPathBuilder;
|
||||
private readonly Logger _logger;
|
||||
private readonly ICached<List<Artist>> _cache;
|
||||
|
||||
public ArtistService(IArtistRepository artistRepository,
|
||||
IEventAggregator eventAggregator,
|
||||
ITrackService trackService,
|
||||
IImportListExclusionService importListExclusionService,
|
||||
IBuildArtistPaths artistPathBuilder,
|
||||
ICacheManager cacheManager,
|
||||
Logger logger)
|
||||
{
|
||||
_artistRepository = artistRepository;
|
||||
_eventAggregator = eventAggregator;
|
||||
_trackService = trackService;
|
||||
_importListExclusionService = importListExclusionService;
|
||||
_artistPathBuilder = artistPathBuilder;
|
||||
_cache = cacheManager.GetCache<List<Artist>>(GetType());
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Artist AddArtist(Artist newArtist)
|
||||
public Artist AddArtist(Artist newArtist, bool doRefresh)
|
||||
{
|
||||
_cache.Clear();
|
||||
_artistRepository.Insert(newArtist);
|
||||
_eventAggregator.PublishEvent(new ArtistAddedEvent(GetArtist(newArtist.Id)));
|
||||
_eventAggregator.PublishEvent(new ArtistAddedEvent(GetArtist(newArtist.Id), doRefresh));
|
||||
|
||||
return newArtist;
|
||||
}
|
||||
|
@ -166,7 +159,7 @@ namespace NzbDrone.Core.Music
|
|||
title,
|
||||
string.Join("\n", sortedArtists.Select(x => $"[{x.Artist.Name}] {x.Artist.CleanName}: {x.MatchProb}")));
|
||||
|
||||
return sortedArtists.TakeWhile((x, i) => i == 0 ? true : sortedArtists[i - 1].MatchProb - x.MatchProb < fuzzGap)
|
||||
return sortedArtists.TakeWhile((x, i) => i == 0 || sortedArtists[i - 1].MatchProb - x.MatchProb < fuzzGap)
|
||||
.TakeWhile((x, i) => x.MatchProb > fuzzThreshold || (i > 0 && sortedArtists[i - 1].MatchProb > fuzzThreshold))
|
||||
.Select(x => x.Artist)
|
||||
.ToList();
|
||||
|
@ -183,9 +176,9 @@ namespace NzbDrone.Core.Music
|
|||
.ToList();
|
||||
}
|
||||
|
||||
public Artist GetArtist(int artistDBId)
|
||||
public Artist GetArtist(int artistId)
|
||||
{
|
||||
return _artistRepository.Get(artistDBId);
|
||||
return _artistRepository.Get(artistId);
|
||||
}
|
||||
|
||||
public Artist GetArtistByMetadataId(int artistMetadataId)
|
||||
|
@ -226,8 +219,6 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
s.Path = _artistPathBuilder.BuildPath(s, useExistingRelativeFolder);
|
||||
|
||||
//s.Path = Path.Combine(s.RootFolderPath, _fileNameBuilder.GetArtistFolder(s));
|
||||
|
||||
_logger.Trace("Changing path for {0} to {1}", s.Name, s.Path);
|
||||
}
|
||||
else
|
|
@ -5,7 +5,6 @@ using NzbDrone.Common.Instrumentation.Extensions;
|
|||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Music.Commands;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
|
@ -18,22 +17,17 @@ namespace NzbDrone.Core.Music
|
|||
private readonly IReleaseService _releaseService;
|
||||
private readonly IRefreshTrackService _refreshTrackService;
|
||||
private readonly ITrackService _trackService;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RefreshAlbumReleaseService(IReleaseService releaseService,
|
||||
IArtistMetadataService artistMetadataService,
|
||||
IRefreshTrackService refreshTrackService,
|
||||
ITrackService trackService,
|
||||
IMediaFileService mediaFileService,
|
||||
Logger logger)
|
||||
: base(logger, artistMetadataService)
|
||||
{
|
||||
_releaseService = releaseService;
|
||||
_trackService = trackService;
|
||||
_refreshTrackService = refreshTrackService;
|
||||
_mediaFileService = mediaFileService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override RemoteData GetRemoteData(AlbumRelease local, List<AlbumRelease> remote)
|
|
@ -1,18 +1,18 @@
|
|||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation.Extensions;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Music.Commands;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.Music.Commands;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
|
@ -130,7 +130,9 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
protected override bool ShouldDelete(Album local)
|
||||
{
|
||||
return !_mediaFileService.GetFilesByAlbum(local.Id).Any();
|
||||
// not manually added and has no files
|
||||
return local.AddOptions.AddType != AlbumAddType.Manual &&
|
||||
!_mediaFileService.GetFilesByAlbum(local.Id).Any();
|
||||
}
|
||||
|
||||
protected override void LogProgress(Album local)
|
||||
|
@ -146,7 +148,9 @@ namespace NzbDrone.Core.Music
|
|||
protected override UpdateResult UpdateEntity(Album local, Album remote)
|
||||
{
|
||||
UpdateResult result;
|
||||
|
||||
|
||||
remote.UseDbFieldsFrom(local);
|
||||
|
||||
if (local.Title != (remote.Title ?? "Unknown") ||
|
||||
local.ForeignAlbumId != remote.ForeignAlbumId ||
|
||||
local.ArtistMetadata.Value.ForeignArtistId != remote.ArtistMetadata.Value.ForeignArtistId)
|
||||
|
@ -302,6 +306,12 @@ namespace NzbDrone.Core.Music
|
|||
return _refreshAlbumReleaseService.RefreshEntityInfo(refreshList, remoteChildren, forceChildRefresh, forceUpdateFileTags);
|
||||
}
|
||||
|
||||
protected override void PublishEntityUpdatedEvent(Album entity)
|
||||
{
|
||||
// Fetch fresh from DB so all lazy loads are available
|
||||
_eventAggregator.PublishEvent(new AlbumUpdatedEvent(_albumService.GetAlbum(entity.Id)));
|
||||
}
|
||||
|
||||
public bool RefreshAlbumInfo(List<Album> albums, List<Album> remoteAlbums, bool forceAlbumRefresh, bool forceUpdateFileTags)
|
||||
{
|
||||
bool updated = false;
|
||||
|
@ -330,6 +340,7 @@ namespace NzbDrone.Core.Music
|
|||
if (updated)
|
||||
{
|
||||
_eventAggregator.PublishEvent(new ArtistUpdatedEvent(artist));
|
||||
_eventAggregator.PublishEvent(new AlbumUpdatedEvent(album));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -193,7 +193,10 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
protected override List<Album> GetRemoteChildren(Artist remote)
|
||||
{
|
||||
return remote.Albums.Value.DistinctBy(m => m.ForeignAlbumId).ToList();
|
||||
var all = remote.Albums.Value.DistinctBy(m => m.ForeignAlbumId).ToList();
|
||||
var ids = all.SelectMany(x => x.OldForeignAlbumIds.Concat(new List<string> { x.ForeignAlbumId })).ToList();
|
||||
var excluded = _importListExclusionService.FindByForeignId(ids).Select(x => x.ForeignId).ToList();
|
||||
return all.Where(x => !excluded.Contains(x.ForeignAlbumId) && !x.OldForeignAlbumIds.Any(y => excluded.Contains(y))).ToList();
|
||||
}
|
||||
|
||||
protected override List<Album> GetLocalChildren(Artist entity, List<Album> remoteChildren)
|
||||
|
@ -235,7 +238,7 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
protected override bool RefreshChildren(SortedChildren localChildren, List<Album> remoteChildren, bool forceChildRefresh, bool forceUpdateFileTags)
|
||||
{
|
||||
// we always want to end up refreshing the albums since we don't get have proper data
|
||||
// we always want to end up refreshing the albums since we don't yet have proper data
|
||||
Ensure.That(localChildren.UpToDate.Count, () => localChildren.UpToDate.Count).IsLessThanOrEqualTo(0);
|
||||
return _refreshAlbumService.RefreshAlbumInfo(localChildren.All, remoteChildren, forceChildRefresh, forceUpdateFileTags);
|
||||
}
|
|
@ -11,8 +11,8 @@ namespace NzbDrone.Core.Music
|
|||
private readonly Logger _logger;
|
||||
private readonly IArtistMetadataService _artistMetadataService;
|
||||
|
||||
public RefreshEntityServiceBase(Logger logger,
|
||||
IArtistMetadataService artistMetadataService)
|
||||
protected RefreshEntityServiceBase(Logger logger,
|
||||
IArtistMetadataService artistMetadataService)
|
||||
{
|
||||
_logger = logger;
|
||||
_artistMetadataService = artistMetadataService;
|
||||
|
@ -61,7 +61,6 @@ namespace NzbDrone.Core.Music
|
|||
|
||||
protected virtual void EnsureNewParent(Entity local, Entity remote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
protected abstract bool IsMerge(Entity local, Entity remote);
|
||||
|
@ -92,8 +91,8 @@ namespace NzbDrone.Core.Music
|
|||
protected abstract List<Child> GetLocalChildren(Entity entity, List<Child> remoteChildren);
|
||||
protected abstract Tuple<Child, List<Child> > GetMatchingExistingChildren(List<Child> existingChildren, Child remote);
|
||||
|
||||
protected abstract void PrepareNewChild(Child remoteChild, Entity entity);
|
||||
protected abstract void PrepareExistingChild(Child existingChild, Child remoteChild, Entity entity);
|
||||
protected abstract void PrepareNewChild(Child child, Entity entity);
|
||||
protected abstract void PrepareExistingChild(Child local, Child remote, Entity entity);
|
||||
protected abstract void AddChildren(List<Child> children);
|
||||
protected abstract bool RefreshChildren(SortedChildren localChildren, List<Child> remoteChildren, bool forceChildRefresh, bool forceUpdateFileTags);
|
||||
|
||||
|
@ -196,13 +195,6 @@ namespace NzbDrone.Core.Music
|
|||
return updated;
|
||||
}
|
||||
|
||||
public UpdateResult UpdateArtistMetadata(List<ArtistMetadata> data)
|
||||
{
|
||||
var remoteMetadata = data.DistinctBy(x => x.ForeignArtistId).ToList();
|
||||
var updated = _artistMetadataService.UpsertMany(data);
|
||||
return updated ? UpdateResult.UpdateTags : UpdateResult.None;
|
||||
}
|
||||
|
||||
public bool RefreshEntityInfo(List<Entity> localList, List<Entity> remoteList, bool forceChildRefresh, bool forceUpdateFileTags)
|
||||
{
|
||||
bool updated = false;
|
||||
|
@ -213,6 +205,13 @@ namespace NzbDrone.Core.Music
|
|||
return updated;
|
||||
}
|
||||
|
||||
public UpdateResult UpdateArtistMetadata(List<ArtistMetadata> data)
|
||||
{
|
||||
var remoteMetadata = data.DistinctBy(x => x.ForeignArtistId).ToList();
|
||||
var updated = _artistMetadataService.UpsertMany(remoteMetadata);
|
||||
return updated ? UpdateResult.UpdateTags : UpdateResult.None;
|
||||
}
|
||||
|
||||
protected bool SortChildren(Entity entity, List<Child> remoteChildren, bool forceChildRefresh, bool forceUpdateFileTags)
|
||||
{
|
||||
// Get existing children (and children to be) from the database
|
|
@ -69,7 +69,7 @@ namespace NzbDrone.Core.Music
|
|||
}
|
||||
_audioTagService.SyncTags(tagsToUpdate);
|
||||
|
||||
return delete.Any() || updateList.Any() || merge.Any();
|
||||
return add.Any() || delete.Any() || updateList.Any() || merge.Any();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using NLog;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
|
@ -33,13 +32,12 @@ namespace NzbDrone.Core.Music
|
|||
IHandle<TrackFileDeletedEvent>
|
||||
{
|
||||
private readonly ITrackRepository _trackRepository;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public TrackService(ITrackRepository trackRepository, IConfigService configService, Logger logger)
|
||||
public TrackService(ITrackRepository trackRepository,
|
||||
Logger logger)
|
||||
{
|
||||
_trackRepository = trackRepository;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
|
@ -1,6 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Indexers;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
|
|
|
@ -5,6 +5,8 @@ using NzbDrone.Core.Music;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.ImportLists;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using System;
|
||||
|
||||
namespace NzbDrone.Core.Profiles.Metadata
|
||||
{
|
||||
|
@ -20,6 +22,7 @@ namespace NzbDrone.Core.Profiles.Metadata
|
|||
|
||||
public class MetadataProfileService : IMetadataProfileService, IHandle<ApplicationStartedEvent>
|
||||
{
|
||||
public const string NONE_PROFILE_NAME = "None";
|
||||
private readonly IMetadataProfileRepository _profileRepository;
|
||||
private readonly IArtistService _artistService;
|
||||
private readonly IImportListFactory _importListFactory;
|
||||
|
@ -43,14 +46,22 @@ namespace NzbDrone.Core.Profiles.Metadata
|
|||
|
||||
public void Update(MetadataProfile profile)
|
||||
{
|
||||
if (profile.Name == NONE_PROFILE_NAME)
|
||||
{
|
||||
throw new InvalidOperationException("Not permitted to alter None metadata profile");
|
||||
}
|
||||
|
||||
_profileRepository.Update(profile);
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
if (_artistService.GetAllArtists().Any(c => c.MetadataProfileId == id) || _importListFactory.All().Any(c => c.MetadataProfileId == id))
|
||||
var profile = _profileRepository.Get(id);
|
||||
|
||||
if (profile.Name == NONE_PROFILE_NAME ||
|
||||
_artistService.GetAllArtists().Any(c => c.MetadataProfileId == id) ||
|
||||
_importListFactory.All().Any(c => c.MetadataProfileId == id))
|
||||
{
|
||||
var profile = _profileRepository.Get(id);
|
||||
throw new MetadataProfileInUseException(profile.Name);
|
||||
}
|
||||
|
||||
|
@ -102,14 +113,48 @@ namespace NzbDrone.Core.Profiles.Metadata
|
|||
|
||||
public void Handle(ApplicationStartedEvent message)
|
||||
{
|
||||
if (All().Any())
|
||||
var profiles = All();
|
||||
|
||||
// Name is a unique property
|
||||
var emptyProfile = profiles.FirstOrDefault(x => x.Name == NONE_PROFILE_NAME);
|
||||
|
||||
// make sure empty profile exists and is actually empty
|
||||
if (emptyProfile != null &&
|
||||
!emptyProfile.PrimaryAlbumTypes.Any(x => x.Allowed) &&
|
||||
!emptyProfile.SecondaryAlbumTypes.Any(x => x.Allowed) &&
|
||||
!emptyProfile.ReleaseStatuses.Any(x => x.Allowed))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Info("Setting up default metadata profile");
|
||||
if (!profiles.Any())
|
||||
{
|
||||
_logger.Info("Setting up standard metadata profile");
|
||||
|
||||
AddDefaultProfile("Standard", new List<PrimaryAlbumType>{PrimaryAlbumType.Album}, new List<SecondaryAlbumType>{ SecondaryAlbumType.Studio }, new List<ReleaseStatus>{ReleaseStatus.Official});
|
||||
AddDefaultProfile("Standard", new List<PrimaryAlbumType>{PrimaryAlbumType.Album}, new List<SecondaryAlbumType>{ SecondaryAlbumType.Studio }, new List<ReleaseStatus>{ReleaseStatus.Official});
|
||||
}
|
||||
|
||||
if (emptyProfile != null)
|
||||
{
|
||||
// emptyProfile is not the correct empty profile - move it out of the way
|
||||
_logger.Info($"Renaming non-empty metadata profile {emptyProfile.Name}");
|
||||
|
||||
var names = profiles.Select(x => x.Name).ToList();
|
||||
|
||||
int i = 1;
|
||||
emptyProfile.Name = $"{NONE_PROFILE_NAME}.{i}";
|
||||
|
||||
while (names.Contains(emptyProfile.Name))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
_profileRepository.Update(emptyProfile);
|
||||
}
|
||||
|
||||
_logger.Info("Setting up empty metadata profile");
|
||||
|
||||
AddDefaultProfile(NONE_PROFILE_NAME, new List<PrimaryAlbumType>(), new List<SecondaryAlbumType>(), new List<ReleaseStatus>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace NzbDrone.Core.Validation
|
|||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
if (context.PropertyValue == null) return true;
|
||||
if ((int)context.PropertyValue == 0) return true;
|
||||
|
||||
return _profileService.Exists((int)context.PropertyValue);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue