You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
48 lines
1.5 KiB
using System.Linq;
|
|
using Lidarr.Http.Extensions;
|
|
using Nancy;
|
|
using NzbDrone.Core.Music;
|
|
|
|
namespace Lidarr.Api.V1.AlbumStudio
|
|
{
|
|
public class AlbumStudioModule : LidarrV1Module
|
|
{
|
|
private readonly IArtistService _artistService;
|
|
private readonly IAlbumMonitoredService _albumMonitoredService;
|
|
|
|
public AlbumStudioModule(IArtistService artistService, IAlbumMonitoredService albumMonitoredService)
|
|
: base("/albumstudio")
|
|
{
|
|
_artistService = artistService;
|
|
_albumMonitoredService = albumMonitoredService;
|
|
Post("/", artist => UpdateAll());
|
|
}
|
|
|
|
private object UpdateAll()
|
|
{
|
|
//Read from request
|
|
var request = Request.Body.FromJson<AlbumStudioResource>();
|
|
var artistToUpdate = _artistService.GetArtists(request.Artist.Select(s => s.Id));
|
|
|
|
foreach (var s in request.Artist)
|
|
{
|
|
var artist = artistToUpdate.Single(c => c.Id == s.Id);
|
|
|
|
if (s.Monitored.HasValue)
|
|
{
|
|
artist.Monitored = s.Monitored.Value;
|
|
}
|
|
|
|
if (request.MonitoringOptions != null && request.MonitoringOptions.Monitor == MonitorTypes.None)
|
|
{
|
|
artist.Monitored = false;
|
|
}
|
|
|
|
_albumMonitoredService.SetAlbumMonitoredStatus(artist, request.MonitoringOptions);
|
|
}
|
|
|
|
return ResponseWithCode("ok", HttpStatusCode.Accepted);
|
|
}
|
|
}
|
|
}
|