mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
fix(filters): add support for year-less titles (#685)
* fix(filters): add support for year-less titles * chore: update pkg * fix: broken tests --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
27f8b14678
commit
af43c98632
5 changed files with 90 additions and 36 deletions
2
go.mod
2
go.mod
|
@ -23,7 +23,7 @@ require (
|
|||
github.com/lib/pq v1.10.7
|
||||
github.com/mattn/go-shellwords v1.0.12
|
||||
github.com/mmcdole/gofeed v1.1.3
|
||||
github.com/moistari/rls v0.5.5
|
||||
github.com/moistari/rls v0.5.6
|
||||
github.com/mrobinsn/go-rtorrent v1.8.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/r3labs/sse/v2 v2.8.1
|
||||
|
|
4
go.sum
4
go.sum
|
@ -319,8 +319,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
|
|||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/moistari/rls v0.5.5 h1:sVj1G5E2eIeqJQh9sdQ4THXCLEBlJElXVxoUwFBY9Uw=
|
||||
github.com/moistari/rls v0.5.5/go.mod h1:+VmEKlV6nBXzhGxyO9NoHIp8ywSQlm89UUGPNi8vZVc=
|
||||
github.com/moistari/rls v0.5.6 h1:fiKytdrlBfiXQomYLY/nuAyzzvz0zbY93FfO1CYJk30=
|
||||
github.com/moistari/rls v0.5.6/go.mod h1:+VmEKlV6nBXzhGxyO9NoHIp8ywSQlm89UUGPNi8vZVc=
|
||||
github.com/mrobinsn/go-rtorrent v1.8.0 h1:+61aDIP0asy57lRD/uZtmxfE0/gjkHnt3uddOhMKUJ8=
|
||||
github.com/mrobinsn/go-rtorrent v1.8.0/go.mod h1:CdVq2IwM+JU9D6TnWiQSg9lqZWu6zUfK67YXET2LqIM=
|
||||
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae/go.mod h1:qAyveg+e4CE+eKJXWVjKXM4ck2QobLqTDytGJbLLhJg=
|
||||
|
|
|
@ -934,7 +934,7 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
{
|
||||
name: "match_music_1",
|
||||
fields: &Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
TorrentName: "Artist - Albumname FLAC CD",
|
||||
ReleaseTags: "FLAC / 24bit Lossless / Log / 100% / Cue / CD",
|
||||
Category: "Album",
|
||||
},
|
||||
|
@ -956,7 +956,7 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
{
|
||||
name: "match_music_2",
|
||||
fields: &Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
TorrentName: "Artist-Albumname-SINGLE-WEB-2023-GROUP",
|
||||
ReleaseTags: "MP3 / 320 / WEB",
|
||||
Category: "Album",
|
||||
},
|
||||
|
@ -974,7 +974,7 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
{
|
||||
name: "match_music_3",
|
||||
fields: &Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
TorrentName: "Artist - Albumname FLAC CD",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / CD",
|
||||
Category: "Album",
|
||||
},
|
||||
|
@ -992,7 +992,7 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
{
|
||||
name: "match_music_4",
|
||||
fields: &Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
TorrentName: "Artist - Albumname FLAC CD",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / CD",
|
||||
Category: "Album",
|
||||
},
|
||||
|
@ -1016,7 +1016,7 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
{
|
||||
name: "match_music_5",
|
||||
fields: &Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
TorrentName: "Artist - Albumname FLAC CD",
|
||||
Year: 2022,
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / Cue / CD",
|
||||
Category: "Album",
|
||||
|
@ -1041,7 +1041,7 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
{
|
||||
name: "match_music_6",
|
||||
fields: &Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
TorrentName: "Artist - Albumname FLAC CD",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / Cue / CD",
|
||||
Category: "Album",
|
||||
},
|
||||
|
@ -1065,7 +1065,7 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
{
|
||||
name: "match_music_7",
|
||||
fields: &Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
TorrentName: "Artist - Albumname FLAC CD",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / Cue / CD",
|
||||
Category: "Album",
|
||||
},
|
||||
|
@ -1082,14 +1082,14 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
LogScore: 100,
|
||||
Cue: true,
|
||||
},
|
||||
rejections: []string{"artists not matching. got: Artist - Albumname want: Artiiiist", "log score. got: 0 want: 100"},
|
||||
rejections: []string{"artists not matching. got: Artist want: Artiiiist", "log score. got: 0 want: 100"},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "match_music_8",
|
||||
fields: &Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
TorrentName: "Artist - Albumname FLAC CD",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / Cue / CD",
|
||||
Category: "Album",
|
||||
},
|
||||
|
|
|
@ -237,30 +237,10 @@ func (r *Release) ParseReleaseTagsString(tags string) {
|
|||
|
||||
t := ParseReleaseTagString(cleanTags)
|
||||
|
||||
f := func(target *[]string, source []string) {
|
||||
toappend := make([]string, 0, len(source))
|
||||
for _, t := range *target {
|
||||
found := false
|
||||
norm := rls.MustNormalize(t)
|
||||
|
||||
for _, s := range source {
|
||||
if rls.MustNormalize(s) == norm {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
toappend = append(toappend, t)
|
||||
}
|
||||
}
|
||||
|
||||
*target = append(*target, toappend...)
|
||||
}
|
||||
|
||||
if len(t.Audio) > 0 {
|
||||
f(&r.Audio, t.Audio)
|
||||
r.Audio = getUniqueTags(r.Audio, t.Audio)
|
||||
}
|
||||
|
||||
if len(t.Bonus) > 0 {
|
||||
if sliceContainsSlice([]string{"Freeleech"}, t.Bonus) {
|
||||
r.Freeleech = true
|
||||
|
@ -270,10 +250,10 @@ func (r *Release) ParseReleaseTagsString(tags string) {
|
|||
r.Bonus = append(r.Bonus, t.Bonus...)
|
||||
}
|
||||
if len(t.Codec) > 0 {
|
||||
f(&r.Codec, append(make([]string, 0, 1), t.Codec))
|
||||
r.Codec = getUniqueTags(r.Codec, append(make([]string, 0, 1), t.Codec))
|
||||
}
|
||||
if len(t.Other) > 0 {
|
||||
f(&r.Other, t.Other)
|
||||
r.Other = getUniqueTags(r.Other, t.Other)
|
||||
}
|
||||
if r.Origin == "" && t.Origin != "" {
|
||||
r.Origin = t.Origin
|
||||
|
@ -593,3 +573,27 @@ func StringEqualFoldMulti(s string, values ...string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getUniqueTags(target []string, source []string) []string {
|
||||
toAppend := make([]string, 0, len(source))
|
||||
|
||||
for _, t := range source {
|
||||
found := false
|
||||
norm := rls.MustNormalize(t)
|
||||
|
||||
for _, s := range target {
|
||||
if rls.MustNormalize(s) == norm {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
toAppend = append(toAppend, t)
|
||||
}
|
||||
}
|
||||
|
||||
target = append(target, toAppend...)
|
||||
|
||||
return target
|
||||
}
|
||||
|
|
|
@ -858,3 +858,53 @@ func TestRelease_DownloadTorrentFile(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getUniqueTags(t *testing.T) {
|
||||
type args struct {
|
||||
target []string
|
||||
source []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "1",
|
||||
args: args{
|
||||
target: []string{},
|
||||
source: []string{"mp4"},
|
||||
},
|
||||
want: []string{"mp4"},
|
||||
},
|
||||
{
|
||||
name: "2",
|
||||
args: args{
|
||||
target: []string{"mp4"},
|
||||
source: []string{"mp4"},
|
||||
},
|
||||
want: []string{"mp4"},
|
||||
},
|
||||
{
|
||||
name: "3",
|
||||
args: args{
|
||||
target: []string{"mp4"},
|
||||
source: []string{"mp4", "dv"},
|
||||
},
|
||||
want: []string{"mp4", "dv"},
|
||||
},
|
||||
{
|
||||
name: "4",
|
||||
args: args{
|
||||
target: []string{"dv"},
|
||||
source: []string{"mp4", "dv"},
|
||||
},
|
||||
want: []string{"dv", "mp4"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equalf(t, tt.want, getUniqueTags(tt.args.target, tt.args.source), "getUniqueTags(%v, %v)", tt.args.target, tt.args.source)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue