fix(filters): except categories (#510)

fix(filters): except categories check
This commit is contained in:
ze0s 2022-10-20 17:39:08 +02:00 committed by GitHub
parent 2cc08bed71
commit 532df38cd4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 3 deletions

View file

@ -341,7 +341,7 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) {
if r.Category != "" { if r.Category != "" {
categories = append(categories, r.Category) categories = append(categories, r.Category)
} }
if !contains(r.Category, f.MatchCategories) && !containsAny(r.Categories, f.MatchCategories) { if !contains(r.Category, f.MatchCategories) && !containsAny(categories, f.MatchCategories) {
r.addRejectionF("category not matching. got: %v want: %v", strings.Join(categories, ","), f.MatchCategories) r.addRejectionF("category not matching. got: %v want: %v", strings.Join(categories, ","), f.MatchCategories)
} }
} }
@ -352,8 +352,8 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) {
if r.Category != "" { if r.Category != "" {
categories = append(categories, r.Category) categories = append(categories, r.Category)
} }
if !contains(r.Category, f.ExceptCategories) && !containsAny(r.Categories, f.ExceptCategories) { if contains(r.Category, f.ExceptCategories) && containsAny(categories, f.ExceptCategories) {
r.addRejectionF("category unwanted. got: %v want: %v", strings.Join(categories, ","), f.ExceptCategories) r.addRejectionF("category unwanted. got: %v unwanted: %v", strings.Join(categories, ","), f.ExceptCategories)
} }
} }

View file

@ -226,6 +226,58 @@ func TestFilter_CheckFilter(t *testing.T) {
}, },
want: true, want: true,
}, },
{
name: "movie_except_category_1",
fields: &Release{
TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
Category: "Movies",
Freeleech: true,
Size: uint64(30000000001), // 30GB
},
args: args{
filter: Filter{
Enabled: true,
ExceptCategories: "*movies*",
Freeleech: true,
MinSize: "10 GB",
MaxSize: "40GB",
Resolutions: []string{"1080p", "2160p"},
Sources: []string{"BluRay"},
Codecs: []string{"x264"},
Years: "2015,2018-2022",
MatchReleaseGroups: "GROUP1,BADGROUP",
Shows: "*Movie*, good story, bad movie",
},
rejections: []string{"category unwanted. got: Movies unwanted: *movies*"},
},
want: false,
},
{
name: "movie_except_category_1",
fields: &Release{
TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
Category: "Movies",
Freeleech: true,
Size: uint64(30000000001), // 30GB
},
args: args{
filter: Filter{
Enabled: true,
ExceptCategories: "*tv*",
Freeleech: true,
MinSize: "10 GB",
MaxSize: "40GB",
Resolutions: []string{"1080p", "2160p"},
Sources: []string{"BluRay"},
Codecs: []string{"x264"},
Years: "2015,2018-2022",
MatchReleaseGroups: "GROUP1,BADGROUP",
Shows: "*Movie*, good story, bad movie",
},
rejections: nil,
},
want: true,
},
{ {
name: "movie_bad_category", name: "movie_bad_category",
fields: &Release{ fields: &Release{