1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-24 16:51:58 +00:00

New: Search for newly added past albums after artist is refreshed

Fixes #195
This commit is contained in:
Qstick 2018-03-19 21:56:05 -04:00
parent b03b3d8243
commit 221c670bf9
5 changed files with 91 additions and 30 deletions

View file

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Music.Events;
namespace NzbDrone.Core.Music
{
public interface IAlbumAddedService
{
void SearchForRecentlyAdded(int artistId);
}
public class AlbumAddedService : IHandle<AlbumInfoRefreshedEvent>, IAlbumAddedService
{
private readonly IManageCommandQueue _commandQueueManager;
private readonly IAlbumService _albumService;
private readonly Logger _logger;
private readonly ICached<List<int>> _addedAlbumsCache;
public AlbumAddedService(ICacheManager cacheManager,
IManageCommandQueue commandQueueManager,
IAlbumService albumService,
Logger logger)
{
_commandQueueManager = commandQueueManager;
_albumService = albumService;
_logger = logger;
_addedAlbumsCache = cacheManager.GetCache<List<int>>(GetType());
}
public void SearchForRecentlyAdded(int artistId)
{
var previouslyReleased = _addedAlbumsCache.Find(artistId.ToString());
if (previouslyReleased != null && previouslyReleased.Any())
{
var missing = previouslyReleased.Select(e => _albumService.GetAlbum(e)).ToList();
if (missing.Any())
{
_commandQueueManager.Push(new AlbumSearchCommand(missing.Select(e => e.Id).ToList()));
}
}
_addedAlbumsCache.Remove(artistId.ToString());
}
public void Handle(AlbumInfoRefreshedEvent message)
{
if (message.Artist.AddOptions == null)
{
if (!message.Artist.Monitored)
{
_logger.Debug("Artist is not monitored");
return;
}
if (message.Added.Empty())
{
_logger.Debug("No new albums, skipping search");
return;
}
if (message.Added.None(a => a.ReleaseDate.HasValue))
{
_logger.Debug("No new albums have an release date");
return;
}
var previouslyReleased = message.Added.Where(a => a.ReleaseDate.HasValue && a.ReleaseDate.Value.Before(DateTime.UtcNow.AddDays(1)) && a.Monitored).ToList();
if (previouslyReleased.Empty())
{
_logger.Debug("Newly added albums all release in the future");
return;
}
_addedAlbumsCache.Set(message.Artist.Id.ToString(), previouslyReleased.Select(e => e.Id).ToList());
}
}
}
}

View file

@ -1,23 +0,0 @@
using NzbDrone.Common.Messaging;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.Music.Events
{
public class TrackInfoRefreshedEvent : IEvent
{
public Album Album { get; set; }
public ReadOnlyCollection<Track> Added { get; private set; }
public ReadOnlyCollection<Track> Updated { get; private set; }
public TrackInfoRefreshedEvent(Album album, IList<Track> added, IList<Track> updated)
{
Album = album;
Added = new ReadOnlyCollection<Track>(added);
Updated = new ReadOnlyCollection<Track>(updated);
}
}
}

View file

@ -134,6 +134,8 @@ private void RefreshArtistInfo(Artist artist)
_albumService.DeleteMany(existingAlbums);
_eventAggregator.PublishEvent(new AlbumInfoRefreshedEvent(artist, newAlbumsList, updateAlbumsList));
_logger.Debug("Finished artist refresh for {0}", artist.Name);
_eventAggregator.PublishEvent(new ArtistUpdatedEvent(artist));
}

View file

@ -86,16 +86,10 @@ public void RefreshTrackInfo(Album album, IEnumerable<Track> remoteTracks)
}
}
var allTracks = new List<Track>();
allTracks.AddRange(newList);
allTracks.AddRange(updateList);
_trackService.DeleteMany(existingTracks);
_trackService.UpdateMany(updateList);
_trackService.InsertMany(newList);
_eventAggregator.PublishEvent(new TrackInfoRefreshedEvent(album, newList, updateList));
if (failCount != 0)
{
_logger.Info("Finished track refresh for album: {0}. Successful: {1} - Failed: {2} ",

View file

@ -803,6 +803,7 @@
<Compile Include="Extras\Metadata\MetadataService.cs" />
<Compile Include="Extras\Metadata\MetadataType.cs" />
<Compile Include="Music\AddAlbumService.cs" />
<Compile Include="Music\AlbumAddedService.cs" />
<Compile Include="Music\AlbumEditedService.cs" />
<Compile Include="Music\AlbumRelease.cs" />
<Compile Include="Music\ArtistStatusType.cs" />
@ -845,7 +846,6 @@
<Compile Include="Music\Events\ArtistRefreshStartingEvent.cs" />
<Compile Include="Music\Events\ArtistUpdatedEvent.cs" />
<Compile Include="Music\Events\AlbumInfoRefreshedEvent.cs" />
<Compile Include="Music\Events\TrackInfoRefreshedEvent.cs" />
<Compile Include="Music\Ratings.cs" />
<Compile Include="Music\RefreshArtistService.cs" />
<Compile Include="Music\RefreshAlbumService.cs" />