Parser Enhancements (#291)

* When matching tracks with metadata, ensure we also check their track number as some albums have two tracks with same title.
pull/6/head
Joseph Milazzo 7 years ago committed by GitHub
parent e67af5e747
commit b661344ba8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -65,7 +65,7 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
.Returns(_fakeAlbum); .Returns(_fakeAlbum);
Mocker.GetMock<ITrackService>() Mocker.GetMock<ITrackService>()
.Setup(s => s.FindTrackByTitle(_fakeArtist.Id, _fakeAlbum.Id, It.IsAny<int>(), _fakeTrack.Title)) .Setup(s => s.FindTrackByTitle(_fakeArtist.Id, _fakeAlbum.Id, It.IsAny<int>(), It.IsAny<int>(), _fakeTrack.Title))
.Returns(_fakeTrack); .Returns(_fakeTrack);
} }

@ -17,7 +17,7 @@ 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(int artistId, int albumId, int mediumNumber, int trackNumber); Track FindTrack(int artistId, int albumId, int mediumNumber, int trackNumber);
Track FindTrackByTitle(int artistId, int albumId, int mediumNumber, string releaseTitle); Track FindTrackByTitle(int artistId, int albumId, int mediumNumber, int trackNumber, string releaseTitle);
List<Track> GetTracksByArtist(int artistId); List<Track> GetTracksByArtist(int artistId);
List<Track> GetTracksByAlbum(int albumId); List<Track> GetTracksByAlbum(int albumId);
//List<Track> GetTracksByAlbumTitle(string artistId, string albumTitle); //List<Track> GetTracksByAlbumTitle(string artistId, string albumTitle);
@ -76,7 +76,7 @@ namespace NzbDrone.Core.Music
return _trackRepository.GetTracksByAlbum(albumId); return _trackRepository.GetTracksByAlbum(albumId);
} }
public Track FindTrackByTitle(int artistId, int albumId, int mediumNumber, string releaseTitle) public Track FindTrackByTitle(int artistId, int albumId, int mediumNumber, int trackNumber, 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(".", " ");
@ -88,9 +88,17 @@ namespace NzbDrone.Core.Music
Position = normalizedReleaseTitle.IndexOf(Parser.Parser.NormalizeEpisodeTitle(track.Title), StringComparison.CurrentCultureIgnoreCase), Position = normalizedReleaseTitle.IndexOf(Parser.Parser.NormalizeEpisodeTitle(track.Title), StringComparison.CurrentCultureIgnoreCase),
Length = Parser.Parser.NormalizeEpisodeTitle(track.Title).Length, Length = Parser.Parser.NormalizeEpisodeTitle(track.Title).Length,
Track = track Track = track
}) });
.Where(e => e.Track.Title.Length > 0 && e.Position >= 0)
.OrderBy(e => e.Position) if (trackNumber == 0)
{
matches = matches.Where(e => e.Track.Title.Length > 0 && e.Position >= 0);
} else
{
matches = matches.Where(e => e.Track.Title.Length > 0 && e.Position >= 0 && e.Track.AbsoluteTrackNumber == trackNumber);
}
matches.OrderBy(e => e.Position)
.ThenByDescending(e => e.Length) .ThenByDescending(e => e.Length)
.ToList(); .ToList();

@ -308,10 +308,16 @@ namespace NzbDrone.Core.Parser
if (parsedTrackInfo.Title.IsNotNullOrWhiteSpace()) if (parsedTrackInfo.Title.IsNotNullOrWhiteSpace())
{ {
Track trackInfo;
var cleanTrackTitle = Parser.CleanTrackTitle(parsedTrackInfo.Title); var cleanTrackTitle = Parser.CleanTrackTitle(parsedTrackInfo.Title);
_logger.Debug("Cleaning Track title of common matching issues. Cleaned track title is '{0}'", cleanTrackTitle); _logger.Debug("Cleaning Track title of common matching issues. Cleaned track title is '{0}'", cleanTrackTitle);
var trackInfo = _trackService.FindTrackByTitle(artist.Id, album.Id, parsedTrackInfo.DiscNumber, cleanTrackTitle); trackInfo = _trackService.FindTrackByTitle(artist.Id, album.Id, parsedTrackInfo.DiscNumber, parsedTrackInfo.TrackNumbers.FirstOrDefault(), cleanTrackTitle);
if (trackInfo == null)
{
trackInfo = _trackService.FindTrackByTitle(artist.Id, album.Id, parsedTrackInfo.DiscNumber, parsedTrackInfo.TrackNumbers.FirstOrDefault(), parsedTrackInfo.Title);
}
if (trackInfo != null) if (trackInfo != null)
{ {

Loading…
Cancel
Save