From 357245a9eb758f5868455634d2d4471bf1e5bb6a Mon Sep 17 00:00:00 2001 From: ta264 Date: Tue, 16 Nov 2021 21:06:16 +0000 Subject: [PATCH] Fixed: None metadata profile no longer grabs future books Fixes #1234 --- .../Metadata/MetadataProfileService.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs b/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs index f9236a088..27d5b89b7 100644 --- a/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs +++ b/src/NzbDrone.Core/Profiles/Metadata/MetadataProfileService.cs @@ -29,6 +29,7 @@ namespace NzbDrone.Core.Profiles.Metadata public class MetadataProfileService : IMetadataProfileService, IHandle { public const string NONE_PROFILE_NAME = "None"; + public const double NONE_PROFILE_MIN_POPULARITY = 1e10; private static readonly Regex PartOrSetRegex = new Regex(@"(?\d+) of (?\d+)|(?\d+)\s?/\s?(?\d+)|(?\d+)\s?-\s?(?\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -153,7 +154,7 @@ namespace NzbDrone.Core.Profiles.Metadata var localHash = new HashSet(localBooks.Where(x => x.AddOptions.AddType == BookAddType.Manual).Select(x => x.ForeignBookId)); localHash.UnionWith(localFiles.Select(x => x.Edition.Value.Book.Value.ForeignBookId)); - FilterByPredicate(hash, x => x.ForeignBookId, localHash, profile, (x, p) => (x.Ratings.Popularity >= p.MinPopularity) || x.ReleaseDate > DateTime.UtcNow, "rating criteria not met"); + FilterByPredicate(hash, x => x.ForeignBookId, localHash, profile, BookAllowedByRating, "rating criteria not met"); FilterByPredicate(hash, x => x.ForeignBookId, localHash, profile, (x, p) => !p.SkipMissingDate || x.ReleaseDate.HasValue, "release date is missing"); FilterByPredicate(hash, x => x.ForeignBookId, localHash, profile, (x, p) => !p.SkipPartsAndSets || !IsPartOrSet(x, seriesLinks.GetValueOrDefault(x), titles), "book is part of set"); FilterByPredicate(hash, x => x.ForeignBookId, localHash, profile, (x, p) => !p.SkipSeriesSecondary || !seriesLinks.ContainsKey(x) || seriesLinks[x].Any(y => y.IsPrimary), "book is a secondary series item"); @@ -198,6 +199,17 @@ namespace NzbDrone.Core.Profiles.Metadata } } + private bool BookAllowedByRating(Book b, MetadataProfile p) + { + // hack for the 'none' metadata profile + if (p.MinPopularity == NONE_PROFILE_MIN_POPULARITY) + { + return false; + } + + return (b.Ratings.Popularity >= p.MinPopularity) || b.ReleaseDate > DateTime.UtcNow; + } + private bool IsPartOrSet(Book book, List seriesLinks, HashSet titles) { if (seriesLinks != null && @@ -258,7 +270,7 @@ namespace NzbDrone.Core.Profiles.Metadata // make sure empty profile exists and is actually empty // TODO: reinstate if (emptyProfile != null && - emptyProfile.MinPopularity == 1e10) + emptyProfile.MinPopularity == NONE_PROFILE_MIN_POPULARITY) { return; } @@ -300,7 +312,7 @@ namespace NzbDrone.Core.Profiles.Metadata Add(new MetadataProfile { Name = NONE_PROFILE_NAME, - MinPopularity = 1e10 + MinPopularity = NONE_PROFILE_MIN_POPULARITY }); } }