mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(releases): releasetags freeleech parsing (#306)
* refactor(releases): remove err from constructor * fix(releases): freeleech parsing and filtering * chore: remove unused releaseinfo package
This commit is contained in:
parent
fd3f10f95a
commit
6675a1df3e
10 changed files with 79 additions and 618 deletions
|
@ -67,6 +67,7 @@ type Filter struct {
|
|||
ExceptReleaseGroups string `json:"except_release_groups"`
|
||||
Scene bool `json:"scene"`
|
||||
Origins []string `json:"origins"`
|
||||
Bonus []string `json:"bonus"`
|
||||
Freeleech bool `json:"freeleech"`
|
||||
FreeleechPercent string `json:"freeleech_percent"`
|
||||
Shows string `json:"shows"`
|
||||
|
@ -115,6 +116,10 @@ func (f Filter) CheckFilter(r *Release) ([]string, bool) {
|
|||
return r.Rejections, false
|
||||
}
|
||||
|
||||
if len(f.Bonus) > 0 && !sliceContainsSlice(r.Bonus, f.Bonus) {
|
||||
r.addRejectionF("bonus not matching. got: %v want: %v", r.Bonus, f.Bonus)
|
||||
}
|
||||
|
||||
if f.Freeleech && r.Freeleech != f.Freeleech {
|
||||
r.addRejection("wanted: freeleech")
|
||||
}
|
||||
|
@ -575,15 +580,6 @@ func containsAnySlice(tags []string, filters []string) bool {
|
|||
func checkFreeleechPercent(announcePercent int, filterPercent string) bool {
|
||||
filters := strings.Split(filterPercent, ",")
|
||||
|
||||
// remove % and trim spaces
|
||||
//announcePercent = strings.Replace(announcePercent, "%", "", -1)
|
||||
//announcePercent = strings.Trim(announcePercent, " ")
|
||||
|
||||
//announcePercentInt, err := strconv.ParseInt(announcePercent, 10, 32)
|
||||
//if err != nil {
|
||||
// return false
|
||||
//}
|
||||
|
||||
for _, s := range filters {
|
||||
s = strings.Replace(s, "%", "", -1)
|
||||
s = strings.Trim(s, " ")
|
||||
|
|
|
@ -954,12 +954,41 @@ func TestFilter_CheckFilter(t *testing.T) {
|
|||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "match_anime_1",
|
||||
fields: &Release{
|
||||
TorrentName: "Kaginado",
|
||||
ReleaseTags: "Web / MKV / h264 / 1080p / AAC 2.0 / Softsubs (SubsPlease) / Episode 22 / Freeleech",
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
Freeleech: true,
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "match_anime_2",
|
||||
fields: &Release{
|
||||
TorrentName: "Kaginado",
|
||||
ReleaseTags: "Web / MKV / h264 / 1080p / AAC 2.0 / Softsubs (SubsPlease) / Episode 22",
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
Freeleech: true,
|
||||
},
|
||||
rejections: []string{"wanted: freeleech"},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := tt.fields // Release
|
||||
|
||||
_ = r.ParseString(tt.fields.TorrentName) // Parse TorrentName into struct
|
||||
r.ParseString(tt.fields.TorrentName) // Parse TorrentName into struct
|
||||
rejections, got := tt.args.filter.CheckFilter(r)
|
||||
|
||||
assert.Equal(t, tt.want, got)
|
||||
|
|
|
@ -116,7 +116,8 @@ const (
|
|||
ReleasePushStatusApproved ReleasePushStatus = "PUSH_APPROVED"
|
||||
ReleasePushStatusRejected ReleasePushStatus = "PUSH_REJECTED"
|
||||
ReleasePushStatusErr ReleasePushStatus = "PUSH_ERROR"
|
||||
ReleasePushStatusPending ReleasePushStatus = "PENDING" // Initial status
|
||||
|
||||
//ReleasePushStatusPending ReleasePushStatus = "PENDING" // Initial status
|
||||
)
|
||||
|
||||
func (r ReleasePushStatus) String() string {
|
||||
|
@ -136,8 +137,9 @@ type ReleaseFilterStatus string
|
|||
|
||||
const (
|
||||
ReleaseStatusFilterApproved ReleaseFilterStatus = "FILTER_APPROVED"
|
||||
ReleaseStatusFilterRejected ReleaseFilterStatus = "FILTER_REJECTED"
|
||||
ReleaseStatusFilterPending ReleaseFilterStatus = "PENDING"
|
||||
|
||||
//ReleaseStatusFilterRejected ReleaseFilterStatus = "FILTER_REJECTED"
|
||||
)
|
||||
|
||||
type ReleaseProtocol string
|
||||
|
@ -165,7 +167,7 @@ type ReleaseQueryParams struct {
|
|||
Search string
|
||||
}
|
||||
|
||||
func NewRelease(indexer string) (*Release, error) {
|
||||
func NewRelease(indexer string) *Release {
|
||||
r := &Release{
|
||||
Indexer: indexer,
|
||||
FilterStatus: ReleaseStatusFilterPending,
|
||||
|
@ -176,10 +178,10 @@ func NewRelease(indexer string) (*Release, error) {
|
|||
Tags: []string{},
|
||||
}
|
||||
|
||||
return r, nil
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Release) ParseString(title string) error {
|
||||
func (r *Release) ParseString(title string) {
|
||||
rel := rls.ParseString(title)
|
||||
|
||||
r.TorrentName = title
|
||||
|
@ -204,12 +206,12 @@ func (r *Release) ParseString(title string) error {
|
|||
|
||||
r.ParseReleaseTagsString(r.ReleaseTags)
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
func (r *Release) ParseReleaseTagsString(tags string) error {
|
||||
func (r *Release) ParseReleaseTagsString(tags string) {
|
||||
// trim delimiters and closest space
|
||||
re := regexp.MustCompile(`\| |\/ |, `)
|
||||
re := regexp.MustCompile(`\| |/ |, `)
|
||||
cleanTags := re.ReplaceAllString(tags, "")
|
||||
|
||||
t := ParseReleaseTagString(cleanTags)
|
||||
|
@ -218,6 +220,11 @@ func (r *Release) ParseReleaseTagsString(tags string) error {
|
|||
r.Audio = append(r.Audio, t.Audio...)
|
||||
}
|
||||
if len(t.Bonus) > 0 {
|
||||
if sliceContainsSlice([]string{"Freeleech"}, t.Bonus) {
|
||||
r.Freeleech = true
|
||||
}
|
||||
// TODO handle percent and other types
|
||||
|
||||
r.Bonus = append(r.Bonus, t.Bonus...)
|
||||
}
|
||||
if len(t.Codec) > 0 {
|
||||
|
@ -240,7 +247,7 @@ func (r *Release) ParseReleaseTagsString(tags string) error {
|
|||
r.AudioChannels = t.Channels
|
||||
}
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
func (r *Release) ParseSizeBytesString(size string) {
|
||||
|
@ -385,8 +392,11 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
|
|||
//log.Debug().Msgf("bad freeleechPercent var: %v", year)
|
||||
}
|
||||
|
||||
r.Freeleech = true
|
||||
r.FreeleechPercent = freeleechPercentInt
|
||||
|
||||
r.Bonus = append(r.Bonus, "Freeleech")
|
||||
|
||||
switch freeleechPercentInt {
|
||||
case 25:
|
||||
r.Bonus = append(r.Bonus, "Freeleech25")
|
||||
|
@ -472,39 +482,6 @@ func getStringMapValue(stringMap map[string]string, key string) (string, error)
|
|||
return "", fmt.Errorf("key was not found in map: %q", lowerKey)
|
||||
}
|
||||
|
||||
func findLast(input string, pattern string) (string, error) {
|
||||
matched := make([]string, 0)
|
||||
//for _, s := range arr {
|
||||
|
||||
rxp, err := regexp.Compile(pattern)
|
||||
if err != nil {
|
||||
return "", err
|
||||
//return errors.Wrapf(err, "invalid regex: %s", value)
|
||||
}
|
||||
|
||||
matches := rxp.FindStringSubmatch(input)
|
||||
if matches != nil {
|
||||
// first value is the match, second value is the text
|
||||
if len(matches) >= 1 {
|
||||
last := matches[len(matches)-1]
|
||||
|
||||
// add to temp slice
|
||||
matched = append(matched, last)
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
// check if multiple values in temp slice, if so get the last one
|
||||
if len(matched) >= 1 {
|
||||
last := matched[len(matched)-1]
|
||||
|
||||
return last, nil
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func SplitAny(s string, seps string) []string {
|
||||
splitter := func(r rune) bool {
|
||||
return strings.ContainsRune(seps, r)
|
||||
|
|
|
@ -8,10 +8,9 @@ import (
|
|||
|
||||
func TestRelease_Parse(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fields Release
|
||||
want Release
|
||||
wantErr bool
|
||||
name string
|
||||
fields Release
|
||||
want Release
|
||||
}{
|
||||
{
|
||||
name: "parse_1",
|
||||
|
@ -32,7 +31,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
Group: "FLUX",
|
||||
//Website: "ATVP",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_2",
|
||||
|
@ -52,7 +50,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
HDR: []string{"DV"},
|
||||
Group: "FLUX",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_3",
|
||||
|
@ -75,7 +72,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
HDR: []string{"DV"},
|
||||
Group: "FLUX",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_4",
|
||||
|
@ -98,7 +94,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
HDR: []string{"DV"},
|
||||
Group: "FLUX",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_5",
|
||||
|
@ -121,7 +116,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
HDR: []string{"DV"},
|
||||
Group: "FLUX",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_6",
|
||||
|
@ -143,9 +137,9 @@ func TestRelease_Parse(t *testing.T) {
|
|||
AudioChannels: "5.1",
|
||||
HDR: []string{"DV"},
|
||||
Group: "FLUX",
|
||||
Freeleech: true,
|
||||
Bonus: []string{"Freeleech"},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_1",
|
||||
|
@ -161,7 +155,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
Audio: []string{"Cue", "FLAC", "Lossless", "Log100", "Log"},
|
||||
Source: "CD",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_2",
|
||||
|
@ -178,7 +171,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
Source: "Cassette",
|
||||
Audio: []string{"320", "MP3"},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_3",
|
||||
|
@ -194,7 +186,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
Source: "CD",
|
||||
Audio: []string{"MP3", "VBR"},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_4",
|
||||
|
@ -210,7 +201,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
Audio: []string{"Cue", "FLAC", "Lossless", "Log100", "Log"},
|
||||
Source: "CD",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_5",
|
||||
|
@ -226,7 +216,6 @@ func TestRelease_Parse(t *testing.T) {
|
|||
Audio: []string{"24BIT Lossless", "Cue", "FLAC", "Lossless", "Log100", "Log"},
|
||||
Source: "CD",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_movies_case_1",
|
||||
|
@ -246,15 +235,12 @@ func TestRelease_Parse(t *testing.T) {
|
|||
Group: "GROUP1",
|
||||
Other: []string{"HYBRiD", "REMUX"},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := tt.fields
|
||||
if err := r.ParseString(tt.fields.TorrentName); (err != nil) != tt.wantErr {
|
||||
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
r.ParseString(tt.fields.TorrentName)
|
||||
|
||||
assert.Equal(t, tt.want, r)
|
||||
})
|
||||
|
@ -307,8 +293,9 @@ func TestRelease_MapVars(t *testing.T) {
|
|||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Freeleech: true,
|
||||
FreeleechPercent: 100,
|
||||
Bonus: []string{"Freeleech100"},
|
||||
Bonus: []string{"Freeleech", "Freeleech100"},
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
},
|
||||
|
@ -326,8 +313,9 @@ func TestRelease_MapVars(t *testing.T) {
|
|||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Freeleech: true,
|
||||
FreeleechPercent: 50,
|
||||
Bonus: []string{"Freeleech50"},
|
||||
Bonus: []string{"Freeleech", "Freeleech50"},
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"foreign", "tv"},
|
||||
|
@ -347,8 +335,9 @@ func TestRelease_MapVars(t *testing.T) {
|
|||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Freeleech: true,
|
||||
FreeleechPercent: 100,
|
||||
Bonus: []string{"Freeleech100"},
|
||||
Bonus: []string{"Freeleech", "Freeleech100"},
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"foreign", "tv"},
|
||||
|
@ -369,8 +358,9 @@ func TestRelease_MapVars(t *testing.T) {
|
|||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Year: 2020,
|
||||
Freeleech: true,
|
||||
FreeleechPercent: 100,
|
||||
Bonus: []string{"Freeleech100"},
|
||||
Bonus: []string{"Freeleech", "Freeleech100"},
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"foreign", "tv"},
|
||||
|
@ -392,8 +382,9 @@ func TestRelease_MapVars(t *testing.T) {
|
|||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Year: 2020,
|
||||
Freeleech: true,
|
||||
FreeleechPercent: 25,
|
||||
Bonus: []string{"Freeleech25"},
|
||||
Bonus: []string{"Freeleech", "Freeleech25"},
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"hip.hop", "rhythm.and.blues", "2000s"},
|
||||
|
@ -415,8 +406,9 @@ func TestRelease_MapVars(t *testing.T) {
|
|||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Year: 2020,
|
||||
Freeleech: true,
|
||||
FreeleechPercent: 100,
|
||||
Bonus: []string{"Freeleech100"},
|
||||
Bonus: []string{"Freeleech", "Freeleech100"},
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"hip.hop", "rhythm.and.blues", "2000s"},
|
||||
|
@ -572,8 +564,7 @@ func TestRelease_ParseString(t *testing.T) {
|
|||
Filter: tt.fields.Filter,
|
||||
ActionStatus: tt.fields.ActionStatus,
|
||||
}
|
||||
_ = r.ParseString(tt.args.title)
|
||||
//fmt.Sprintf("ParseString(%v)", tt.args.title)
|
||||
r.ParseString(tt.args.title)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ func TestParseReleaseTagString(t *testing.T) {
|
|||
{name: "movies_6", args: args{tags: "H.264, DVD"}, want: ReleaseTags{Codec: "H.264", Source: "DVD"}},
|
||||
{name: "movies_7", args: args{tags: "H.264, DVD, Freeleech"}, want: ReleaseTags{Codec: "H.264", Source: "DVD", Bonus: []string{"Freeleech"}}},
|
||||
{name: "movies_8", args: args{tags: "H.264, DVD, Freeleech!"}, want: ReleaseTags{Codec: "H.264", Source: "DVD", Bonus: []string{"Freeleech"}}},
|
||||
{name: "anime_1", args: args{tags: "Web / MKV / h264 / 1080p / AAC 2.0 / Softsubs (SubsPlease) / Episode 22 / Freeleech"}, want: ReleaseTags{Audio: []string{"AAC"}, Channels: "2.0", Source: "WEB", Resolution: "1080p", Container: "iso", Codec: "H.264", Bonus: []string{"Freeleech"}}},
|
||||
{name: "anime_2", args: args{tags: "Web | MKV | h264 | 1080p | AAC 2.0 | Softsubs (SubsPlease) | Episode 22 | Freeleech"}, want: ReleaseTags{Audio: []string{"AAC"}, Channels: "2.0", Source: "WEB", Resolution: "1080p", Container: "iso", Codec: "H.264", Bonus: []string{"Freeleech"}}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue