New: Add old ids, artist aliases and genres

This commit is contained in:
ta264 2019-07-09 21:13:52 +01:00
parent 5ac46270ed
commit 76db27e8c2
16 changed files with 91 additions and 14 deletions

View File

@ -148,8 +148,8 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
var localAlbumRelease = new LocalAlbumRelease(localTracks);
Mocker.GetMock<IReleaseService>()
.Setup(x => x.GetReleaseByForeignReleaseId("xxx"))
.Returns(release);
.Setup(x => x.GetReleaseByForeignReleaseId("xxx", true))
.Returns(release);
Subject.GetCandidatesFromTags(localAlbumRelease, null, null, null, false).ShouldBeEquivalentTo(
new List<CandidateAlbumRelease> { new CandidateAlbumRelease(release) }

View File

@ -0,0 +1,20 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(32)]
public class old_ids_and_artist_alias : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("ArtistMetadata").AddColumn("Aliases").AsString().WithDefaultValue("[]");
Alter.Table("ArtistMetadata").AddColumn("OldForeignArtistIds").AsString().WithDefaultValue("[]");
Alter.Table("Albums").AddColumn("OldForeignAlbumIds").AsString().WithDefaultValue("[]");
Alter.Table("AlbumReleases").AddColumn("OldForeignReleaseIds").AsString().WithDefaultValue("[]");
Alter.Table("Tracks").AddColumn("OldForeignRecordingIds").AsString().WithDefaultValue("[]");
Alter.Table("Tracks").AddColumn("OldForeignTrackIds").AsString().WithDefaultValue("[]");
}
}
}

View File

@ -275,7 +275,8 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
if (releaseIds.Count == 1 && releaseIds[0].IsNotNullOrWhiteSpace())
{
_logger.Debug("Selecting release from consensus ForeignReleaseId [{0}]", releaseIds[0]);
tagMbidRelease = _releaseService.GetReleaseByForeignReleaseId(releaseIds[0]);
tagMbidRelease = _releaseService.GetReleaseByForeignReleaseId(releaseIds[0], true);
if (tagMbidRelease != null)
{
tagCandidate = GetCandidatesByRelease(new List<AlbumRelease> { tagMbidRelease }, includeExisting);
@ -555,7 +556,8 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
var recordingId = localTrack.FileTrackInfo.RecordingMBId;
if (recordingId.IsNotNullOrWhiteSpace())
{
dist.AddBool("recording_id", localTrack.FileTrackInfo.RecordingMBId != mbTrack.ForeignRecordingId);
dist.AddBool("recording_id", localTrack.FileTrackInfo.RecordingMBId != mbTrack.ForeignRecordingId &&
!mbTrack.OldForeignRecordingIds.Contains(localTrack.FileTrackInfo.RecordingMBId));
}
// for fingerprinted files
@ -657,8 +659,8 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
var mbAlbumId = MostCommon(localTracks.Select(x => x.FileTrackInfo.ReleaseMBId));
if (mbAlbumId.IsNotNullOrWhiteSpace())
{
dist.AddEquality("album_id", mbAlbumId, new List<string> { release.ForeignReleaseId });
_logger.Trace("album_id: {0} vs {1}; {2}", mbAlbumId, release.ForeignReleaseId, dist.NormalizedDistance());
dist.AddBool("album_id", mbAlbumId != release.ForeignReleaseId && !release.OldForeignReleaseIds.Contains(mbAlbumId));
_logger.Trace("album_id: {0} vs {1} or {2}; {3}", mbAlbumId, release.ForeignReleaseId, string.Join(", ", release.OldForeignReleaseIds), dist.NormalizedDistance());
}
// tracks

View File

@ -9,9 +9,11 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
public List<ArtistResource> Artists { get; set; }
public string Disambiguation { get; set; }
public string Overview { get; set; }
public string Id { get; set; }
public string Id { get; set; }
public List<string> OldIds { get; set; }
public List<ImageResource> Images { get; set; }
public List<LinkResource> Links { get; set; }
public List<string> Genres { get; set; }
public RatingResource Rating { get; set; }
public DateTime? ReleaseDate { get; set; }
public List<ReleaseResource> Releases { get; set; }

View File

@ -17,9 +17,11 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
public string Type { get; set; }
public string Disambiguation { get; set; }
public string Id { get; set; }
public List<string> OldIds { get; set; }
public List<ImageResource> Images { get; set; }
public List<LinkResource> Links { get; set; }
public string ArtistName { get; set; }
public List<string> ArtistAliases { get; set; }
public List<AlbumResource> Albums { get; set; }
public string Status { get; set; }
public RatingResource Rating { get; set; }

View File

@ -9,6 +9,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
public List<string> Country { get; set; }
public DateTime? ReleaseDate { get; set; }
public string Id { get; set; }
public List<string> OldIds { get; set; }
public List<string> Label { get; set; }
public List<MediumResource> Media { get; set; }
public string Title { get; set; }

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
{
public class TrackResource
@ -10,7 +12,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
public string ArtistId { get; set; }
public int DurationMs { get; set; }
public string Id { get; set; }
public List<string> OldIds { get; set; }
public string RecordingId { get; set; }
public List<string> OldRecordingIds { get; set; }
public string TrackName { get; set; }
public string TrackNumber { get; set; }
public int TrackPosition { get; set; }

View File

@ -301,6 +301,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
{
Album album = new Album();
album.ForeignAlbumId = resource.Id;
album.OldForeignAlbumIds = resource.OldIds;
album.Title = resource.Title;
album.Overview = resource.Overview;
album.Disambiguation = resource.Disambiguation;
@ -315,6 +316,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
album.SecondaryTypes = resource.SecondaryTypes.Select(MapSecondaryTypes).ToList();
album.Ratings = MapRatings(resource.Rating);
album.Links = resource.Links?.Select(MapLink).ToList();
album.Genres = resource.Genres;
album.CleanTitle = Parser.Parser.CleanArtistName(album.Title);
if (resource.Releases != null)
@ -331,6 +333,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
{
AlbumRelease release = new AlbumRelease();
release.ForeignReleaseId = resource.Id;
release.OldForeignReleaseIds = resource.OldIds;
release.Title = resource.Title;
release.Status = resource.Status;
release.Label = resource.Label;
@ -384,7 +387,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
ArtistMetadata = artistDict[resource.ArtistId],
Title = resource.TrackName,
ForeignTrackId = resource.Id,
OldForeignTrackIds = resource.OldIds,
ForeignRecordingId = resource.RecordingId,
OldForeignRecordingIds = resource.OldRecordingIds,
TrackNumber = resource.TrackNumber,
AbsoluteTrackNumber = resource.TrackPosition,
Duration = resource.DurationMs,
@ -400,7 +405,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
ArtistMetadata artist = new ArtistMetadata();
artist.Name = resource.ArtistName;
artist.Aliases = resource.ArtistAliases;
artist.ForeignArtistId = resource.Id;
artist.OldForeignArtistIds = resource.OldIds;
artist.Genres = resource.Genres;
artist.Overview = resource.Overview;
artist.Disambiguation = resource.Disambiguation;

View File

@ -1,7 +1,6 @@
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore;
using System;
using System.Linq;
using System.Collections.Generic;
using Marr.Data;
@ -16,6 +15,7 @@ namespace NzbDrone.Core.Music
Links = new List<Links>();
Ratings = new Ratings();
Artist = new Artist();
OldForeignAlbumIds = new List<string>();
}
public const string RELEASE_DATE_FORMAT = "yyyy-MM-dd";
@ -24,6 +24,7 @@ namespace NzbDrone.Core.Music
// These are metadata entries
public int ArtistMetadataId { get; set; }
public string ForeignAlbumId { get; set; }
public List<string> OldForeignAlbumIds { get; set; }
public string Title { get; set; }
public string Overview { get; set; }
public string Disambiguation { get; set; }

View File

@ -15,10 +15,14 @@ namespace NzbDrone.Core.Music
Genres = new List<string>();
Members = new List<Member>();
Links = new List<Links>();
OldForeignArtistIds = new List<string>();
Aliases = new List<string>();
}
public string ForeignArtistId { get; set; }
public List<string> OldForeignArtistIds { get; set; }
public string Name { get; set; }
public List<string> Aliases { get; set; }
public string Overview { get; set; }
public string Disambiguation { get; set; }
public string Type { get; set; }
@ -37,7 +41,9 @@ namespace NzbDrone.Core.Music
public void ApplyChanges(ArtistMetadata otherArtist)
{
ForeignArtistId = otherArtist.ForeignArtistId;
OldForeignArtistIds = otherArtist.OldForeignArtistIds;
Name = otherArtist.Name;
Aliases = otherArtist.Aliases;
Overview = otherArtist.Overview.IsNullOrWhiteSpace() ? Overview : otherArtist.Overview;
Disambiguation = otherArtist.Disambiguation;
Type = otherArtist.Type;
@ -58,7 +64,9 @@ namespace NzbDrone.Core.Music
if (Id == other.Id &&
ForeignArtistId == other.ForeignArtistId &&
(OldForeignArtistIds?.SequenceEqual(other.OldForeignArtistIds) ?? true) &&
Name == other.Name &&
(Aliases?.SequenceEqual(other.Aliases) ?? true) &&
Overview == other.Overview &&
Disambiguation == other.Disambiguation &&
Type == other.Type &&
@ -100,7 +108,9 @@ namespace NzbDrone.Core.Music
int hash = 17;
hash = hash * 23 + Id;
hash = hash * 23 + ForeignArtistId.GetHashCode();
hash = hash * 23 + OldForeignArtistIds.GetHashCode();
hash = hash * 23 + Name?.GetHashCode() ?? 0;
hash = hash * 23 + Aliases?.GetHashCode() ?? 0;
hash = hash * 23 + Overview?.GetHashCode() ?? 0;
hash = hash * 23 + Disambiguation?.GetHashCode() ?? 0;
hash = hash * 23 + Type?.GetHashCode() ?? 0;

View File

@ -143,6 +143,7 @@ namespace NzbDrone.Core.Music
forceUpdateFileTags |= album.Title != (albumInfo.Title ?? "Unknown");
updated |= forceUpdateFileTags;
album.OldForeignAlbumIds = albumInfo.OldForeignAlbumIds;
album.LastInfoSync = DateTime.UtcNow;
album.CleanTitle = albumInfo.CleanTitle;
album.Title = albumInfo.Title ?? "Unknown";

View File

@ -10,9 +10,15 @@ namespace NzbDrone.Core.Music
{
public class AlbumRelease : ModelBase, IEquatable<AlbumRelease>
{
public AlbumRelease()
{
OldForeignReleaseIds = new List<string>();
}
// These correspond to columns in the AlbumReleases table
public int AlbumId { get; set; }
public string ForeignReleaseId { get; set; }
public List<string> OldForeignReleaseIds { get; set; }
public string Title { get; set; }
public string Status { get; set; }
public int Duration { get; set; }
@ -43,6 +49,7 @@ namespace NzbDrone.Core.Music
if (Id == other.Id &&
AlbumId == other.AlbumId &&
ForeignReleaseId == other.ForeignReleaseId &&
(OldForeignReleaseIds?.SequenceEqual(other.OldForeignReleaseIds) ?? true) &&
Title == other.Title &&
Status == other.Status &&
Duration == other.Duration &&
@ -86,6 +93,7 @@ namespace NzbDrone.Core.Music
hash = hash * 23 + Id;
hash = hash * 23 + AlbumId;
hash = hash * 23 + ForeignReleaseId.GetHashCode();
hash = hash * 23 + OldForeignReleaseIds?.GetHashCode() ?? 0;
hash = hash * 23 + Title?.GetHashCode() ?? 0;
hash = hash * 23 + Status?.GetHashCode() ?? 0;
hash = hash * 23 + Duration;

View File

@ -9,7 +9,7 @@ namespace NzbDrone.Core.Music
{
public interface IReleaseRepository : IBasicRepository<AlbumRelease>
{
AlbumRelease FindByForeignReleaseId(string foreignReleaseId);
AlbumRelease FindByForeignReleaseId(string foreignReleaseId, bool checkRedirect = false);
List<AlbumRelease> FindByAlbum(int id);
List<AlbumRelease> FindByRecordingId(List<string> recordingIds);
List<AlbumRelease> GetReleasesForRefresh(int albumId, IEnumerable<string> foreignReleaseIds);
@ -23,11 +23,19 @@ namespace NzbDrone.Core.Music
{
}
public AlbumRelease FindByForeignReleaseId(string foreignReleaseId)
public AlbumRelease FindByForeignReleaseId(string foreignReleaseId, bool checkRedirect = false)
{
return Query
var release = Query
.Where(x => x.ForeignReleaseId == foreignReleaseId)
.SingleOrDefault();
if (release == null && checkRedirect)
{
release = Query.Where(x => x.OldForeignReleaseIds.Contains(foreignReleaseId))
.SingleOrDefault();
}
return release;
}
public List<AlbumRelease> GetReleasesForRefresh(int albumId, IEnumerable<string> foreignReleaseIds)

View File

@ -7,7 +7,7 @@ namespace NzbDrone.Core.Music
public interface IReleaseService
{
AlbumRelease GetRelease(int id);
AlbumRelease GetReleaseByForeignReleaseId(string foreignReleaseId);
AlbumRelease GetReleaseByForeignReleaseId(string foreignReleaseId, bool checkRedirect = false);
void InsertMany(List<AlbumRelease> releases);
void UpdateMany(List<AlbumRelease> releases);
void DeleteMany(List<AlbumRelease> releases);
@ -35,9 +35,9 @@ namespace NzbDrone.Core.Music
return _releaseRepository.Get(id);
}
public AlbumRelease GetReleaseByForeignReleaseId(string foreignReleaseId)
public AlbumRelease GetReleaseByForeignReleaseId(string foreignReleaseId, bool checkRedirect = false)
{
return _releaseRepository.FindByForeignReleaseId(foreignReleaseId);
return _releaseRepository.FindByForeignReleaseId(foreignReleaseId, checkRedirect);
}
public void InsertMany(List<AlbumRelease> releases)

View File

@ -4,6 +4,8 @@ using Marr.Data;
using NzbDrone.Common.Extensions;
using System;
using NzbDrone.Common.Serializer;
using System.Collections.Generic;
using System.Linq;
namespace NzbDrone.Core.Music
{
@ -11,11 +13,15 @@ namespace NzbDrone.Core.Music
{
public Track()
{
OldForeignTrackIds = new List<string>();
OldForeignRecordingIds = new List<string>();
}
// These are model fields
public string ForeignTrackId { get; set; }
public List<string> OldForeignTrackIds { get; set; }
public string ForeignRecordingId { get; set; }
public List<string> OldForeignRecordingIds { get; set; }
public int AlbumReleaseId { get; set; }
public int ArtistMetadataId { get; set; }
public string TrackNumber { get; set; }
@ -53,7 +59,9 @@ namespace NzbDrone.Core.Music
if (Id == other.Id &&
ForeignTrackId == other.ForeignTrackId &&
(OldForeignTrackIds?.SequenceEqual(other.OldForeignTrackIds) ?? true) &&
ForeignRecordingId == other.ForeignRecordingId &&
(OldForeignRecordingIds?.SequenceEqual(other.OldForeignRecordingIds) ?? true) &&
AlbumReleaseId == other.AlbumReleaseId &&
ArtistMetadataId == other.ArtistMetadataId &&
TrackNumber == other.TrackNumber &&
@ -96,7 +104,9 @@ namespace NzbDrone.Core.Music
int hash = 17;
hash = hash * 23 + Id;
hash = hash * 23 + ForeignTrackId.GetHashCode();
hash = hash * 23 + OldForeignTrackIds?.GetHashCode() ?? 0;
hash = hash * 23 + ForeignRecordingId.GetHashCode();
hash = hash * 23 + OldForeignRecordingIds?.GetHashCode() ?? 0;
hash = hash * 23 + AlbumReleaseId;
hash = hash * 23 + ArtistMetadataId;
hash = hash * 23 + TrackNumber?.GetHashCode() ?? 0;

View File

@ -172,6 +172,7 @@
<Compile Include="Datastore\Migration\028_clean_artistmetadata_table.cs" />
<Compile Include="Datastore\Migration\030_add_mediafilerepository_mtime.cs" />
<Compile Include="Datastore\Migration\031_add_artistmetadataid_constraint.cs" />
<Compile Include="Datastore\Migration\032_old_ids_and_artist_alias.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationDbFactory.cs" />