Get distinct values from scraper (#1338)

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
bnkai
2021-04-29 04:38:55 +03:00
committed by GitHub
parent 502d99de1b
commit 597576f5e6
5 changed files with 73 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
"gopkg.in/yaml.v2"
)
@@ -73,7 +74,9 @@ func (s mappedConfig) postProcess(q mappedQuery, attrConfig mappedScraperAttrCon
result := attrConfig.concatenateResults(found)
result = attrConfig.postProcess(result, q)
if attrConfig.hasSplit() {
return attrConfig.splitString(result)
results := attrConfig.splitString(result)
results = attrConfig.distinctResults(results)
return results
}
ret = []string{result}
@@ -86,6 +89,7 @@ func (s mappedConfig) postProcess(q mappedQuery, attrConfig mappedScraperAttrCon
ret = append(ret, text)
}
ret = attrConfig.distinctResults(ret)
}
return ret
@@ -639,6 +643,10 @@ func (c mappedScraperAttrConfig) concatenateResults(nodes []string) string {
return strings.Join(result, separator)
}
func (c mappedScraperAttrConfig) distinctResults(nodes []string) []string {
return utils.StrUnique(nodes)
}
func (c mappedScraperAttrConfig) splitString(value string) []string {
separator := c.Split
var res []string