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

@ -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, "-", ""))