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.
45 lines
1.3 KiB
45 lines
1.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NLog;
|
|
|
|
namespace NzbDrone.Core.Music
|
|
{
|
|
public interface IMonitorNewAlbumService
|
|
{
|
|
bool ShouldMonitorNewAlbum(Album addedAlbum, List<Album> existingAlbums, NewItemMonitorTypes monitorNewItems);
|
|
}
|
|
|
|
public class MonitorNewAlbumService : IMonitorNewAlbumService
|
|
{
|
|
private readonly Logger _logger;
|
|
|
|
public MonitorNewAlbumService(Logger logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public bool ShouldMonitorNewAlbum(Album addedAlbum, List<Album> existingAlbums, NewItemMonitorTypes monitorNewItems)
|
|
{
|
|
if (monitorNewItems == NewItemMonitorTypes.None)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (monitorNewItems == NewItemMonitorTypes.All)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (monitorNewItems == NewItemMonitorTypes.New)
|
|
{
|
|
var newest = existingAlbums.MaxBy(x => x.ReleaseDate ?? DateTime.MinValue)?.ReleaseDate ?? DateTime.MinValue;
|
|
|
|
return (addedAlbum.ReleaseDate ?? DateTime.MinValue) >= newest;
|
|
}
|
|
|
|
throw new NotImplementedException($"Unknown new item monitor type {monitorNewItems}");
|
|
}
|
|
}
|
|
}
|