mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-15 17:43:49 -07:00
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.
This commit is contained in:
parent
798e85e4db
commit
aaa3b5495f
4 changed files with 49 additions and 2 deletions
|
@ -227,6 +227,7 @@ class ImportArtistSelectArtist extends Component {
|
||||||
canSpin={true}
|
canSpin={true}
|
||||||
isSpinning={isFetching}
|
isSpinning={isFetching}
|
||||||
onPress={this.onRefreshPress}
|
onPress={this.onRefreshPress}
|
||||||
|
title="Refresh"
|
||||||
>
|
>
|
||||||
<Icon name={icons.REFRESH} />
|
<Icon name={icons.REFRESH} />
|
||||||
</FormInputButton>
|
</FormInputButton>
|
||||||
|
|
|
@ -47,6 +47,24 @@ namespace NzbDrone.Core.Test.ParserTests
|
||||||
title.CleanArtistName().Should().Be("carnivale");
|
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")]
|
[TestCase("Discovery TV - Gold Rush : 02 Road From Hell [S04].mp4")]
|
||||||
public void should_clean_up_invalid_path_characters(string postTitle)
|
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 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)
|
public static ParsedTrackInfo ParseMusicPath(string path)
|
||||||
{
|
{
|
||||||
|
|
||||||
var fileInfo = new FileInfo(path);
|
var fileInfo = new FileInfo(path);
|
||||||
|
|
||||||
var result = new ParsedTrackInfo { };
|
var result = new ParsedTrackInfo { };
|
||||||
|
@ -210,6 +211,12 @@ namespace NzbDrone.Core.Parser
|
||||||
if (MediaFiles.MediaFileExtensions.Extensions.Contains(fileInfo.Extension))
|
if (MediaFiles.MediaFileExtensions.Extensions.Contains(fileInfo.Extension))
|
||||||
{
|
{
|
||||||
result = ParseAudioTags(path);
|
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
|
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
|
// TODO: Check if it is common that we might need to fallback to parser to gather details
|
||||||
//var result = ParseMusicTitle(fileInfo.Name);
|
//var result = ParseMusicTitle(fileInfo.Name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
Logger.Debug("Attempting to parse track info using directory and file names. {0}", fileInfo.Directory.Name);
|
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);
|
Logger.Debug("Parsing string '{0}'", title);
|
||||||
|
|
||||||
|
|
||||||
if (ReversedTitleRegex.IsMatch(title))
|
if (ReversedTitleRegex.IsMatch(title))
|
||||||
{
|
{
|
||||||
var titleWithoutExtension = RemoveFileExtension(title).ToCharArray();
|
var titleWithoutExtension = RemoveFileExtension(title).ToCharArray();
|
||||||
|
@ -407,6 +417,7 @@ namespace NzbDrone.Core.Parser
|
||||||
|
|
||||||
Logger.Debug("Parsing string '{0}'", title);
|
Logger.Debug("Parsing string '{0}'", title);
|
||||||
|
|
||||||
|
|
||||||
if (ReversedTitleRegex.IsMatch(title))
|
if (ReversedTitleRegex.IsMatch(title))
|
||||||
{
|
{
|
||||||
var titleWithoutExtension = RemoveFileExtension(title).ToCharArray();
|
var titleWithoutExtension = RemoveFileExtension(title).ToCharArray();
|
||||||
|
@ -582,6 +593,16 @@ namespace NzbDrone.Core.Parser
|
||||||
return title;
|
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)
|
private static ParsedTrackInfo ParseAudioTags(string path)
|
||||||
{
|
{
|
||||||
var file = TagLib.File.Create(path);
|
var file = TagLib.File.Create(path);
|
||||||
|
|
|
@ -245,7 +245,8 @@ namespace NzbDrone.Core.Parser
|
||||||
}
|
}
|
||||||
|
|
||||||
var tracks = GetTracks(artist, parsedTrackInfo);
|
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
|
return new LocalTrack
|
||||||
{
|
{
|
||||||
|
@ -270,6 +271,9 @@ namespace NzbDrone.Core.Parser
|
||||||
return new List<Track>();
|
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);
|
var album = _albumService.FindByTitle(artist.Id, parsedTrackInfo.AlbumTitle);
|
||||||
_logger.Debug("Album {0} selected for {1}", album, parsedTrackInfo);
|
_logger.Debug("Album {0} selected for {1}", album, parsedTrackInfo);
|
||||||
|
|
||||||
|
@ -283,6 +287,9 @@ namespace NzbDrone.Core.Parser
|
||||||
|
|
||||||
if (parsedTrackInfo.Title.IsNotNullOrWhiteSpace())
|
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);
|
trackInfo = _trackService.FindTrackByTitle(artist.Id, album.Id, parsedTrackInfo.DiscNumber, parsedTrackInfo.Title);
|
||||||
|
|
||||||
if (trackInfo != null)
|
if (trackInfo != null)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue