mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-20 21:54:25 -04:00
New: Add/remove individual albums
This commit is contained in:
@@ -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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user