Feature/common tag parsing (#273)

* Added refresh title on the refresh button.

* Added a quick fix for common parsing issues when albums or tracks contain (special edition), (deluxe edition), [bonus], (version), (single), etc.
pull/276/merge
Joseph Milazzo 7 years ago committed by GitHub
parent 798e85e4db
commit aaa3b5495f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -227,6 +227,7 @@ class ImportArtistSelectArtist extends Component {
canSpin={true}
isSpinning={isFetching}
onPress={this.onRefreshPress}
title="Refresh"
>
<Icon name={icons.REFRESH} />
</FormInputButton>

@ -47,6 +47,24 @@ namespace NzbDrone.Core.Test.ParserTests
title.CleanArtistName().Should().Be("carnivale");
}
[TestCase("Songs of Experience (Deluxe Edition)", "Songs of Experience")]
[TestCase("Mr. Bad Guy [Special Edition]", "Mr. Bad Guy")]
[TestCase("Sweet Dreams (Album)", "Sweet Dreams")]
public void should_remove_common_tags_from_album_title(string title, string correct)
{
var result = Parser.Parser.CleanAlbumTitle(title);
result.Should().Be(correct);
}
[TestCase("Songs of Experience (Deluxe Edition)", "Songs of Experience")]
[TestCase("Mr. Bad Guy [Special Edition]", "Mr. Bad Guy")]
[TestCase("Smooth Criminal (single)", "Smooth Criminal")]
public void should_remove_common_tags_from_track_title(string title, string correct)
{
var result = Parser.Parser.CleanTrackTitle(title);
result.Should().Be(correct);
}
[TestCase("Discovery TV - Gold Rush : 02 Road From Hell [S04].mp4")]
public void should_clean_up_invalid_path_characters(string postTitle)
{

@ -200,9 +200,10 @@ namespace NzbDrone.Core.Parser
private static readonly string[] Numbers = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
private static readonly Regex CommonTagRegex = new Regex(@"(\[|\(){1}(version|deluxe|single|clean|album|special|bonus)+\s*.*(\]|\)){1}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
public static ParsedTrackInfo ParseMusicPath(string path)
{
var fileInfo = new FileInfo(path);
var result = new ParsedTrackInfo { };
@ -210,6 +211,12 @@ namespace NzbDrone.Core.Parser
if (MediaFiles.MediaFileExtensions.Extensions.Contains(fileInfo.Extension))
{
result = ParseAudioTags(path);
if (CommonTagRegex.IsMatch(result.AlbumTitle))
{
result.AlbumTitle = CleanAlbumTitle(result.AlbumTitle);
Logger.Debug("Cleaning Album title of common matching issues. Cleaned album title is '{0}'", result.AlbumTitle);
}
}
else
{
@ -219,6 +226,8 @@ namespace NzbDrone.Core.Parser
// TODO: Check if it is common that we might need to fallback to parser to gather details
//var result = ParseMusicTitle(fileInfo.Name);
if (result == null)
{
Logger.Debug("Attempting to parse track info using directory and file names. {0}", fileInfo.Directory.Name);
@ -327,6 +336,7 @@ namespace NzbDrone.Core.Parser
Logger.Debug("Parsing string '{0}'", title);
if (ReversedTitleRegex.IsMatch(title))
{
var titleWithoutExtension = RemoveFileExtension(title).ToCharArray();
@ -407,6 +417,7 @@ namespace NzbDrone.Core.Parser
Logger.Debug("Parsing string '{0}'", title);
if (ReversedTitleRegex.IsMatch(title))
{
var titleWithoutExtension = RemoveFileExtension(title).ToCharArray();
@ -582,6 +593,16 @@ namespace NzbDrone.Core.Parser
return title;
}
public static string CleanAlbumTitle(string album)
{
return CommonTagRegex.Replace(album, string.Empty).Trim();
}
public static string CleanTrackTitle(string title)
{
return CommonTagRegex.Replace(title, string.Empty).Trim();
}
private static ParsedTrackInfo ParseAudioTags(string path)
{
var file = TagLib.File.Create(path);

@ -245,7 +245,8 @@ namespace NzbDrone.Core.Parser
}
var tracks = GetTracks(artist, parsedTrackInfo);
var album = _albumService.FindByTitle(artist.Id, parsedTrackInfo.AlbumTitle);
//var album = _albumService.FindByTitle(artist.Id, parsedTrackInfo.AlbumTitle);
var album = tracks.FirstOrDefault()?.Album;
return new LocalTrack
{
@ -270,6 +271,9 @@ namespace NzbDrone.Core.Parser
return new List<Track>();
}
parsedTrackInfo.AlbumTitle = Parser.CleanAlbumTitle(parsedTrackInfo.AlbumTitle);
_logger.Debug("Cleaning Album title of common matching issues. Cleaned album title is '{0}'", parsedTrackInfo.AlbumTitle);
var album = _albumService.FindByTitle(artist.Id, parsedTrackInfo.AlbumTitle);
_logger.Debug("Album {0} selected for {1}", album, parsedTrackInfo);
@ -283,6 +287,9 @@ namespace NzbDrone.Core.Parser
if (parsedTrackInfo.Title.IsNotNullOrWhiteSpace())
{
parsedTrackInfo.Title = Parser.CleanTrackTitle(parsedTrackInfo.Title);
_logger.Debug("Cleaning Track title of common matching issues. Cleaned track title is '{0}'", parsedTrackInfo.Title);
trackInfo = _trackService.FindTrackByTitle(artist.Id, album.Id, parsedTrackInfo.DiscNumber, parsedTrackInfo.Title);
if (trackInfo != null)

Loading…
Cancel
Save