From b1e92e7f73f695a886a59afe020f3d26d62e1929 Mon Sep 17 00:00:00 2001 From: ta264 Date: Sun, 25 Jul 2021 21:39:59 +0100 Subject: [PATCH] Fixed: Computing most common author now we have multiple authors --- .../Identification/CandidateService.cs | 8 ++++++- .../Identification/DistanceCalculator.cs | 21 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Core/MediaFiles/BookImport/Identification/CandidateService.cs b/src/NzbDrone.Core/MediaFiles/BookImport/Identification/CandidateService.cs index 71cd7004c..f7d8acc78 100644 --- a/src/NzbDrone.Core/MediaFiles/BookImport/Identification/CandidateService.cs +++ b/src/NzbDrone.Core/MediaFiles/BookImport/Identification/CandidateService.cs @@ -285,7 +285,13 @@ public IEnumerable GetRemoteCandidates(LocalEdition localEditi } else { - authorTags.AddRange(localEdition.LocalBooks.MostCommon(x => x.FileTrackInfo.Authors)); + // the most common list of authors reported by a file + var authors = localEdition.LocalBooks.Select(x => x.FileTrackInfo.Authors.Where(a => a.IsNotNullOrWhiteSpace()).ToList()) + .GroupBy(x => x.ConcatToString()) + .OrderByDescending(x => x.Count()) + .First() + .First(); + authorTags.AddRange(authors); } var bookTag = localEdition.LocalBooks.MostCommon(x => x.FileTrackInfo.BookTitle) ?? ""; diff --git a/src/NzbDrone.Core/MediaFiles/BookImport/Identification/DistanceCalculator.cs b/src/NzbDrone.Core/MediaFiles/BookImport/Identification/DistanceCalculator.cs index 1e9ce5e23..292c0d9fa 100644 --- a/src/NzbDrone.Core/MediaFiles/BookImport/Identification/DistanceCalculator.cs +++ b/src/NzbDrone.Core/MediaFiles/BookImport/Identification/DistanceCalculator.cs @@ -23,19 +23,20 @@ public static Distance BookDistance(List localTracks, Edition edition { var dist = new Distance(); - var authors = new List(); + // the most common list of authors reported by a file + var fileAuthors = localTracks.Select(x => x.FileTrackInfo.Authors.Where(a => a.IsNotNullOrWhiteSpace()).ToList()) + .GroupBy(x => x.ConcatToString()) + .OrderByDescending(x => x.Count()) + .First() + .First(); - var fileAuthors = localTracks.MostCommon(x => x.FileTrackInfo.Authors); - if (fileAuthors?.Any() ?? false) + var authors = new List(fileAuthors); + + foreach (var author in fileAuthors) { - authors.AddRange(fileAuthors); - - foreach (var author in fileAuthors) + if (author.Contains(',')) { - if (author.Contains(',')) - { - authors.Add(authors[0].Split(',', 2).Select(x => x.Trim()).Reverse().ConcatToString(" ")); - } + authors.Add(authors[0].Split(',', 2).Select(x => x.Trim()).Reverse().ConcatToString(" ")); } }