feat(indexers): mam parse vip as freeleech (#407)

This commit is contained in:
ze0s 2022-08-12 16:13:45 +02:00 committed by GitHub
parent 7deac6a781
commit 9c036033e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View file

@ -384,7 +384,7 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
}
if freeleech, err := getStringMapValue(varMap, "freeleech"); err == nil {
fl := strings.EqualFold(freeleech, "freeleech") || strings.EqualFold(freeleech, "yes") || strings.EqualFold(freeleech, "1")
fl := StringEqualFoldMulti(freeleech, "freeleech", "yes", "1", "VIP")
if fl {
r.Freeleech = true
r.Bonus = append(r.Bonus, "Freeleech")
@ -441,7 +441,7 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
}
if scene, err := getStringMapValue(varMap, "scene"); err == nil {
r.IsScene = strings.EqualFold(scene, "true") || strings.EqualFold(scene, "yes")
r.IsScene = StringEqualFoldMulti(scene, "true", "yes")
}
// set origin. P2P, SCENE, O-SCENE and Internal
@ -505,3 +505,12 @@ func SplitAny(s string, seps string) []string {
}
return strings.FieldsFunc(s, splitter)
}
func StringEqualFoldMulti(s string, values ...string) bool {
for _, value := range values {
if strings.EqualFold(s, value) {
return true
}
}
return false
}

View file

@ -444,6 +444,27 @@ func TestRelease_MapVars(t *testing.T) {
"uploader": "Tester",
}},
},
{
name: "10",
fields: &Release{},
want: &Release{
TorrentName: "Greatest Anime Ever",
Year: 2022,
Group: "GROUP1",
Tags: []string{"comedy", "fantasy", "school.life", "shounen", "slice.of.life"},
Uploader: "Tester",
Freeleech: true,
Bonus: []string{"Freeleech"},
},
args: args{varMap: map[string]string{
"torrentName": "Greatest Anime Ever",
"year": "2022",
"releaseGroup": "GROUP1",
"tags": "comedy, fantasy, school.life, shounen, slice.of.life",
"uploader": "Tester",
"freeleech": "VIP",
}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {