mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-20 13:06:57 +00:00
Track Mapping Fixes
Fix Some Issues with Track Mapping
This commit is contained in:
parent
0f3c355381
commit
15b70ede7c
7 changed files with 42 additions and 55 deletions
|
@ -40,7 +40,7 @@ protected override void MainDbUpgrade()
|
|||
.WithColumn("AddOptions").AsString().Nullable();
|
||||
|
||||
Create.TableForModel("Albums")
|
||||
.WithColumn("ForeignArtistId").AsString().Unique()
|
||||
.WithColumn("ForeignAlbumId").AsString().Unique()
|
||||
.WithColumn("ArtistId").AsInt32()
|
||||
.WithColumn("MBId").AsString().Indexed()
|
||||
.WithColumn("AMId").AsString().Nullable()
|
||||
|
@ -68,12 +68,14 @@ protected override void MainDbUpgrade()
|
|||
.WithColumn("AddOptions").AsString().Nullable();
|
||||
|
||||
Create.TableForModel("Tracks")
|
||||
.WithColumn("ForeignTrackId").AsString().Unique()
|
||||
.WithColumn("ArtistId").AsInt32().Indexed()
|
||||
.WithColumn("AlbumId").AsInt32()
|
||||
.WithColumn("MBId").AsString().Indexed()
|
||||
.WithColumn("TrackNumber").AsInt32()
|
||||
.WithColumn("Title").AsString().Nullable()
|
||||
.WithColumn("Explicit").AsBoolean()
|
||||
.WithColumn("Compilation").AsBoolean()
|
||||
.WithColumn("DiscNumber").AsInt32().Nullable()
|
||||
.WithColumn("TrackFileId").AsInt32().Nullable().Indexed()
|
||||
.WithColumn("Monitored").AsBoolean()
|
||||
|
|
|
@ -19,7 +19,7 @@ public TrackResource()
|
|||
public string TrackName { get; set; }
|
||||
public int TrackNumber { get; set; }
|
||||
public bool Explicit { get; set; }
|
||||
public List<ArtistInfoResource> Artists { get; set; }
|
||||
public List<ArtistResource> Artists { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public void RefreshTrackInfo(Artist artist, IEnumerable<Track> remoteTracks)
|
|||
var successCount = 0;
|
||||
var failCount = 0;
|
||||
|
||||
var existingTracks = _trackService.GetTracksByArtist(artist.ForeignArtistId);
|
||||
var existingTracks = _trackService.GetTracksByArtist(artist.Id);
|
||||
var albums = artist.Albums;
|
||||
|
||||
var updateList = new List<Track>();
|
||||
|
@ -58,20 +58,13 @@ public void RefreshTrackInfo(Artist artist, IEnumerable<Track> remoteTracks)
|
|||
newList.Add(trackToUpdate);
|
||||
}
|
||||
|
||||
trackToUpdate.SpotifyTrackId = track.SpotifyTrackId;
|
||||
trackToUpdate.ForeignTrackId = track.ForeignTrackId;
|
||||
trackToUpdate.TrackNumber = track.TrackNumber;
|
||||
trackToUpdate.Title = track.Title ?? "Unknown";
|
||||
trackToUpdate.AlbumId = track.AlbumId;
|
||||
trackToUpdate.Album = track.Album;
|
||||
trackToUpdate.Explict = track.Explict;
|
||||
if (track.ArtistSpotifyId.IsNullOrWhiteSpace())
|
||||
{
|
||||
trackToUpdate.ArtistSpotifyId = artist.ForeignArtistId;
|
||||
} else
|
||||
{
|
||||
trackToUpdate.ArtistSpotifyId = track.ArtistSpotifyId;
|
||||
}
|
||||
trackToUpdate.ArtistId = track.ArtistId;
|
||||
trackToUpdate.Explicit = track.Explicit;
|
||||
trackToUpdate.ArtistId = artist.Id;
|
||||
trackToUpdate.Compilation = track.Compilation;
|
||||
|
||||
// TODO: Implement rest of [RefreshTrackService] fields
|
||||
|
@ -119,7 +112,7 @@ private bool GetMonitoredStatus(Track track, IEnumerable<Album> albums)
|
|||
return false;
|
||||
}
|
||||
|
||||
var album = albums.SingleOrDefault(c => c.AlbumId == track.AlbumId);
|
||||
var album = albums.SingleOrDefault(c => c.Id == track.AlbumId);
|
||||
return album == null || album.Monitored;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,20 +17,20 @@ public Track()
|
|||
|
||||
public const string RELEASE_DATE_FORMAT = "yyyy-MM-dd";
|
||||
|
||||
public string SpotifyTrackId { get; set; }
|
||||
public string AlbumId { get; set; }
|
||||
public string ForeignTrackId { get; set; }
|
||||
public int AlbumId { get; set; }
|
||||
public LazyLoaded<Artist> Artist { get; set; }
|
||||
public string ArtistSpotifyId { get; set; }
|
||||
public long ArtistId { get; set; } // This is the DB Id of the Artist, not the SpotifyId
|
||||
|
||||
public int ArtistId { get; set; } // This is the DB Id of the Artist, not the SpotifyId
|
||||
//public int CompilationId { get; set; }
|
||||
public bool Compilation { get; set; }
|
||||
public int TrackNumber { get; set; }
|
||||
public string Title { get; set; }
|
||||
public bool Ignored { get; set; }
|
||||
public bool Explict { get; set; }
|
||||
//public bool Ignored { get; set; }
|
||||
public bool Explicit { get; set; }
|
||||
public bool Monitored { get; set; }
|
||||
public int TrackFileId { get; set; }
|
||||
public DateTime? ReleaseDate { get; set; }
|
||||
//public DateTime? ReleaseDate { get; set; }
|
||||
|
||||
public LazyLoaded<TrackFile> TrackFile { get; set; }
|
||||
|
||||
|
@ -40,7 +40,7 @@ public Track()
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("[{0}]{1}", SpotifyTrackId, Title.NullSafe());
|
||||
return string.Format("[{0}]{1}", ForeignTrackId, Title.NullSafe());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
public interface ITrackRepository : IBasicRepository<Track>
|
||||
{
|
||||
Track Find(string artistId, string albumId, int trackNumber);
|
||||
List<Track> GetTracks(string artistId);
|
||||
List<Track> GetTracks(string artistId, string albumId);
|
||||
Track Find(int artistId, int albumId, int trackNumber);
|
||||
List<Track> GetTracks(int artistId);
|
||||
List<Track> GetTracks(int artistId, int albumId);
|
||||
List<Track> GetTracksByFileId(int fileId);
|
||||
List<Track> TracksWithFiles(string artistId);
|
||||
List<Track> TracksWithFiles(int artistId);
|
||||
PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec);
|
||||
PagingSpec<Track> TracksWhereCutoffUnmet(PagingSpec<Track> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff);
|
||||
void SetMonitoredFlat(Track episode, bool monitored);
|
||||
|
@ -37,23 +37,23 @@ public TrackRepository(IMainDatabase database, IEventAggregator eventAggregator,
|
|||
_logger = logger;
|
||||
}
|
||||
|
||||
public Track Find(string artistId, string albumId, int trackNumber)
|
||||
public Track Find(int artistId, int albumId, int trackNumber)
|
||||
{
|
||||
return Query.Where(s => s.ArtistSpotifyId == artistId)
|
||||
return Query.Where(s => s.ArtistId == artistId)
|
||||
.AndWhere(s => s.AlbumId == albumId)
|
||||
.AndWhere(s => s.TrackNumber == trackNumber)
|
||||
.SingleOrDefault();
|
||||
}
|
||||
|
||||
|
||||
public List<Track> GetTracks(string artistId)
|
||||
public List<Track> GetTracks(int artistId)
|
||||
{
|
||||
return Query.Where(s => s.ArtistSpotifyId == artistId).ToList();
|
||||
return Query.Where(s => s.ArtistId == artistId).ToList();
|
||||
}
|
||||
|
||||
public List<Track> GetTracks(string artistId, string albumId)
|
||||
public List<Track> GetTracks(int artistId, int albumId)
|
||||
{
|
||||
return Query.Where(s => s.ArtistSpotifyId == artistId)
|
||||
return Query.Where(s => s.ArtistId == artistId)
|
||||
.AndWhere(s => s.AlbumId == albumId)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -63,10 +63,10 @@ public List<Track> GetTracksByFileId(int fileId)
|
|||
return Query.Where(e => e.TrackFileId == fileId).ToList();
|
||||
}
|
||||
|
||||
public List<Track> TracksWithFiles(string artistId)
|
||||
public List<Track> TracksWithFiles(int artistId)
|
||||
{
|
||||
return Query.Join<Track, TrackFile>(JoinType.Inner, e => e.TrackFile, (e, ef) => e.TrackFileId == ef.Id)
|
||||
.Where(e => e.ArtistSpotifyId == artistId);
|
||||
.Where(e => e.ArtistId == artistId);
|
||||
}
|
||||
|
||||
public PagingSpec<Track> TracksWhereCutoffUnmet(PagingSpec<Track> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff)
|
||||
|
@ -118,7 +118,7 @@ public PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec)
|
|||
|
||||
private SortBuilder<Track> GetMissingEpisodesQuery(PagingSpec<Track> pagingSpec, DateTime currentTime)
|
||||
{
|
||||
return Query.Join<Track, Artist>(JoinType.Inner, e => e.Artist, (e, s) => e.ArtistSpotifyId == s.ForeignArtistId)
|
||||
return Query.Join<Track, Artist>(JoinType.Inner, e => e.Artist, (e, s) => e.ArtistId == s.Id)
|
||||
.Where(pagingSpec.FilterExpression)
|
||||
.AndWhere(e => e.TrackFileId == 0)
|
||||
.AndWhere(BuildAirDateUtcCutoffWhereClause(currentTime))
|
||||
|
@ -130,7 +130,7 @@ private SortBuilder<Track> GetMissingEpisodesQuery(PagingSpec<Track> pagingSpec,
|
|||
|
||||
private SortBuilder<Track> EpisodesWhereCutoffUnmetQuery(PagingSpec<Track> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff)
|
||||
{
|
||||
return Query.Join<Track, Artist>(JoinType.Inner, e => e.Artist, (e, s) => e.ArtistSpotifyId == s.ForeignArtistId)
|
||||
return Query.Join<Track, Artist>(JoinType.Inner, e => e.Artist, (e, s) => e.ArtistId == s.Id)
|
||||
.Join<Track, TrackFile>(JoinType.Left, e => e.TrackFile, (e, s) => e.TrackFileId == s.Id)
|
||||
.Where(pagingSpec.FilterExpression)
|
||||
.AndWhere(e => e.TrackFileId != 0)
|
||||
|
|
|
@ -15,12 +15,12 @@ public interface ITrackService
|
|||
{
|
||||
Track GetTrack(int id);
|
||||
List<Track> GetTracks(IEnumerable<int> ids);
|
||||
Track FindTrack(string artistId, string albumId, int trackNumber);
|
||||
Track FindTrackByTitle(string artistId, string albumId, string releaseTitle);
|
||||
List<Track> GetTracksByArtist(string artistId);
|
||||
Track FindTrack(int artistId, int albumId, int trackNumber);
|
||||
Track FindTrackByTitle(int artistId, int albumId, string releaseTitle);
|
||||
List<Track> GetTracksByArtist(int artistId);
|
||||
//List<Track> GetTracksByAlbum(string artistId, string albumId);
|
||||
//List<Track> GetTracksByAlbumTitle(string artistId, string albumTitle);
|
||||
List<Track> TracksWithFiles(string artistId);
|
||||
List<Track> TracksWithFiles(int artistId);
|
||||
//PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec);
|
||||
List<Track> GetTracksByFileId(int trackFileId);
|
||||
void UpdateTrack(Track track);
|
||||
|
@ -55,22 +55,22 @@ public List<Track> GetTracks(IEnumerable<int> ids)
|
|||
return _trackRepository.Get(ids).ToList();
|
||||
}
|
||||
|
||||
public Track FindTrack(string artistId, string albumId, int episodeNumber)
|
||||
public Track FindTrack(int artistId, int albumId, int episodeNumber)
|
||||
{
|
||||
return _trackRepository.Find(artistId, albumId, episodeNumber);
|
||||
}
|
||||
|
||||
public List<Track> GetTracksByArtist(string artistId)
|
||||
public List<Track> GetTracksByArtist(int artistId)
|
||||
{
|
||||
return _trackRepository.GetTracks(artistId).ToList();
|
||||
}
|
||||
|
||||
public List<Track> GetTracksByAlbum(string artistId, string albumId)
|
||||
public List<Track> GetTracksByAlbum(int artistId, int albumId)
|
||||
{
|
||||
return _trackRepository.GetTracks(artistId, albumId);
|
||||
}
|
||||
|
||||
public Track FindTrackByTitle(string artistId, string albumId, string releaseTitle)
|
||||
public Track FindTrackByTitle(int artistId, int albumId, string releaseTitle)
|
||||
{
|
||||
// TODO: can replace this search mechanism with something smarter/faster/better
|
||||
var normalizedReleaseTitle = Parser.Parser.NormalizeEpisodeTitle(releaseTitle).Replace(".", " ");
|
||||
|
@ -96,7 +96,7 @@ public Track FindTrackByTitle(string artistId, string albumId, string releaseTit
|
|||
return null;
|
||||
}
|
||||
|
||||
public List<Track> TracksWithFiles(string artistId)
|
||||
public List<Track> TracksWithFiles(int artistId)
|
||||
{
|
||||
return _trackRepository.TracksWithFiles(artistId);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public void DeleteMany(List<Track> tracks)
|
|||
|
||||
public void HandleAsync(ArtistDeletedEvent message)
|
||||
{
|
||||
var tracks = GetTracksByArtist(message.Artist.ForeignArtistId);
|
||||
var tracks = GetTracksByArtist(message.Artist.Id);
|
||||
_trackRepository.DeleteMany(tracks);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,20 +19,12 @@ public LocalTrack()
|
|||
public long Size { get; set; }
|
||||
public ParsedTrackInfo ParsedTrackInfo { get; set; }
|
||||
public Artist Artist { get; set; }
|
||||
public Album Album { get; set; }
|
||||
public List<Track> Tracks { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
public MediaInfoModel MediaInfo { get; set; }
|
||||
public bool ExistingFile { get; set; }
|
||||
|
||||
public string Album
|
||||
{
|
||||
get
|
||||
{
|
||||
return Tracks.Select(c => c.AlbumId).Distinct().Single();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSpecial => Album != "";
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue