fix(filters): check match other and except other (#433)

fix(filters): check other and excpet other
This commit is contained in:
ze0s 2022-08-27 14:54:41 +02:00 committed by GitHub
parent 48d6468503
commit 9813f5718d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 74 deletions

View file

@ -286,6 +286,16 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) {
r.addRejectionF("hdr unwanted. got: %v want: %v", r.HDR, f.ExceptHDR) r.addRejectionF("hdr unwanted. got: %v want: %v", r.HDR, f.ExceptHDR)
} }
// Other is parsed into the Other slice from rls
if len(f.MatchOther) > 0 && !sliceContainsSlice(r.Other, f.MatchOther) {
r.addRejectionF("match other not matching. got: %v want: %v", r.Other, f.MatchOther)
}
// Other is parsed into the Other slice from rls
if len(f.ExceptOther) > 0 && sliceContainsSlice(r.Other, f.ExceptOther) {
r.addRejectionF("except other unwanted. got: %v unwanted: %v", r.Other, f.ExceptOther)
}
if f.Years != "" && !containsIntStrings(r.Year, f.Years) { if f.Years != "" && !containsIntStrings(r.Year, f.Years) {
r.addRejectionF("year not matching. got: %d want: %v", r.Year, f.Years) r.addRejectionF("year not matching. got: %d want: %v", r.Year, f.Years)
} }

View file

@ -2,7 +2,6 @@ package domain
import ( import (
"testing" "testing"
"time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -998,61 +997,7 @@ func TestFilter_CheckFilter(t *testing.T) {
} }
func TestFilter_CheckFilter1(t *testing.T) { func TestFilter_CheckFilter1(t *testing.T) {
type fields struct { type fields Filter
ID int
Name string
Enabled bool
CreatedAt time.Time
UpdatedAt time.Time
MinSize string
MaxSize string
MaxDownloads int
MaxDownloadsPer FilterMaxDownloadsUnit
Delay int
Priority int32
MatchReleases string
ExceptReleases string
UseRegex bool
MatchReleaseGroups string
ExceptReleaseGroups string
Scene bool
Origins []string
ExceptOrigins []string
Freeleech bool
FreeleechPercent string
Shows string
Seasons string
Episodes string
Resolutions []string
Codecs []string
Sources []string
Containers []string
MatchHDR []string
ExceptHDR []string
Years string
Artists string
Albums string
MatchReleaseTypes []string
ExceptReleaseTypes string
Formats []string
Quality []string
Media []string
PerfectFlac bool
Cue bool
Log bool
LogScore int
MatchCategories string
ExceptCategories string
MatchUploaders string
ExceptUploaders string
Tags string
ExceptTags string
TagsAny string
ExceptTagsAny string
Actions []*Action
Indexers []Indexer
State *FilterDownloads
}
type args struct { type args struct {
r *Release r *Release
} }
@ -1205,9 +1150,10 @@ func TestFilter_CheckFilter1(t *testing.T) {
Sources: []string{"BluRay"}, Sources: []string{"BluRay"},
Codecs: []string{"x265", "HEVC"}, Codecs: []string{"x265", "HEVC"},
MatchHDR: []string{"DV", "HDR"}, MatchHDR: []string{"DV", "HDR"},
ExceptOther: []string{"REMUX", "HYBRID"},
}, },
args: args{&Release{TorrentName: "Stranger Things S02 UHD BluRay 2160p DTS-HD MA 5.1 DV HEVC HYBRID REMUX-FraMeSToR"}}, args: args{&Release{TorrentName: "Stranger Things S02 UHD BluRay 2160p DTS-HD MA 5.1 DV HEVC HYBRID REMUX-FraMeSToR"}},
wantRejections: []string{"source not matching. got: UHD.BluRay want: [BluRay]"}, wantRejections: []string{"source not matching. got: UHD.BluRay want: [BluRay]", "except other unwanted. got: [HYBRiD REMUX] unwanted: [REMUX HYBRID]"},
wantMatch: false, wantMatch: false,
}, },
{ {
@ -1217,6 +1163,7 @@ func TestFilter_CheckFilter1(t *testing.T) {
Sources: []string{"UHD.BluRay"}, Sources: []string{"UHD.BluRay"},
Codecs: []string{"x265", "HEVC"}, Codecs: []string{"x265", "HEVC"},
MatchHDR: []string{"DV", "HDR"}, MatchHDR: []string{"DV", "HDR"},
MatchOther: []string{"REMUX", "HYBRID"},
}, },
args: args{&Release{TorrentName: "Stranger Things S02 UHD BluRay 2160p DTS-HD MA 5.1 DV HEVC HYBRID REMUX-FraMeSToR"}}, args: args{&Release{TorrentName: "Stranger Things S02 UHD BluRay 2160p DTS-HD MA 5.1 DV HEVC HYBRID REMUX-FraMeSToR"}},
wantRejections: nil, wantRejections: nil,
@ -1448,8 +1395,8 @@ func TestFilter_CheckFilter1(t *testing.T) {
name: "test_32", name: "test_32",
fields: fields{ fields: fields{
MaxDownloads: 1, MaxDownloads: 1,
MaxDownloadsPer: FilterMaxDownloadsMonth, MaxDownloadsUnit: FilterMaxDownloadsMonth,
State: &FilterDownloads{ Downloads: &FilterDownloads{
MonthCount: 0, MonthCount: 0,
}, },
}, },
@ -1461,8 +1408,8 @@ func TestFilter_CheckFilter1(t *testing.T) {
name: "test_33", name: "test_33",
fields: fields{ fields: fields{
MaxDownloads: 10, MaxDownloads: 10,
MaxDownloadsPer: FilterMaxDownloadsMonth, MaxDownloadsUnit: FilterMaxDownloadsMonth,
State: &FilterDownloads{ Downloads: &FilterDownloads{
MonthCount: 10, MonthCount: 10,
}, },
}, },
@ -1474,8 +1421,8 @@ func TestFilter_CheckFilter1(t *testing.T) {
name: "test_34", name: "test_34",
fields: fields{ fields: fields{
MaxDownloads: 10, MaxDownloads: 10,
MaxDownloadsPer: FilterMaxDownloadsMonth, MaxDownloadsUnit: FilterMaxDownloadsMonth,
State: &FilterDownloads{ Downloads: &FilterDownloads{
MonthCount: 50, MonthCount: 50,
}, },
}, },
@ -1487,8 +1434,8 @@ func TestFilter_CheckFilter1(t *testing.T) {
name: "test_35", name: "test_35",
fields: fields{ fields: fields{
MaxDownloads: 15, MaxDownloads: 15,
MaxDownloadsPer: FilterMaxDownloadsHour, MaxDownloadsUnit: FilterMaxDownloadsHour,
State: &FilterDownloads{ Downloads: &FilterDownloads{
HourCount: 20, HourCount: 20,
MonthCount: 50, MonthCount: 50,
}, },
@ -1501,8 +1448,8 @@ func TestFilter_CheckFilter1(t *testing.T) {
name: "test_36", name: "test_36",
fields: fields{ fields: fields{
MaxDownloads: 15, MaxDownloads: 15,
MaxDownloadsPer: FilterMaxDownloadsHour, MaxDownloadsUnit: FilterMaxDownloadsHour,
State: &FilterDownloads{ Downloads: &FilterDownloads{
HourCount: 14, HourCount: 14,
MonthCount: 50, MonthCount: 50,
}, },
@ -1543,7 +1490,7 @@ func TestFilter_CheckFilter1(t *testing.T) {
Delay: tt.fields.Delay, Delay: tt.fields.Delay,
Priority: tt.fields.Priority, Priority: tt.fields.Priority,
MaxDownloads: tt.fields.MaxDownloads, MaxDownloads: tt.fields.MaxDownloads,
MaxDownloadsUnit: tt.fields.MaxDownloadsPer, MaxDownloadsUnit: tt.fields.MaxDownloadsUnit,
MatchReleases: tt.fields.MatchReleases, MatchReleases: tt.fields.MatchReleases,
ExceptReleases: tt.fields.ExceptReleases, ExceptReleases: tt.fields.ExceptReleases,
UseRegex: tt.fields.UseRegex, UseRegex: tt.fields.UseRegex,
@ -1575,6 +1522,8 @@ func TestFilter_CheckFilter1(t *testing.T) {
Cue: tt.fields.Cue, Cue: tt.fields.Cue,
Log: tt.fields.Log, Log: tt.fields.Log,
LogScore: tt.fields.LogScore, LogScore: tt.fields.LogScore,
MatchOther: tt.fields.MatchOther,
ExceptOther: tt.fields.ExceptOther,
MatchCategories: tt.fields.MatchCategories, MatchCategories: tt.fields.MatchCategories,
ExceptCategories: tt.fields.ExceptCategories, ExceptCategories: tt.fields.ExceptCategories,
MatchUploaders: tt.fields.MatchUploaders, MatchUploaders: tt.fields.MatchUploaders,
@ -1585,7 +1534,7 @@ func TestFilter_CheckFilter1(t *testing.T) {
ExceptTagsAny: tt.fields.ExceptTagsAny, ExceptTagsAny: tt.fields.ExceptTagsAny,
Actions: tt.fields.Actions, Actions: tt.fields.Actions,
Indexers: tt.fields.Indexers, Indexers: tt.fields.Indexers,
Downloads: tt.fields.State, Downloads: tt.fields.Downloads,
} }
tt.args.r.ParseString(tt.args.r.TorrentName) tt.args.r.ParseString(tt.args.r.TorrentName)
rejections, match := f.CheckFilter(tt.args.r) rejections, match := f.CheckFilter(tt.args.r)