fix(releases): improve tags parsing (#459)

This commit is contained in:
ze0s 2022-09-10 21:26:26 +02:00 committed by GitHub
parent bbb8d2fe6e
commit dc309a57e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View file

@ -464,8 +464,12 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
}
if tags, err := getStringMapValue(varMap, "tags"); err == nil {
tagArr := strings.Split(strings.ReplaceAll(tags, " ", ""), ",")
r.Tags = tagArr
tagsArr := []string{}
s := strings.Split(tags, ",")
for _, t := range s {
tagsArr = append(tagsArr, strings.Trim(t, " "))
}
r.Tags = tagsArr
}
if title, err := getStringMapValue(varMap, "title"); err == nil {
@ -486,7 +490,7 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
}
if episodeVal, err := getStringMapValue(varMap, "releaseEpisode"); err == nil {
episode, _ := strconv.Atoi(episodeVal);
episode, _ := strconv.Atoi(episodeVal)
r.Episode = episode
}

View file

@ -465,6 +465,29 @@ func TestRelease_MapVars(t *testing.T) {
"freeleech": "VIP",
}},
},
{
name: "11",
fields: &Release{},
want: &Release{
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
Category: "tv",
Freeleech: true,
Bonus: []string{"Freeleech"},
Uploader: "Anon",
Size: uint64(10000000000),
Tags: []string{"comedy", "science fiction", "fantasy", "school.life", "shounen", "slice.of.life"},
},
args: args{
varMap: map[string]string{
"torrentName": "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
"category": "tv",
"tags": "comedy, science fiction, fantasy, school.life, shounen, slice.of.life",
"freeleech": "freeleech",
"uploader": "Anon",
"torrentSize": "10GB",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {