mirror of
https://github.com/Readarr/Readarr
synced 2025-12-15 21:02:40 +01:00
parent
8280908c39
commit
357245a9eb
1 changed files with 15 additions and 3 deletions
|
|
@ -29,6 +29,7 @@ public interface IMetadataProfileService
|
|||
public class MetadataProfileService : IMetadataProfileService, IHandle<ApplicationStartedEvent>
|
||||
{
|
||||
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+)",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
|
@ -153,7 +154,7 @@ private List<Book> FilterBooks(IEnumerable<Book> remoteBooks, List<Book> localBo
|
|||
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));
|
||||
|
||||
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 @@ private void FilterByPredicate<T>(HashSet<T> remoteItems, Func<T, string> getId,
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (seriesLinks != null &&
|
||||
|
|
@ -258,7 +270,7 @@ public void Handle(ApplicationStartedEvent message)
|
|||
// 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 @@ public void Handle(ApplicationStartedEvent message)
|
|||
Add(new MetadataProfile
|
||||
{
|
||||
Name = NONE_PROFILE_NAME,
|
||||
MinPopularity = 1e10
|
||||
MinPopularity = NONE_PROFILE_MIN_POPULARITY
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue