2017-09-04 02:20:56 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using Nancy;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Core.Music;
|
|
|
|
using Lidarr.Http.Extensions;
|
|
|
|
|
2017-10-31 01:28:29 +00:00
|
|
|
namespace Lidarr.Api.V1.Artist
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2017-10-31 01:28:29 +00:00
|
|
|
public class ArtistEditorModule : LidarrV1Module
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
private readonly IArtistService _artistService;
|
|
|
|
|
|
|
|
public ArtistEditorModule(IArtistService artistService)
|
|
|
|
: base("/artist/editor")
|
|
|
|
{
|
|
|
|
_artistService = artistService;
|
|
|
|
Put["/"] = artist => SaveAll();
|
2017-10-22 05:25:59 +00:00
|
|
|
Delete["/"] = artist => DeleteArtist();
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private Response SaveAll()
|
|
|
|
{
|
|
|
|
var resource = Request.Body.FromJson<ArtistEditorResource>();
|
|
|
|
var artistToUpdate = _artistService.GetArtists(resource.ArtistIds);
|
|
|
|
|
|
|
|
foreach (var artist in artistToUpdate)
|
|
|
|
{
|
|
|
|
if (resource.Monitored.HasValue)
|
|
|
|
{
|
|
|
|
artist.Monitored = resource.Monitored.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource.QualityProfileId.HasValue)
|
|
|
|
{
|
|
|
|
artist.ProfileId = resource.QualityProfileId.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource.AlbumFolder.HasValue)
|
|
|
|
{
|
|
|
|
artist.AlbumFolder = resource.AlbumFolder.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource.RootFolderPath.IsNotNullOrWhiteSpace())
|
|
|
|
{
|
|
|
|
artist.RootFolderPath = resource.RootFolderPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource.Tags != null)
|
|
|
|
{
|
|
|
|
var newTags = resource.Tags;
|
|
|
|
var applyTags = resource.ApplyTags;
|
|
|
|
|
|
|
|
switch (applyTags)
|
|
|
|
{
|
|
|
|
case ApplyTags.Add:
|
|
|
|
newTags.ForEach(t => artist.Tags.Add(t));
|
|
|
|
break;
|
|
|
|
case ApplyTags.Remove:
|
|
|
|
newTags.ForEach(t => artist.Tags.Remove(t));
|
|
|
|
break;
|
|
|
|
case ApplyTags.Replace:
|
|
|
|
artist.Tags = new HashSet<int>(newTags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _artistService.UpdateArtists(artistToUpdate)
|
|
|
|
.ToResource()
|
|
|
|
.AsResponse(HttpStatusCode.Accepted);
|
|
|
|
}
|
|
|
|
|
2017-10-22 05:25:59 +00:00
|
|
|
private Response DeleteArtist()
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
var resource = Request.Body.FromJson<ArtistEditorResource>();
|
|
|
|
|
|
|
|
foreach (var artistId in resource.ArtistIds)
|
|
|
|
{
|
|
|
|
_artistService.DeleteArtist(artistId, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new object().AsResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|