Fixed: Skip albums and releases with no valid tracks (#754)

* Fixed: Artist only marked as refreshed if Albums/Tracks refreshed also

* Fixed: Skip album releases with no valid tracks

* Fixed: Don't add albums with no valid releases

* Fixed: Remove Albums with no valid releases
pull/6/head
ta264 6 years ago committed by Qstick
parent af88b3f807
commit 045a3ce404

@ -89,6 +89,30 @@ namespace NzbDrone.Core.Test.MusicTests
ExceptionVerification.ExpectedErrors(1); ExceptionVerification.ExpectedErrors(1);
} }
[Test]
public void should_not_add_if_no_releases()
{
_fakeAlbum.AlbumReleases = new List<AlbumRelease>();
GivenValidAlbum(_fakeAlbum.ForeignAlbumId);
Subject.AddAlbum(_fakeAlbum).Should().BeNull();
Mocker.GetMock<IAlbumService>()
.Verify(x => x.AddAlbum(It.IsAny<Album>()), Times.Never());
}
[Test]
public void should_not_add_item_in_list_if_no_releases()
{
_fakeAlbum.AlbumReleases = new List<AlbumRelease>();
GivenValidAlbum(_fakeAlbum.ForeignAlbumId);
Subject.AddAlbums(new List<Album> { _fakeAlbum }).Should().BeEquivalentTo(new List<Album> { null });
Mocker.GetMock<IAlbumService>()
.Verify(x => x.AddAlbum(It.IsAny<Album>()), Times.Never());
}
[Test] [Test]
public void should_not_add_duplicate_releases() public void should_not_add_duplicate_releases()
{ {

@ -107,6 +107,21 @@ namespace NzbDrone.Core.Test.MusicTests
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
} }
[Test]
public void should_remove_album_with_no_valid_releases()
{
var album = _albums.First();
album.AlbumReleases = new List<AlbumRelease>();
GivenNewAlbumInfo(album);
Subject.RefreshAlbumInfo(album, false);
Mocker.GetMock<IAlbumService>()
.Verify(x => x.DeleteMany(It.Is<List<Album>>(y => y.Count == 1 && y.First().ForeignAlbumId == album.ForeignAlbumId)),
Times.Once());
}
[Test] [Test]
public void two_equivalent_releases_should_be_equal() public void two_equivalent_releases_should_be_equal()
{ {

@ -319,7 +319,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
if (resource.Releases != null) if (resource.Releases != null)
{ {
album.AlbumReleases = resource.Releases.Select(x => MapRelease(x, artistDict)).ToList(); album.AlbumReleases = resource.Releases.Select(x => MapRelease(x, artistDict)).Where(x => x.TrackCount > 0).ToList();
} }
album.AnyReleaseOk = true; album.AnyReleaseOk = true;

@ -86,6 +86,13 @@ namespace NzbDrone.Core.Music
private Album AddAlbum(Tuple<string, Album, List<ArtistMetadata>> skyHookData) private Album AddAlbum(Tuple<string, Album, List<ArtistMetadata>> skyHookData)
{ {
var newAlbum = skyHookData.Item2; var newAlbum = skyHookData.Item2;
if (newAlbum.AlbumReleases.Value.Count == 0)
{
_logger.Debug($"Skipping album with no valid releases {newAlbum}");
return null;
}
_logger.ProgressInfo("Adding Album {0}", newAlbum.Title); _logger.ProgressInfo("Adding Album {0}", newAlbum.Title);
_artistMetadataRepository.UpsertMany(skyHookData.Item3); _artistMetadataRepository.UpsertMany(skyHookData.Item3);

@ -84,6 +84,13 @@ namespace NzbDrone.Core.Music
return; return;
} }
if (tuple.Item2.AlbumReleases.Value.Count == 0)
{
_logger.Debug($"{album} has no valid releases, removing.");
_albumService.DeleteMany(new List<Album> { album });
return;
}
var remoteMetadata = tuple.Item3.DistinctBy(x => x.ForeignArtistId).ToList(); var remoteMetadata = tuple.Item3.DistinctBy(x => x.ForeignArtistId).ToList();
var existingMetadata = _artistMetadataRepository.FindById(remoteMetadata.Select(x => x.ForeignArtistId).ToList()); var existingMetadata = _artistMetadataRepository.FindById(remoteMetadata.Select(x => x.ForeignArtistId).ToList());
var updateMetadataList = new List<ArtistMetadata>(); var updateMetadataList = new List<ArtistMetadata>();

@ -139,8 +139,6 @@ namespace NzbDrone.Core.Music
} }
} }
_artistService.UpdateArtist(artist);
_logger.Debug("{0} Deleting {1}, Updating {2}, Adding {3} albums", _logger.Debug("{0} Deleting {1}, Updating {2}, Adding {3} albums",
artist, existingAlbums.Count, updateAlbumsList.Count, newAlbumsList.Count); artist, existingAlbums.Count, updateAlbumsList.Count, newAlbumsList.Count);
@ -157,10 +155,12 @@ namespace NzbDrone.Core.Music
_refreshAlbumService.RefreshAlbumInfo(updateAlbumsList, forceAlbumRefresh, forceUpdateFileTags); _refreshAlbumService.RefreshAlbumInfo(updateAlbumsList, forceAlbumRefresh, forceUpdateFileTags);
_eventAggregator.PublishEvent(new AlbumInfoRefreshedEvent(artist, newAlbumsList, updateAlbumsList)); // Do this last so artist only marked as refreshed if refresh of tracks / albums completed successfully
_artistService.UpdateArtist(artist);
_logger.Debug("Finished artist refresh for {0}", artist.Name); _eventAggregator.PublishEvent(new AlbumInfoRefreshedEvent(artist, newAlbumsList, updateAlbumsList));
_eventAggregator.PublishEvent(new ArtistUpdatedEvent(artist)); _eventAggregator.PublishEvent(new ArtistUpdatedEvent(artist));
_logger.Debug("Finished artist refresh for {0}", artist.Name);
} }
private List<Album> UpdateAlbums(Artist artist, List<Album> albumsToUpdate) private List<Album> UpdateAlbums(Artist artist, List<Album> albumsToUpdate)

Loading…
Cancel
Save