mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Add lbToKg pp action to the scraper (#1337)
This commit is contained in:
@@ -462,12 +462,25 @@ func (p *postProcessFeetToCm) Apply(value string, q mappedQuery) string {
|
||||
return strconv.Itoa(int(math.Round(centimeters)))
|
||||
}
|
||||
|
||||
type postProcessLbToKg bool
|
||||
|
||||
func (p *postProcessLbToKg) Apply(value string, q mappedQuery) string {
|
||||
const lb_in_kg = 0.45359237
|
||||
w, err := strconv.ParseFloat(value, 64)
|
||||
if err == nil {
|
||||
w = w * lb_in_kg
|
||||
value = strconv.Itoa(int(math.Round(w)))
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
type mappedPostProcessAction struct {
|
||||
ParseDate string `yaml:"parseDate"`
|
||||
Replace mappedRegexConfigs `yaml:"replace"`
|
||||
SubScraper *mappedScraperAttrConfig `yaml:"subScraper"`
|
||||
Map map[string]string `yaml:"map"`
|
||||
FeetToCm bool `yaml:"feetToCm"`
|
||||
LbToKg bool `yaml:"lbToKg"`
|
||||
}
|
||||
|
||||
func (a mappedPostProcessAction) ToPostProcessAction() (postProcessAction, error) {
|
||||
@@ -511,6 +524,14 @@ func (a mappedPostProcessAction) ToPostProcessAction() (postProcessAction, error
|
||||
action := postProcessFeetToCm(a.FeetToCm)
|
||||
ret = &action
|
||||
}
|
||||
if a.LbToKg {
|
||||
if found != "" {
|
||||
return nil, fmt.Errorf("post-process actions must have a single field, found %s and %s", found, "lbToKg")
|
||||
}
|
||||
found = "lbToKg"
|
||||
action := postProcessLbToKg(a.LbToKg)
|
||||
ret = &action
|
||||
}
|
||||
|
||||
if ret == nil {
|
||||
return nil, errors.New("invalid post-process action")
|
||||
|
||||
Reference in New Issue
Block a user