From 9813f5718d748a434434e55881e51849b8890498 Mon Sep 17 00:00:00 2001 From: ze0s <43699394+zze0s@users.noreply.github.com> Date: Sat, 27 Aug 2022 14:54:41 +0200 Subject: [PATCH] fix(filters): check `match other` and `except other` (#433) fix(filters): check other and excpet other --- internal/domain/filter.go | 10 ++++ internal/domain/filter_test.go | 97 ++++++++-------------------------- 2 files changed, 33 insertions(+), 74 deletions(-) diff --git a/internal/domain/filter.go b/internal/domain/filter.go index 9d24ef2..dbe1e9f 100644 --- a/internal/domain/filter.go +++ b/internal/domain/filter.go @@ -286,6 +286,16 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) { 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) { r.addRejectionF("year not matching. got: %d want: %v", r.Year, f.Years) } diff --git a/internal/domain/filter_test.go b/internal/domain/filter_test.go index 6d43972..7ee49fb 100644 --- a/internal/domain/filter_test.go +++ b/internal/domain/filter_test.go @@ -2,7 +2,6 @@ package domain import ( "testing" - "time" "github.com/stretchr/testify/assert" ) @@ -998,61 +997,7 @@ func TestFilter_CheckFilter(t *testing.T) { } func TestFilter_CheckFilter1(t *testing.T) { - type fields struct { - 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 fields Filter type args struct { r *Release } @@ -1205,9 +1150,10 @@ func TestFilter_CheckFilter1(t *testing.T) { Sources: []string{"BluRay"}, Codecs: []string{"x265", "HEVC"}, 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"}}, - 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, }, { @@ -1217,6 +1163,7 @@ func TestFilter_CheckFilter1(t *testing.T) { Sources: []string{"UHD.BluRay"}, Codecs: []string{"x265", "HEVC"}, 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"}}, wantRejections: nil, @@ -1447,9 +1394,9 @@ func TestFilter_CheckFilter1(t *testing.T) { { name: "test_32", fields: fields{ - MaxDownloads: 1, - MaxDownloadsPer: FilterMaxDownloadsMonth, - State: &FilterDownloads{ + MaxDownloads: 1, + MaxDownloadsUnit: FilterMaxDownloadsMonth, + Downloads: &FilterDownloads{ MonthCount: 0, }, }, @@ -1460,9 +1407,9 @@ func TestFilter_CheckFilter1(t *testing.T) { { name: "test_33", fields: fields{ - MaxDownloads: 10, - MaxDownloadsPer: FilterMaxDownloadsMonth, - State: &FilterDownloads{ + MaxDownloads: 10, + MaxDownloadsUnit: FilterMaxDownloadsMonth, + Downloads: &FilterDownloads{ MonthCount: 10, }, }, @@ -1473,9 +1420,9 @@ func TestFilter_CheckFilter1(t *testing.T) { { name: "test_34", fields: fields{ - MaxDownloads: 10, - MaxDownloadsPer: FilterMaxDownloadsMonth, - State: &FilterDownloads{ + MaxDownloads: 10, + MaxDownloadsUnit: FilterMaxDownloadsMonth, + Downloads: &FilterDownloads{ MonthCount: 50, }, }, @@ -1486,9 +1433,9 @@ func TestFilter_CheckFilter1(t *testing.T) { { name: "test_35", fields: fields{ - MaxDownloads: 15, - MaxDownloadsPer: FilterMaxDownloadsHour, - State: &FilterDownloads{ + MaxDownloads: 15, + MaxDownloadsUnit: FilterMaxDownloadsHour, + Downloads: &FilterDownloads{ HourCount: 20, MonthCount: 50, }, @@ -1500,9 +1447,9 @@ func TestFilter_CheckFilter1(t *testing.T) { { name: "test_36", fields: fields{ - MaxDownloads: 15, - MaxDownloadsPer: FilterMaxDownloadsHour, - State: &FilterDownloads{ + MaxDownloads: 15, + MaxDownloadsUnit: FilterMaxDownloadsHour, + Downloads: &FilterDownloads{ HourCount: 14, MonthCount: 50, }, @@ -1543,7 +1490,7 @@ func TestFilter_CheckFilter1(t *testing.T) { Delay: tt.fields.Delay, Priority: tt.fields.Priority, MaxDownloads: tt.fields.MaxDownloads, - MaxDownloadsUnit: tt.fields.MaxDownloadsPer, + MaxDownloadsUnit: tt.fields.MaxDownloadsUnit, MatchReleases: tt.fields.MatchReleases, ExceptReleases: tt.fields.ExceptReleases, UseRegex: tt.fields.UseRegex, @@ -1575,6 +1522,8 @@ func TestFilter_CheckFilter1(t *testing.T) { Cue: tt.fields.Cue, Log: tt.fields.Log, LogScore: tt.fields.LogScore, + MatchOther: tt.fields.MatchOther, + ExceptOther: tt.fields.ExceptOther, MatchCategories: tt.fields.MatchCategories, ExceptCategories: tt.fields.ExceptCategories, MatchUploaders: tt.fields.MatchUploaders, @@ -1585,7 +1534,7 @@ func TestFilter_CheckFilter1(t *testing.T) { ExceptTagsAny: tt.fields.ExceptTagsAny, Actions: tt.fields.Actions, Indexers: tt.fields.Indexers, - Downloads: tt.fields.State, + Downloads: tt.fields.Downloads, } tt.args.r.ParseString(tt.args.r.TorrentName) rejections, match := f.CheckFilter(tt.args.r)