mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07: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 @@ namespace NzbDrone.Core.Datastore.Migration
|
||||||
.WithColumn("AddOptions").AsString().Nullable();
|
.WithColumn("AddOptions").AsString().Nullable();
|
||||||
|
|
||||||
Create.TableForModel("Albums")
|
Create.TableForModel("Albums")
|
||||||
.WithColumn("ForeignArtistId").AsString().Unique()
|
.WithColumn("ForeignAlbumId").AsString().Unique()
|
||||||
.WithColumn("ArtistId").AsInt32()
|
.WithColumn("ArtistId").AsInt32()
|
||||||
.WithColumn("MBId").AsString().Indexed()
|
.WithColumn("MBId").AsString().Indexed()
|
||||||
.WithColumn("AMId").AsString().Nullable()
|
.WithColumn("AMId").AsString().Nullable()
|
||||||
|
@ -68,12 +68,14 @@ namespace NzbDrone.Core.Datastore.Migration
|
||||||
.WithColumn("AddOptions").AsString().Nullable();
|
.WithColumn("AddOptions").AsString().Nullable();
|
||||||
|
|
||||||
Create.TableForModel("Tracks")
|
Create.TableForModel("Tracks")
|
||||||
|
.WithColumn("ForeignTrackId").AsString().Unique()
|
||||||
.WithColumn("ArtistId").AsInt32().Indexed()
|
.WithColumn("ArtistId").AsInt32().Indexed()
|
||||||
.WithColumn("AlbumId").AsInt32()
|
.WithColumn("AlbumId").AsInt32()
|
||||||
.WithColumn("MBId").AsString().Indexed()
|
.WithColumn("MBId").AsString().Indexed()
|
||||||
.WithColumn("TrackNumber").AsInt32()
|
.WithColumn("TrackNumber").AsInt32()
|
||||||
.WithColumn("Title").AsString().Nullable()
|
.WithColumn("Title").AsString().Nullable()
|
||||||
.WithColumn("Explicit").AsBoolean()
|
.WithColumn("Explicit").AsBoolean()
|
||||||
|
.WithColumn("Compilation").AsBoolean()
|
||||||
.WithColumn("DiscNumber").AsInt32().Nullable()
|
.WithColumn("DiscNumber").AsInt32().Nullable()
|
||||||
.WithColumn("TrackFileId").AsInt32().Nullable().Indexed()
|
.WithColumn("TrackFileId").AsInt32().Nullable().Indexed()
|
||||||
.WithColumn("Monitored").AsBoolean()
|
.WithColumn("Monitored").AsBoolean()
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||||
public string TrackName { get; set; }
|
public string TrackName { get; set; }
|
||||||
public int TrackNumber { get; set; }
|
public int TrackNumber { get; set; }
|
||||||
public bool Explicit { get; set; }
|
public bool Explicit { get; set; }
|
||||||
public List<ArtistInfoResource> Artists { get; set; }
|
public List<ArtistResource> Artists { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace NzbDrone.Core.Music
|
||||||
var successCount = 0;
|
var successCount = 0;
|
||||||
var failCount = 0;
|
var failCount = 0;
|
||||||
|
|
||||||
var existingTracks = _trackService.GetTracksByArtist(artist.ForeignArtistId);
|
var existingTracks = _trackService.GetTracksByArtist(artist.Id);
|
||||||
var albums = artist.Albums;
|
var albums = artist.Albums;
|
||||||
|
|
||||||
var updateList = new List<Track>();
|
var updateList = new List<Track>();
|
||||||
|
@ -58,20 +58,13 @@ namespace NzbDrone.Core.Music
|
||||||
newList.Add(trackToUpdate);
|
newList.Add(trackToUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
trackToUpdate.SpotifyTrackId = track.SpotifyTrackId;
|
trackToUpdate.ForeignTrackId = track.ForeignTrackId;
|
||||||
trackToUpdate.TrackNumber = track.TrackNumber;
|
trackToUpdate.TrackNumber = track.TrackNumber;
|
||||||
trackToUpdate.Title = track.Title ?? "Unknown";
|
trackToUpdate.Title = track.Title ?? "Unknown";
|
||||||
trackToUpdate.AlbumId = track.AlbumId;
|
trackToUpdate.AlbumId = track.AlbumId;
|
||||||
trackToUpdate.Album = track.Album;
|
trackToUpdate.Album = track.Album;
|
||||||
trackToUpdate.Explict = track.Explict;
|
trackToUpdate.Explicit = track.Explicit;
|
||||||
if (track.ArtistSpotifyId.IsNullOrWhiteSpace())
|
trackToUpdate.ArtistId = artist.Id;
|
||||||
{
|
|
||||||
trackToUpdate.ArtistSpotifyId = artist.ForeignArtistId;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
trackToUpdate.ArtistSpotifyId = track.ArtistSpotifyId;
|
|
||||||
}
|
|
||||||
trackToUpdate.ArtistId = track.ArtistId;
|
|
||||||
trackToUpdate.Compilation = track.Compilation;
|
trackToUpdate.Compilation = track.Compilation;
|
||||||
|
|
||||||
// TODO: Implement rest of [RefreshTrackService] fields
|
// TODO: Implement rest of [RefreshTrackService] fields
|
||||||
|
@ -119,7 +112,7 @@ namespace NzbDrone.Core.Music
|
||||||
return false;
|
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;
|
return album == null || album.Monitored;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,20 +17,20 @@ namespace NzbDrone.Core.Music
|
||||||
|
|
||||||
public const string RELEASE_DATE_FORMAT = "yyyy-MM-dd";
|
public const string RELEASE_DATE_FORMAT = "yyyy-MM-dd";
|
||||||
|
|
||||||
public string SpotifyTrackId { get; set; }
|
public string ForeignTrackId { get; set; }
|
||||||
public string AlbumId { get; set; }
|
public int AlbumId { get; set; }
|
||||||
public LazyLoaded<Artist> Artist { 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 int CompilationId { get; set; }
|
||||||
public bool Compilation { get; set; }
|
public bool Compilation { get; set; }
|
||||||
public int TrackNumber { get; set; }
|
public int TrackNumber { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public bool Ignored { get; set; }
|
//public bool Ignored { get; set; }
|
||||||
public bool Explict { get; set; }
|
public bool Explicit { get; set; }
|
||||||
public bool Monitored { get; set; }
|
public bool Monitored { get; set; }
|
||||||
public int TrackFileId { get; set; }
|
public int TrackFileId { get; set; }
|
||||||
public DateTime? ReleaseDate { get; set; }
|
//public DateTime? ReleaseDate { get; set; }
|
||||||
|
|
||||||
public LazyLoaded<TrackFile> TrackFile { get; set; }
|
public LazyLoaded<TrackFile> TrackFile { get; set; }
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ namespace NzbDrone.Core.Music
|
||||||
|
|
||||||
public override string ToString()
|
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>
|
public interface ITrackRepository : IBasicRepository<Track>
|
||||||
{
|
{
|
||||||
Track Find(string artistId, string albumId, int trackNumber);
|
Track Find(int artistId, int albumId, int trackNumber);
|
||||||
List<Track> GetTracks(string artistId);
|
List<Track> GetTracks(int artistId);
|
||||||
List<Track> GetTracks(string artistId, string albumId);
|
List<Track> GetTracks(int artistId, int albumId);
|
||||||
List<Track> GetTracksByFileId(int fileId);
|
List<Track> GetTracksByFileId(int fileId);
|
||||||
List<Track> TracksWithFiles(string artistId);
|
List<Track> TracksWithFiles(int artistId);
|
||||||
PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec);
|
PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec);
|
||||||
PagingSpec<Track> TracksWhereCutoffUnmet(PagingSpec<Track> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff);
|
PagingSpec<Track> TracksWhereCutoffUnmet(PagingSpec<Track> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff);
|
||||||
void SetMonitoredFlat(Track episode, bool monitored);
|
void SetMonitoredFlat(Track episode, bool monitored);
|
||||||
|
@ -37,23 +37,23 @@ namespace NzbDrone.Core.Music
|
||||||
_logger = logger;
|
_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.AlbumId == albumId)
|
||||||
.AndWhere(s => s.TrackNumber == trackNumber)
|
.AndWhere(s => s.TrackNumber == trackNumber)
|
||||||
.SingleOrDefault();
|
.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)
|
.AndWhere(s => s.AlbumId == albumId)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,10 @@ namespace NzbDrone.Core.Music
|
||||||
return Query.Where(e => e.TrackFileId == fileId).ToList();
|
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)
|
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)
|
public PagingSpec<Track> TracksWhereCutoffUnmet(PagingSpec<Track> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff)
|
||||||
|
@ -118,7 +118,7 @@ namespace NzbDrone.Core.Music
|
||||||
|
|
||||||
private SortBuilder<Track> GetMissingEpisodesQuery(PagingSpec<Track> pagingSpec, DateTime currentTime)
|
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)
|
.Where(pagingSpec.FilterExpression)
|
||||||
.AndWhere(e => e.TrackFileId == 0)
|
.AndWhere(e => e.TrackFileId == 0)
|
||||||
.AndWhere(BuildAirDateUtcCutoffWhereClause(currentTime))
|
.AndWhere(BuildAirDateUtcCutoffWhereClause(currentTime))
|
||||||
|
@ -130,7 +130,7 @@ namespace NzbDrone.Core.Music
|
||||||
|
|
||||||
private SortBuilder<Track> EpisodesWhereCutoffUnmetQuery(PagingSpec<Track> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff)
|
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)
|
.Join<Track, TrackFile>(JoinType.Left, e => e.TrackFile, (e, s) => e.TrackFileId == s.Id)
|
||||||
.Where(pagingSpec.FilterExpression)
|
.Where(pagingSpec.FilterExpression)
|
||||||
.AndWhere(e => e.TrackFileId != 0)
|
.AndWhere(e => e.TrackFileId != 0)
|
||||||
|
|
|
@ -15,12 +15,12 @@ namespace NzbDrone.Core.Music
|
||||||
{
|
{
|
||||||
Track GetTrack(int id);
|
Track GetTrack(int id);
|
||||||
List<Track> GetTracks(IEnumerable<int> ids);
|
List<Track> GetTracks(IEnumerable<int> ids);
|
||||||
Track FindTrack(string artistId, string albumId, int trackNumber);
|
Track FindTrack(int artistId, int albumId, int trackNumber);
|
||||||
Track FindTrackByTitle(string artistId, string albumId, string releaseTitle);
|
Track FindTrackByTitle(int artistId, int albumId, string releaseTitle);
|
||||||
List<Track> GetTracksByArtist(string artistId);
|
List<Track> GetTracksByArtist(int artistId);
|
||||||
//List<Track> GetTracksByAlbum(string artistId, string albumId);
|
//List<Track> GetTracksByAlbum(string artistId, string albumId);
|
||||||
//List<Track> GetTracksByAlbumTitle(string artistId, string albumTitle);
|
//List<Track> GetTracksByAlbumTitle(string artistId, string albumTitle);
|
||||||
List<Track> TracksWithFiles(string artistId);
|
List<Track> TracksWithFiles(int artistId);
|
||||||
//PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec);
|
//PagingSpec<Track> TracksWithoutFiles(PagingSpec<Track> pagingSpec);
|
||||||
List<Track> GetTracksByFileId(int trackFileId);
|
List<Track> GetTracksByFileId(int trackFileId);
|
||||||
void UpdateTrack(Track track);
|
void UpdateTrack(Track track);
|
||||||
|
@ -55,22 +55,22 @@ namespace NzbDrone.Core.Music
|
||||||
return _trackRepository.Get(ids).ToList();
|
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);
|
return _trackRepository.Find(artistId, albumId, episodeNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Track> GetTracksByArtist(string artistId)
|
public List<Track> GetTracksByArtist(int artistId)
|
||||||
{
|
{
|
||||||
return _trackRepository.GetTracks(artistId).ToList();
|
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);
|
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
|
// TODO: can replace this search mechanism with something smarter/faster/better
|
||||||
var normalizedReleaseTitle = Parser.Parser.NormalizeEpisodeTitle(releaseTitle).Replace(".", " ");
|
var normalizedReleaseTitle = Parser.Parser.NormalizeEpisodeTitle(releaseTitle).Replace(".", " ");
|
||||||
|
@ -96,7 +96,7 @@ namespace NzbDrone.Core.Music
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Track> TracksWithFiles(string artistId)
|
public List<Track> TracksWithFiles(int artistId)
|
||||||
{
|
{
|
||||||
return _trackRepository.TracksWithFiles(artistId);
|
return _trackRepository.TracksWithFiles(artistId);
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ namespace NzbDrone.Core.Music
|
||||||
|
|
||||||
public void HandleAsync(ArtistDeletedEvent message)
|
public void HandleAsync(ArtistDeletedEvent message)
|
||||||
{
|
{
|
||||||
var tracks = GetTracksByArtist(message.Artist.ForeignArtistId);
|
var tracks = GetTracksByArtist(message.Artist.Id);
|
||||||
_trackRepository.DeleteMany(tracks);
|
_trackRepository.DeleteMany(tracks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,20 +19,12 @@ namespace NzbDrone.Core.Parser.Model
|
||||||
public long Size { get; set; }
|
public long Size { get; set; }
|
||||||
public ParsedTrackInfo ParsedTrackInfo { get; set; }
|
public ParsedTrackInfo ParsedTrackInfo { get; set; }
|
||||||
public Artist Artist { get; set; }
|
public Artist Artist { get; set; }
|
||||||
|
public Album Album { get; set; }
|
||||||
public List<Track> Tracks { get; set; }
|
public List<Track> Tracks { get; set; }
|
||||||
public QualityModel Quality { get; set; }
|
public QualityModel Quality { get; set; }
|
||||||
public MediaInfoModel MediaInfo { get; set; }
|
public MediaInfoModel MediaInfo { get; set; }
|
||||||
public bool ExistingFile { 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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue