feat(filters): add except origins (#396)

* feat(filters): add except origins

* feat(filters): add user origin
This commit is contained in:
ze0s 2022-08-03 12:47:32 +02:00 committed by GitHub
parent bd8db18a0e
commit 5d80e48b54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 5 deletions

View file

@ -67,6 +67,7 @@ type Filter struct {
ExceptReleaseGroups string `json:"except_release_groups,omitempty"`
Scene bool `json:"scene,omitempty"`
Origins []string `json:"origins,omitempty"`
ExceptOrigins []string `json:"except_origins,omitempty"`
Bonus []string `json:"bonus,omitempty"`
Freeleech bool `json:"freeleech,omitempty"`
FreeleechPercent string `json:"freeleech_percent,omitempty"`
@ -140,6 +141,9 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) {
if len(f.Origins) > 0 && !containsSlice(r.Origin, f.Origins) {
r.addRejectionF("origin not matching. got: %v want: %v", r.Origin, f.Origins)
}
if len(f.ExceptOrigins) > 0 && containsSlice(r.Origin, f.ExceptOrigins) {
r.addRejectionF("except origin not matching. got: %v unwanted: %v", r.Origin, f.ExceptOrigins)
}
// title is the parsed title
if f.Shows != "" && !contains(r.Title, f.Shows) {

View file

@ -1017,6 +1017,7 @@ func TestFilter_CheckFilter1(t *testing.T) {
ExceptReleaseGroups string
Scene bool
Origins []string
ExceptOrigins []string
Freeleech bool
FreeleechPercent string
Shows string
@ -1510,6 +1511,24 @@ func TestFilter_CheckFilter1(t *testing.T) {
wantRejections: nil,
wantMatch: true,
},
{
name: "test_37",
fields: fields{
ExceptOrigins: []string{"Internal"},
},
args: args{&Release{TorrentName: "Gillan - Future Shock", Origin: "Internal"}},
wantRejections: []string{"except origin not matching. got: Internal unwanted: [Internal]"},
wantMatch: false,
},
{
name: "test_38",
fields: fields{
ExceptOrigins: []string{"Internal"},
},
args: args{&Release{TorrentName: "Gillan - Future Shock", Origin: "Scene"}},
wantRejections: nil,
wantMatch: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@ -1532,6 +1551,7 @@ func TestFilter_CheckFilter1(t *testing.T) {
ExceptReleaseGroups: tt.fields.ExceptReleaseGroups,
Scene: tt.fields.Scene,
Origins: tt.fields.Origins,
ExceptOrigins: tt.fields.ExceptOrigins,
Freeleech: tt.fields.Freeleech,
FreeleechPercent: tt.fields.FreeleechPercent,
Shows: tt.fields.Shows,

View file

@ -133,6 +133,7 @@ func init() {
{tag: "Scene", title: "Scene", regexp: "", re: nil},
{tag: "O-Scene", title: "O-Scene", regexp: "", re: nil},
{tag: "Internal", title: "Internal", regexp: "", re: nil},
{tag: "User", title: "User", regexp: "", re: nil},
}
types["origin"] = origin