mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-08 05:51:47 -07:00
Added: Additional Album Monitoring Options
This commit is contained in:
parent
af090c7a3a
commit
f9fb33eb08
10 changed files with 102 additions and 95 deletions
|
@ -4,11 +4,11 @@ import SelectInput from './SelectInput';
|
||||||
|
|
||||||
const monitorOptions = [
|
const monitorOptions = [
|
||||||
{ key: 'all', value: 'All Albums' },
|
{ key: 'all', value: 'All Albums' },
|
||||||
// { key: 'future', value: 'Future Albums' },
|
{ key: 'future', value: 'Future Albums' },
|
||||||
// { key: 'missing', value: 'Missing Albums' },
|
{ key: 'missing', value: 'Missing Albums' },
|
||||||
// { key: 'existing', value: 'Existing Albums' },
|
{ key: 'existing', value: 'Existing Albums' },
|
||||||
// { key: 'first', value: 'Only First Album' },
|
{ key: 'first', value: 'Only First Album' },
|
||||||
// { key: 'latest', value: 'Only Latest Album' },
|
{ key: 'latest', value: 'Only Latest Album' },
|
||||||
{ key: 'none', value: 'None' }
|
{ key: 'none', value: 'None' }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -2,26 +2,32 @@ import _ from 'lodash';
|
||||||
|
|
||||||
function getMonitoringOptions(monitor) {
|
function getMonitoringOptions(monitor) {
|
||||||
const monitoringOptions = {
|
const monitoringOptions = {
|
||||||
ignoreAlbumsWithFiles: false,
|
selectedOption: 0,
|
||||||
ignoreAlbumsWithoutFiles: false,
|
|
||||||
monitored: true
|
monitored: true
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (monitor) {
|
switch (monitor) {
|
||||||
case 'future':
|
case 'future':
|
||||||
monitoringOptions.ignoreAlbumsWithFiles = true;
|
monitoringOptions.selectedOption = 1;
|
||||||
monitoringOptions.ignoreAlbumsWithoutFiles = true;
|
|
||||||
break;
|
break;
|
||||||
case 'missing':
|
case 'missing':
|
||||||
monitoringOptions.ignoreAlbumsWithFiles = true;
|
monitoringOptions.selectedOption = 2;
|
||||||
break;
|
break;
|
||||||
case 'existing':
|
case 'existing':
|
||||||
monitoringOptions.ignoreAlbumsWithoutFiles = true;
|
monitoringOptions.selectedOption = 3;
|
||||||
|
break;
|
||||||
|
case 'first':
|
||||||
|
monitoringOptions.selectedOption = 5;
|
||||||
|
break;
|
||||||
|
case 'latest':
|
||||||
|
monitoringOptions.selectedOption = 4;
|
||||||
break;
|
break;
|
||||||
case 'none':
|
case 'none':
|
||||||
monitoringOptions.monitored = false;
|
monitoringOptions.monitored = false;
|
||||||
|
monitoringOptions.selectedOption = 6;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
monitoringOptions.selectedOption = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,10 @@ namespace NzbDrone.Core.Test.MusicTests.AlbumMonitoredServiceTests
|
||||||
.Setup(s => s.GetAlbumsByArtist(It.IsAny<int>()))
|
.Setup(s => s.GetAlbumsByArtist(It.IsAny<int>()))
|
||||||
.Returns(_albums);
|
.Returns(_albums);
|
||||||
|
|
||||||
|
Mocker.GetMock<IAlbumService>()
|
||||||
|
.Setup(s => s.GetArtistAlbumsWithFiles(It.IsAny<Artist>()))
|
||||||
|
.Returns(new List<Album>());
|
||||||
|
|
||||||
Mocker.GetMock<ITrackService>()
|
Mocker.GetMock<ITrackService>()
|
||||||
.Setup(s => s.GetTracksByAlbum(It.IsAny<int>()))
|
.Setup(s => s.GetTracksByAlbum(It.IsAny<int>()))
|
||||||
.Returns(new List<Track>());
|
.Returns(new List<Track>());
|
||||||
|
@ -83,13 +87,11 @@ namespace NzbDrone.Core.Test.MusicTests.AlbumMonitoredServiceTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Ignore("Not Implemented Yet")]
|
|
||||||
public void should_be_able_to_monitor_new_albums_only()
|
public void should_be_able_to_monitor_new_albums_only()
|
||||||
{
|
{
|
||||||
var monitoringOptions = new MonitoringOptions
|
var monitoringOptions = new MonitoringOptions
|
||||||
{
|
{
|
||||||
IgnoreAlbumsWithFiles = true,
|
SelectedOption = MonitoringOption.Future
|
||||||
IgnoreAlbumsWithoutFiles = true
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Subject.SetAlbumMonitoredStatus(_artist, monitoringOptions);
|
Subject.SetAlbumMonitoredStatus(_artist, monitoringOptions);
|
||||||
|
|
|
@ -106,7 +106,7 @@ namespace NzbDrone.Core.ImportLists
|
||||||
LanguageProfileId = importList.LanguageProfileId,
|
LanguageProfileId = importList.LanguageProfileId,
|
||||||
MetadataProfileId = importList.MetadataProfileId,
|
MetadataProfileId = importList.MetadataProfileId,
|
||||||
AlbumFolder = true,
|
AlbumFolder = true,
|
||||||
AddOptions = new AddArtistOptions{SearchForMissingAlbums = true, Monitored = importList.ShouldMonitor }
|
AddOptions = new AddArtistOptions{SearchForMissingAlbums = true, Monitored = importList.ShouldMonitor, SelectedOption = 0}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Net.Sockets;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Datastore;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Music
|
namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
|
@ -34,8 +37,13 @@ namespace NzbDrone.Core.Music
|
||||||
|
|
||||||
var albums = _albumService.GetAlbumsByArtist(artist.Id);
|
var albums = _albumService.GetAlbumsByArtist(artist.Id);
|
||||||
|
|
||||||
|
var albumsWithFiles = _albumService.GetArtistAlbumsWithFiles(artist);
|
||||||
|
|
||||||
|
var albumsWithoutFiles = albums.Where(c => !albumsWithFiles.Select(e => e.Id).Contains(c.Id) && c.ReleaseDate <= DateTime.UtcNow).ToList();
|
||||||
|
|
||||||
var monitoredAlbums = monitoringOptions.AlbumsToMonitor;
|
var monitoredAlbums = monitoringOptions.AlbumsToMonitor;
|
||||||
|
|
||||||
|
// If specific albums are passed use those instead of the monitoring options.
|
||||||
if (monitoredAlbums.Any())
|
if (monitoredAlbums.Any())
|
||||||
{
|
{
|
||||||
ToggleAlbumsMonitoredState(
|
ToggleAlbumsMonitoredState(
|
||||||
|
@ -45,11 +53,45 @@ namespace NzbDrone.Core.Music
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ToggleAlbumsMonitoredState(albums, monitoringOptions.Monitored);
|
switch (monitoringOptions.SelectedOption)
|
||||||
|
{
|
||||||
|
case MonitoringOption.All:
|
||||||
|
ToggleAlbumsMonitoredState(albums, true);
|
||||||
|
break;
|
||||||
|
case MonitoringOption.Future:
|
||||||
|
_logger.Debug("Unmonitoring Albums with Files");
|
||||||
|
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), false);
|
||||||
|
_logger.Debug("Unmonitoring Albums without Files");
|
||||||
|
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), false);
|
||||||
|
break;
|
||||||
|
case MonitoringOption.None:
|
||||||
|
ToggleAlbumsMonitoredState(albums, false);
|
||||||
|
break;
|
||||||
|
case MonitoringOption.Missing:
|
||||||
|
_logger.Debug("Unmonitoring Albums with Files");
|
||||||
|
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), false);
|
||||||
|
_logger.Debug("Monitoring Albums without Files");
|
||||||
|
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), true);
|
||||||
|
break;
|
||||||
|
case MonitoringOption.Existing:
|
||||||
|
_logger.Debug("Monitoring Albums with Files");
|
||||||
|
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), true);
|
||||||
|
_logger.Debug("Unmonitoring Albums without Files");
|
||||||
|
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), false);
|
||||||
|
break;
|
||||||
|
case MonitoringOption.Latest:
|
||||||
|
ToggleAlbumsMonitoredState(albums, false);
|
||||||
|
ToggleAlbumsMonitoredState(albums.OrderByDescending(e=>e.ReleaseDate).Take(1),true);
|
||||||
|
break;
|
||||||
|
case MonitoringOption.First:
|
||||||
|
ToggleAlbumsMonitoredState(albums, false);
|
||||||
|
ToggleAlbumsMonitoredState(albums.OrderBy(e => e.ReleaseDate).Take(1), true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Add Other Options for Future/Exisitng/Missing Once we have a good way to check for Album Related Files.
|
|
||||||
|
|
||||||
_albumService.UpdateAlbums(albums);
|
_albumService.UpdateAlbums(albums);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace NzbDrone.Core.Music
|
||||||
void SetMonitoredFlat(Album album, bool monitored);
|
void SetMonitoredFlat(Album album, bool monitored);
|
||||||
void SetMonitored(IEnumerable<int> ids, bool monitored);
|
void SetMonitored(IEnumerable<int> ids, bool monitored);
|
||||||
Album FindAlbumByRelease(string releaseId);
|
Album FindAlbumByRelease(string releaseId);
|
||||||
|
List<Album> GetArtistAlbumsWithFiles(Artist artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AlbumRepository : BasicRepository<Album>, IAlbumRepository
|
public class AlbumRepository : BasicRepository<Album>, IAlbumRepository
|
||||||
|
@ -307,5 +308,19 @@ namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
return Query.FirstOrDefault(e => e.Releases.Any(r => r.Id == releaseId));
|
return Query.FirstOrDefault(e => e.Releases.Any(r => r.Id == releaseId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Album> GetArtistAlbumsWithFiles(Artist artist)
|
||||||
|
{
|
||||||
|
string query = string.Format("SELECT Albums.* FROM (SELECT Tracks.AlbumId, COUNT(*) AS TotalTrackCount," + "" +
|
||||||
|
"SUM(CASE WHEN TrackFileId > 0 THEN 1 ELSE 0 END) AS AvailableTrackCount FROM Tracks GROUP BY Tracks.ArtistId, Tracks.AlbumId) as Tracks" +
|
||||||
|
" LEFT OUTER JOIN Albums ON Tracks.AlbumId == Albums.Id" +
|
||||||
|
" LEFT OUTER JOIN Artists ON Albums.ArtistId == Artists.Id" +
|
||||||
|
" WHERE Tracks.AvailableTrackCount > 0" +
|
||||||
|
" AND Albums.ArtistId=" + artist.Id +
|
||||||
|
" GROUP BY Tracks.AlbumId");
|
||||||
|
|
||||||
|
return Query.QueryText(query);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace NzbDrone.Core.Music
|
||||||
void DeleteMany(List<Album> albums);
|
void DeleteMany(List<Album> albums);
|
||||||
void RemoveAddOptions(Album album);
|
void RemoveAddOptions(Album album);
|
||||||
Album FindAlbumByRelease(string releaseId);
|
Album FindAlbumByRelease(string releaseId);
|
||||||
|
List<Album> GetArtistAlbumsWithFiles(Artist artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AlbumService : IAlbumService,
|
public class AlbumService : IAlbumService,
|
||||||
|
@ -142,6 +143,11 @@ namespace NzbDrone.Core.Music
|
||||||
return albums;
|
return albums;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Album> GetArtistAlbumsWithFiles(Artist artist)
|
||||||
|
{
|
||||||
|
return _albumRepository.GetArtistAlbumsWithFiles(artist);
|
||||||
|
}
|
||||||
|
|
||||||
public void InsertMany(List<Album> albums)
|
public void InsertMany(List<Album> albums)
|
||||||
{
|
{
|
||||||
_albumRepository.InsertMany(albums);
|
_albumRepository.InsertMany(albums);
|
||||||
|
|
|
@ -10,9 +10,19 @@ namespace NzbDrone.Core.Music
|
||||||
AlbumsToMonitor = new List<string>();
|
AlbumsToMonitor = new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IgnoreAlbumsWithFiles { get; set; }
|
public MonitoringOption SelectedOption { get; set; }
|
||||||
public bool IgnoreAlbumsWithoutFiles { get; set; }
|
|
||||||
public List<string> AlbumsToMonitor { get; set; }
|
public List<string> AlbumsToMonitor { get; set; }
|
||||||
public bool Monitored { get; set; }
|
public bool Monitored { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum MonitoringOption
|
||||||
|
{
|
||||||
|
All = 0,
|
||||||
|
Future = 1,
|
||||||
|
Missing = 2,
|
||||||
|
Existing = 3,
|
||||||
|
Latest = 4,
|
||||||
|
First = 5,
|
||||||
|
None = 6
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using NLog;
|
|
||||||
using NzbDrone.Common.Extensions;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Music
|
|
||||||
{
|
|
||||||
public interface ITrackMonitoredService
|
|
||||||
{
|
|
||||||
void SetTrackMonitoredStatus(Artist album, MonitoringOptions monitoringOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TrackMonitoredService : ITrackMonitoredService
|
|
||||||
{
|
|
||||||
private readonly IArtistService _albumService;
|
|
||||||
private readonly ITrackService _trackService;
|
|
||||||
private readonly Logger _logger;
|
|
||||||
|
|
||||||
public TrackMonitoredService(IArtistService albumService, ITrackService trackService, Logger logger)
|
|
||||||
{
|
|
||||||
_albumService = albumService;
|
|
||||||
_trackService = trackService;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetTrackMonitoredStatus(Artist album, MonitoringOptions monitoringOptions)
|
|
||||||
{
|
|
||||||
if (monitoringOptions != null)
|
|
||||||
{
|
|
||||||
_logger.Debug("[{0}] Setting track monitored status.", album.Name);
|
|
||||||
|
|
||||||
var tracks = _trackService.GetTracksByArtist(album.Id);
|
|
||||||
|
|
||||||
if (monitoringOptions.IgnoreAlbumsWithFiles)
|
|
||||||
{
|
|
||||||
_logger.Debug("Ignoring Tracks with Files");
|
|
||||||
ToggleTracksMonitoredState(tracks.Where(e => e.HasFile), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Debug("Monitoring Tracks with Files");
|
|
||||||
ToggleTracksMonitoredState(tracks.Where(e => e.HasFile), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (monitoringOptions.IgnoreAlbumsWithoutFiles)
|
|
||||||
{
|
|
||||||
_logger.Debug("Ignoring Tracks without Files");
|
|
||||||
ToggleTracksMonitoredState(tracks.Where(e => !e.HasFile), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.Debug("Monitoring Episodes without Files");
|
|
||||||
ToggleTracksMonitoredState(tracks.Where(e => !e.HasFile), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
_trackService.UpdateTracks(tracks);
|
|
||||||
}
|
|
||||||
|
|
||||||
_albumService.UpdateArtist(album);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ToggleTracksMonitoredState(IEnumerable<Track> tracks, bool monitored)
|
|
||||||
{
|
|
||||||
foreach (var track in tracks)
|
|
||||||
{
|
|
||||||
track.Monitored = monitored;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -829,7 +829,6 @@
|
||||||
<Compile Include="Music\ArtistScannedHandler.cs" />
|
<Compile Include="Music\ArtistScannedHandler.cs" />
|
||||||
<Compile Include="Music\ArtistEditedService.cs" />
|
<Compile Include="Music\ArtistEditedService.cs" />
|
||||||
<Compile Include="Music\ShouldRefreshAlbum.cs" />
|
<Compile Include="Music\ShouldRefreshAlbum.cs" />
|
||||||
<Compile Include="Music\TrackMonitoredService.cs" />
|
|
||||||
<Compile Include="Music\Member.cs" />
|
<Compile Include="Music\Member.cs" />
|
||||||
<Compile Include="Music\AddArtistOptions.cs" />
|
<Compile Include="Music\AddArtistOptions.cs" />
|
||||||
<Compile Include="Music\AddArtistService.cs" />
|
<Compile Include="Music\AddArtistService.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue