mirror of
https://github.com/Readarr/Readarr
synced 2025-12-15 12:52:27 +01:00
Fixed: Take publisher and format into account when choosing best edition
This commit is contained in:
parent
000022a927
commit
8e37aa2e78
2 changed files with 37 additions and 2 deletions
|
|
@ -18,11 +18,13 @@ public class Distance
|
|||
{ "asin", 10.0 },
|
||||
{ "asin_missing", 0.1 },
|
||||
{ "media_count", 1.0 },
|
||||
{ "media_format", 1.0 },
|
||||
{ "ebook_format", 0.1 },
|
||||
{ "audio_format", 0.1 },
|
||||
{ "wrong_format", 5.0 },
|
||||
{ "year", 1.0 },
|
||||
{ "country", 0.5 },
|
||||
{ "language", 5.0 },
|
||||
{ "label", 0.5 },
|
||||
{ "publisher", 0.5 },
|
||||
{ "catalog_number", 0.5 },
|
||||
{ "book_disambiguation", 0.5 },
|
||||
{ "book_id", 5.0 },
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ public static class DistanceCalculator
|
|||
|
||||
private static readonly RegexReplace CleanTitleCruft = new RegexReplace(@"\((?:unabridged)\)", string.Empty, RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
private static readonly List<string> EbookFormats = new List<string> { "Kindle Edition", "Nook", "ebook" };
|
||||
|
||||
private static readonly List<string> AudiobookFormats = new List<string> { "Audiobook", "Audio CD", "Audio Cassette", "Audible Audio", "CD-ROM", "MP3 CD" };
|
||||
|
||||
public static Distance BookDistance(List<LocalBook> localTracks, Edition edition)
|
||||
{
|
||||
var dist = new Distance();
|
||||
|
|
@ -123,6 +127,35 @@ public static Distance BookDistance(List<LocalBook> localTracks, Edition edition
|
|||
Logger.Trace($"language: {localLanguage} vs {editionLanguage}; {dist.NormalizedDistance()}");
|
||||
}
|
||||
|
||||
// Publisher - only if set for both the local book and remote edition
|
||||
var localPublisher = localTracks.MostCommon(x => x.FileTrackInfo.Publisher);
|
||||
var editionPublisher = edition.Publisher;
|
||||
if (localPublisher.IsNotNullOrWhiteSpace() && editionPublisher.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
dist.AddString("publisher", localPublisher, editionPublisher);
|
||||
Logger.Trace($"publisher: {localPublisher} vs {editionPublisher}; {dist.NormalizedDistance()}");
|
||||
}
|
||||
|
||||
// try to tilt it towards the correct "type" of release
|
||||
var isAudio = MediaFileExtensions.AudioExtensions.Contains(localTracks.First().Path.GetPathExtension());
|
||||
|
||||
if (edition.Format.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
if (!isAudio)
|
||||
{
|
||||
// text books should prefer ebook formats
|
||||
dist.AddBool("ebook_format", !EbookFormats.Contains(edition.Format));
|
||||
|
||||
// text books should not match audio entries
|
||||
dist.AddBool("wrong_format", AudiobookFormats.Contains(edition.Format));
|
||||
}
|
||||
else
|
||||
{
|
||||
// audio books should prefer audio formats
|
||||
dist.AddBool("audio_format", !AudiobookFormats.Contains(edition.Format));
|
||||
}
|
||||
}
|
||||
|
||||
return dist;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue