feat(filters): implement min and max seeders/leechers filtering for Torznab feeds (#1342)

* feat(filter):implement min and max seeders/leechers filtering

* chore: go fmt and reorder fields

---------

Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
luckyboy 2024-01-13 00:08:18 +08:00 committed by GitHub
parent 256fbb49ba
commit a86258aaa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 192 additions and 3 deletions

View file

@ -133,6 +133,10 @@ type Filter struct {
MatchDescription string `json:"match_description,omitempty"`
ExceptDescription string `json:"except_description,omitempty"`
UseRegexDescription bool `json:"use_regex_description,omitempty"`
MinSeeders int `json:"min_seeders,omitempty"`
MaxSeeders int `json:"max_seeders,omitempty"`
MinLeechers int `json:"min_leechers,omitempty"`
MaxLeechers int `json:"max_leechers,omitempty"`
ActionsCount int `json:"actions_count"`
ActionsEnabledCount int `json:"actions_enabled_count"`
Actions []*Action `json:"actions,omitempty"`
@ -232,6 +236,10 @@ type FilterUpdate struct {
ExceptTagsAny *string `json:"except_tags_any,omitempty"`
TagsMatchLogic *string `json:"tags_match_logic,omitempty"`
ExceptTagsMatchLogic *string `json:"except_tags_match_logic,omitempty"`
MinSeeders *int `json:"min_seeders,omitempty"`
MaxSeeders *int `json:"max_seeders,omitempty"`
MinLeechers *int `json:"min_leechers,omitempty"`
MaxLeechers *int `json:"max_leechers,omitempty"`
ExternalScriptEnabled *bool `json:"external_script_enabled,omitempty"`
ExternalScriptCmd *string `json:"external_script_cmd,omitempty"`
ExternalScriptArgs *string `json:"external_script_args,omitempty"`
@ -507,6 +515,31 @@ func (f *Filter) CheckFilter(r *Release) ([]string, bool) {
}
}
// Min and Max Seeders/Leechers is only for Torznab feeds
if f.MinSeeders > 0 {
if f.MinSeeders > r.Seeders {
f.addRejectionF("min seeders not matcing. got: %d want %d", r.Seeders, f.MinSeeders)
}
}
if f.MaxSeeders > 0 {
if f.MaxSeeders < r.Seeders {
f.addRejectionF("max seeders not matcing. got: %d want %d", r.Seeders, f.MaxSeeders)
}
}
if f.MinLeechers > 0 {
if f.MinLeechers > r.Leechers {
f.addRejectionF("min leechers not matcing. got: %d want %d", r.Leechers, f.MinLeechers)
}
}
if f.MaxLeechers > 0 {
if f.MaxLeechers < r.Leechers {
f.addRejectionF("max leechers not matcing. got: %d want %d", r.Leechers, f.MaxLeechers)
}
}
if len(f.Rejections) > 0 {
return f.Rejections, false
}