diff --git a/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs b/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs index 339abff86..48e7586c5 100644 --- a/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs +++ b/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs @@ -17,6 +17,10 @@ namespace NzbDrone.Core.IndexerSearch.Definitions public string SearchType { get; set; } public int? Limit { get; set; } public int? Offset { get; set; } + public int? MinAge { get; set; } + public int? MaxAge { get; set; } + public long? MinSize { get; set; } + public long? MaxSize { get; set; } public string Source { get; set; } public string Host { get; set; } diff --git a/src/NzbDrone.Core/IndexerSearch/NewznabRequest.cs b/src/NzbDrone.Core/IndexerSearch/NewznabRequest.cs index bddfc4de4..442b7ba00 100644 --- a/src/NzbDrone.Core/IndexerSearch/NewznabRequest.cs +++ b/src/NzbDrone.Core/IndexerSearch/NewznabRequest.cs @@ -18,6 +18,10 @@ namespace NzbDrone.Core.IndexerSearch public string extended { get; set; } public int? limit { get; set; } public int? offset { get; set; } + public int? minage { get; set; } + public int? maxage { get; set; } + public long? minsize { get; set; } + public long? maxsize { get; set; } public int? rid { get; set; } public int? tvmazeid { get; set; } public int? traktid { get; set; } diff --git a/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs b/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs index 7ff28807f..281a39b89 100644 --- a/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs @@ -139,6 +139,10 @@ namespace NzbDrone.Core.IndexerSearch spec.SearchType = query.t; spec.Limit = query.limit; spec.Offset = query.offset; + spec.MinAge = query.minage; + spec.MaxAge = query.maxage; + spec.MinSize = query.minsize; + spec.MaxSize = query.maxsize; spec.Source = query.source; spec.Host = query.host; @@ -218,6 +222,34 @@ namespace NzbDrone.Core.IndexerSearch } } + if (criteriaBase.MinAge.HasValue && criteriaBase.MinAge.Value > 0) + { + var cutoffDate = DateTime.UtcNow.Subtract(TimeSpan.FromDays(criteriaBase.MinAge.Value)); + + releases = releases.Where(r => r.PublishDate <= cutoffDate).ToList(); + } + + if (criteriaBase.MaxAge.HasValue && criteriaBase.MaxAge.Value > 0) + { + var cutoffDate = DateTime.UtcNow.Subtract(TimeSpan.FromDays(criteriaBase.MaxAge.Value)); + + releases = releases.Where(r => r.PublishDate >= cutoffDate).ToList(); + } + + if (criteriaBase.MinSize.HasValue && criteriaBase.MinSize.Value > 0) + { + var minSize = criteriaBase.MinSize.Value; + + releases = releases.Where(r => r.Size >= minSize).ToList(); + } + + if (criteriaBase.MaxSize.HasValue && criteriaBase.MaxSize.Value > 0) + { + var maxSize = criteriaBase.MaxSize.Value; + + releases = releases.Where(r => r.Size <= maxSize).ToList(); + } + foreach (var query in indexerReports.Queries) { _eventAggregator.PublishEvent(new IndexerQueryEvent(indexer.Definition.Id, criteriaBase, query)); diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRequestGenerator.cs index 0ce17321e..86c05585c 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRequestGenerator.cs @@ -272,6 +272,26 @@ namespace NzbDrone.Core.Indexers.Newznab parameters.Set("offset", searchCriteria.Offset.ToString()); } + if (searchCriteria.MinAge.HasValue) + { + parameters.Set("minage", searchCriteria.MaxAge.ToString()); + } + + if (searchCriteria.MaxAge.HasValue) + { + parameters.Set("maxage", searchCriteria.MaxAge.ToString()); + } + + if (searchCriteria.MinSize.HasValue) + { + parameters.Set("minsize", searchCriteria.MaxAge.ToString()); + } + + if (searchCriteria.MaxSize.HasValue) + { + parameters.Set("maxsize", searchCriteria.MaxAge.ToString()); + } + if (parameters.Count > 0) { searchUrl += $"&{parameters.GetQueryString()}";