mirror of
https://github.com/stashapp/stash.git
synced 2025-12-30 04:03:17 +01:00
Added multiple images to Performer XPath Scraper
This commit is contained in:
parent
034fd4407d
commit
71a06350c5
1 changed files with 19 additions and 6 deletions
|
|
@ -11,9 +11,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/robertkrimen/otto"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/stashapp/stash/pkg/javascript"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil"
|
||||
|
|
@ -230,14 +230,17 @@ func (s *mappedGalleryScraperConfig) UnmarshalYAML(unmarshal func(interface{}) e
|
|||
|
||||
type mappedPerformerScraperConfig struct {
|
||||
mappedConfig
|
||||
|
||||
Tags mappedConfig `yaml:"Tags"`
|
||||
Images mappedConfig `yaml:"Images"`
|
||||
Tags mappedConfig `yaml:"Tags"`
|
||||
}
|
||||
type _mappedPerformerScraperConfig mappedPerformerScraperConfig
|
||||
|
||||
const (
|
||||
mappedScraperConfigPerformerTags = "Tags"
|
||||
)
|
||||
const (
|
||||
mappedScraperConfigPerformerImages = "Images"
|
||||
)
|
||||
|
||||
func (s *mappedPerformerScraperConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
// HACK - unmarshal to map first, then remove known scene sub-fields, then
|
||||
|
|
@ -251,8 +254,10 @@ func (s *mappedPerformerScraperConfig) UnmarshalYAML(unmarshal func(interface{})
|
|||
thisMap := make(map[string]interface{})
|
||||
|
||||
thisMap[mappedScraperConfigPerformerTags] = parentMap[mappedScraperConfigPerformerTags]
|
||||
thisMap[mappedScraperConfigPerformerImages] = parentMap[mappedScraperConfigPerformerImages]
|
||||
|
||||
delete(parentMap, mappedScraperConfigPerformerTags)
|
||||
delete(parentMap, mappedScraperConfigPerformerImages)
|
||||
|
||||
// re-unmarshal the sub-fields
|
||||
yml, err := yaml.Marshal(thisMap)
|
||||
|
|
@ -528,19 +533,19 @@ func (p *postProcessLbToKg) Apply(ctx context.Context, value string, q mappedQue
|
|||
type postProcessJavascript string
|
||||
|
||||
func (p *postProcessJavascript) Apply(ctx context.Context, value string, q mappedQuery) string {
|
||||
vm := javascript.NewVM()
|
||||
vm := otto.New()
|
||||
if err := vm.Set("value", value); err != nil {
|
||||
logger.Warnf("javascript failed to set value: %v", err)
|
||||
return value
|
||||
}
|
||||
|
||||
script, err := javascript.CompileScript("", "(function() { "+string(*p)+"})()")
|
||||
script, err := vm.Compile("", "(function() { "+string(*p)+"})()")
|
||||
if err != nil {
|
||||
logger.Warnf("javascript failed to compile: %v", err)
|
||||
return value
|
||||
}
|
||||
|
||||
output, err := vm.RunProgram(script)
|
||||
output, err := vm.Run(script)
|
||||
if err != nil {
|
||||
logger.Warnf("javascript failed to run: %v", err)
|
||||
return value
|
||||
|
|
@ -819,6 +824,7 @@ func (s mappedScraper) scrapePerformer(ctx context.Context, q mappedQuery) (*mod
|
|||
}
|
||||
|
||||
performerTagsMap := performerMap.Tags
|
||||
performerImagesMap := performerMap.Images
|
||||
|
||||
results := performerMap.process(ctx, q, s.Common)
|
||||
|
||||
|
|
@ -834,6 +840,13 @@ func (s mappedScraper) scrapePerformer(ctx context.Context, q mappedQuery) (*mod
|
|||
}
|
||||
}
|
||||
|
||||
if performerImagesMap != nil {
|
||||
imageResults := performerImagesMap.process(ctx, q, s.Common)
|
||||
for _, p := range imageResults {
|
||||
ret.Images = append(ret.Images, p["URL"])
|
||||
}
|
||||
}
|
||||
|
||||
if len(results) == 0 && len(ret.Tags) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue