feat: add hdr filtering (#86)

* feat: filter hdr content

* feat: check filter hdr

* feat: improve hdr parse and filter and tests
This commit is contained in:
Ludvig Lundgren 2022-01-16 13:50:21 +01:00 committed by GitHub
parent 67c6bd7b53
commit 284a2f9590
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 284 additions and 22 deletions

View file

@ -48,6 +48,8 @@ type Filter struct {
Codecs []string `json:"codecs"` // XviD, DivX, x264, h.264 (or h264), mpeg2 (or mpeg-2), VC-1 (or VC1), WMV, Remux, h.264 Remux (or h264 Remux), VC-1 Remux (or VC1 Remux).
Sources []string `json:"sources"` // DSR, PDTV, HDTV, HR.PDTV, HR.HDTV, DVDRip, DVDScr, BDr, BD5, BD9, BDRip, BRRip, DVDR, MDVDR, HDDVD, HDDVDRip, BluRay, WEB-DL, TVRip, CAM, R5, TELESYNC, TS, TELECINE, TC. TELESYNC and TS are synonyms (you don't need both). Same for TELECINE and TC
Containers []string `json:"containers"`
MatchHDR []string `json:"match_hdr"`
ExceptHDR []string `json:"except_hdr"`
Years string `json:"years"`
Artists string `json:"artists"`
Albums string `json:"albums"`

View file

@ -248,7 +248,7 @@ func (r *Release) extractContainerFromTags(tag string) error {
}
func (r *Release) extractHDR() error {
v, err := findLast(r.TorrentName, `(?i)(HDR10\+|HDR10|DoVi HDR|DV HDR|HDR|DV|DoVi|Dolby Vision \+ HDR10|Dolby Vision)`)
v, err := findLast(r.TorrentName, `(?i)[\. ](HDR10\+|HDR10|DoVi[\. ]HDR|DV[\. ]HDR10\+|DV[\. ]HDR10|DV[\. ]HDR|HDR|DV|DoVi|Dolby[\. ]Vision[\. ]\+[\. ]HDR10|Dolby[\. ]Vision)[\. ]`)
if err != nil {
return err
}
@ -711,6 +711,16 @@ func (r *Release) CheckFilter(filter Filter) bool {
return false
}
if len(filter.MatchHDR) > 0 && !checkMultipleFilterHDR(filter.MatchHDR, r.HDR, r.TorrentName) {
r.addRejection("hdr not matching")
return false
}
if len(filter.ExceptHDR) > 0 && checkMultipleFilterHDR(filter.ExceptHDR, r.HDR, r.TorrentName) {
r.addRejection("unwanted hdr")
return false
}
if filter.Years != "" && !checkFilterIntStrings(r.Year, filter.Years) {
r.addRejection("year not matching")
return false
@ -1017,6 +1027,34 @@ func checkMultipleFilterGroups(filterList string, vars ...string) bool {
return false
}
func checkMultipleFilterHDR(filterList []string, vars ...string) bool {
for _, name := range vars {
name = strings.ToLower(name)
for _, s := range filterList {
s = strings.ToLower(strings.Trim(s, " "))
// check if line contains * or ?, if so try wildcard match, otherwise try substring match
a := strings.ContainsAny(s, "?|*")
if a {
match := wildcard.Match(s, name)
if match {
return true
}
} else {
split := SplitAny(name, " .-")
for _, c := range split {
if c == s {
return true
}
}
continue
}
}
}
return false
}
func checkFilterSource(name string, filterList []string) bool {
// remove dash (-) in blu-ray web-dl and make lowercase
name = strings.ToLower(strings.ReplaceAll(name, "-", ""))

View file

@ -863,6 +863,174 @@ func TestRelease_CheckFilter(t *testing.T) {
},
want: false,
},
{
name: "match_hdr_1",
fields: &Release{
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP",
Category: "TV",
Uploader: "Uploader1",
},
args: args{
filter: Filter{
Enabled: true,
MatchCategories: "*tv*",
MatchUploaders: "Uploader1,Uploader2",
ExceptUploaders: "Anonymous",
Shows: "Good show shift",
MatchReleaseGroups: "GROUP",
ExceptReleases: "NORDiC",
MatchHDR: []string{"DV", "HDR"},
},
},
want: true,
},
{
name: "match_hdr_2",
fields: &Release{
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos DoVi HEVC-GROUP",
Category: "TV",
Uploader: "Uploader1",
},
args: args{
filter: Filter{
Enabled: true,
MatchCategories: "*tv*",
MatchUploaders: "Uploader1,Uploader2",
ExceptUploaders: "Anonymous",
Shows: "Good show shift",
MatchReleaseGroups: "GROUP",
ExceptReleases: "NORDiC",
MatchHDR: []string{"DV", "HDR"},
},
},
want: false,
},
{
name: "match_hdr_3",
fields: &Release{
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos DoVi HEVC-GROUP",
Category: "TV",
Uploader: "Uploader1",
},
args: args{
filter: Filter{
Enabled: true,
MatchCategories: "*tv*",
MatchUploaders: "Uploader1,Uploader2",
ExceptUploaders: "Anonymous",
Shows: "Good show shift",
MatchReleaseGroups: "GROUP",
ExceptReleases: "NORDiC",
ExceptHDR: []string{"DV", "HDR", "DoVi"},
},
},
want: false,
},
{
name: "match_hdr_4",
fields: &Release{
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos HEVC-GROUP",
Category: "TV",
Uploader: "Uploader1",
},
args: args{
filter: Filter{
Enabled: true,
MatchCategories: "*tv*",
MatchUploaders: "Uploader1,Uploader2",
ExceptUploaders: "Anonymous",
Shows: "Good show shift",
MatchReleaseGroups: "GROUP",
ExceptReleases: "NORDiC",
MatchHDR: []string{"DV", "HDR", "DoVi"},
},
},
want: false,
},
{
name: "match_hdr_5",
fields: &Release{
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos HEVC-GROUP",
Category: "TV",
Uploader: "Uploader1",
},
args: args{
filter: Filter{
Enabled: true,
MatchCategories: "*tv*",
MatchUploaders: "Uploader1,Uploader2",
ExceptUploaders: "Anonymous",
Shows: "Good show shift",
MatchReleaseGroups: "GROUP",
ExceptReleases: "NORDiC",
ExceptHDR: []string{"DV", "HDR", "DoVi"},
},
},
want: true,
},
{
name: "match_hdr_6",
fields: &Release{
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos HDR HEVC-GROUP",
Category: "TV",
Uploader: "Uploader1",
},
args: args{
filter: Filter{
Enabled: true,
MatchCategories: "*tv*",
MatchUploaders: "Uploader1,Uploader2",
ExceptUploaders: "Anonymous",
Shows: "Good show shift",
MatchReleaseGroups: "GROUP",
ExceptReleases: "NORDiC",
ExceptHDR: []string{"DV", "DoVi"},
},
},
want: true,
},
{
name: "match_hdr_7",
fields: &Release{
TorrentName: "Good show dvorak shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos HDR HEVC-GROUP",
Category: "TV",
Uploader: "Uploader1",
},
args: args{
filter: Filter{
Enabled: true,
MatchCategories: "*tv*",
MatchUploaders: "Uploader1,Uploader2",
ExceptUploaders: "Anonymous",
Shows: "Good show dvorak shift",
MatchReleaseGroups: "GROUP",
ExceptReleases: "NORDiC",
ExceptHDR: []string{"DV", "DoVi"},
},
},
want: true,
},
{
name: "match_hdr_8",
fields: &Release{
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos HDR10+ HEVC-GROUP",
Category: "TV",
Uploader: "Uploader1",
},
args: args{
filter: Filter{
Enabled: true,
MatchCategories: "*tv*",
MatchUploaders: "Uploader1,Uploader2",
ExceptUploaders: "Anonymous",
Shows: "Good show shift",
MatchReleaseGroups: "GROUP",
ExceptReleases: "NORDiC",
MatchHDR: []string{"DV", "DoVi", "HDR10+"},
},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {