Fixed: None metadata profile no longer grabs future books

Fixes #1234
pull/1332/head
ta264 3 years ago
parent 8280908c39
commit 357245a9eb

@ -29,6 +29,7 @@ namespace NzbDrone.Core.Profiles.Metadata
public class MetadataProfileService : IMetadataProfileService, IHandle<ApplicationStartedEvent> public class MetadataProfileService : IMetadataProfileService, IHandle<ApplicationStartedEvent>
{ {
public const string NONE_PROFILE_NAME = "None"; public const string NONE_PROFILE_NAME = "None";
public const double NONE_PROFILE_MIN_POPULARITY = 1e10;
private static readonly Regex PartOrSetRegex = new Regex(@"(?<from>\d+) of (?<to>\d+)|(?<from>\d+)\s?/\s?(?<to>\d+)|(?<from>\d+)\s?-\s?(?<to>\d+)", private static readonly Regex PartOrSetRegex = new Regex(@"(?<from>\d+) of (?<to>\d+)|(?<from>\d+)\s?/\s?(?<to>\d+)|(?<from>\d+)\s?-\s?(?<to>\d+)",
RegexOptions.Compiled | RegexOptions.IgnoreCase); RegexOptions.Compiled | RegexOptions.IgnoreCase);
@ -153,7 +154,7 @@ namespace NzbDrone.Core.Profiles.Metadata
var localHash = new HashSet<string>(localBooks.Where(x => x.AddOptions.AddType == BookAddType.Manual).Select(x => x.ForeignBookId)); var localHash = new HashSet<string>(localBooks.Where(x => x.AddOptions.AddType == BookAddType.Manual).Select(x => x.ForeignBookId));
localHash.UnionWith(localFiles.Select(x => x.Edition.Value.Book.Value.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.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.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"); 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<SeriesBookLink> seriesLinks, HashSet<string> titles) private bool IsPartOrSet(Book book, List<SeriesBookLink> seriesLinks, HashSet<string> titles)
{ {
if (seriesLinks != null && if (seriesLinks != null &&
@ -258,7 +270,7 @@ namespace NzbDrone.Core.Profiles.Metadata
// make sure empty profile exists and is actually empty // make sure empty profile exists and is actually empty
// TODO: reinstate // TODO: reinstate
if (emptyProfile != null && if (emptyProfile != null &&
emptyProfile.MinPopularity == 1e10) emptyProfile.MinPopularity == NONE_PROFILE_MIN_POPULARITY)
{ {
return; return;
} }
@ -300,7 +312,7 @@ namespace NzbDrone.Core.Profiles.Metadata
Add(new MetadataProfile Add(new MetadataProfile
{ {
Name = NONE_PROFILE_NAME, Name = NONE_PROFILE_NAME,
MinPopularity = 1e10 MinPopularity = NONE_PROFILE_MIN_POPULARITY
}); });
} }
} }

Loading…
Cancel
Save