Stash scraper scene query (#5722)

* Enable scene querying in stash scraper
* Update docs
This commit is contained in:
WithoutPants
2025-03-17 10:20:08 +11:00
committed by GitHub
parent 193b175618
commit bc923929bb
2 changed files with 57 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ type stashFindPerformerNamePerformer struct {
func (p stashFindPerformerNamePerformer) toPerformer() *models.ScrapedPerformer {
return &models.ScrapedPerformer{
Name: &p.Name,
// put id into the URL field
// HACK - put id into the URL field
URL: &p.ID,
}
}
@@ -107,16 +107,18 @@ func (s *stashScraper) imageGetter() imageGetter {
}
func (s *stashScraper) scrapeByFragment(ctx context.Context, input Input) (ScrapedContent, error) {
if input.Gallery != nil || input.Scene != nil {
return nil, fmt.Errorf("%w: using stash scraper as a fragment scraper", ErrNotSupported)
if input.Performer != nil {
return s.scrapeByPerformerFragment(ctx, *input.Performer)
}
if input.Performer == nil {
return nil, fmt.Errorf("%w: the given performer is nil", ErrNotSupported)
if input.Scene != nil {
return s.scrapeBySceneFragment(ctx, *input.Scene)
}
scrapedPerformer := input.Performer
return nil, fmt.Errorf("%w: using stash scraper as a fragment scraper", ErrNotSupported)
}
func (s *stashScraper) scrapeByPerformerFragment(ctx context.Context, scrapedPerformer ScrapedPerformerInput) (ScrapedContent, error) {
client := s.getStashClient()
var q struct {
@@ -168,6 +170,45 @@ func (s *stashScraper) scrapeByFragment(ctx context.Context, input Input) (Scrap
return &ret, nil
}
func (s *stashScraper) scrapeBySceneFragment(ctx context.Context, scrapedScene ScrapedSceneInput) (ScrapedContent, error) {
client := s.getStashClient()
var q struct {
FindScene *scrapedSceneStash `graphql:"findScene(id: $f)"`
}
sceneID := scrapedScene.URLs[0]
// get the id from the URL field
vars := map[string]interface{}{
"f": graphql.ID(sceneID),
}
err := client.Query(ctx, &q, vars)
if err != nil {
return nil, convertGraphqlError(err)
}
if q.FindScene == nil {
return nil, nil
}
// need to copy back to a scraped scene
ret, err := s.scrapedStashSceneToScrapedScene(ctx, q.FindScene)
if err != nil {
return nil, err
}
// get the scene image directly
ig := s.imageGetter()
ret.Image, err = getStashSceneImage(ctx, s.config.StashServer.URL, q.FindScene.ID, ig)
if err != nil {
return nil, err
}
return ret, nil
}
type scrapedStudioStash struct {
Name string `graphql:"name" json:"name"`
URL *string `graphql:"url" json:"url"`
@@ -232,6 +273,10 @@ func (s *stashScraper) scrapeByName(ctx context.Context, name string, ty ScrapeC
if err != nil {
return nil, err
}
// HACK - put id into the URL field
// put id into the URL field
converted.URLs = []string{scene.ID}
ret = append(ret, converted)
}
@@ -334,7 +379,7 @@ func (s *stashScraper) scrapeSceneByScene(ctx context.Context, scene *models.Sce
return nil, err
}
// get the performer image directly
// get the scene image directly
ig := s.imageGetter()
ret.Image, err = getStashSceneImage(ctx, s.config.StashServer.URL, q.FindScene.ID, ig)
if err != nil {