mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
Stash scraper scene query (#5722)
* Enable scene querying in stash scraper * Update docs
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -251,7 +251,7 @@ sceneByURL:
|
||||
|
||||
### Stash
|
||||
|
||||
A different stash server can be configured as a scraping source. This action applies only to `performerByName`, `performerByFragment`, and `sceneByFragment` types. This action requires that the top-level `stashServer` field is configured.
|
||||
A different stash server can be configured as a scraping source. This action applies only to `performerByName`, `performerByFragment`, `sceneByName`, `sceneByQueryFragment` and `sceneByFragment`, types. This action requires that the top-level `stashServer` field is configured.
|
||||
|
||||
`stashServer` contains a single `url` field for the remote stash server. The username and password can be embedded in this string using `username:password@host`. Alternatively, the `apiKey` field can be used to authenticate with the remote stash server.
|
||||
|
||||
@@ -265,6 +265,10 @@ performerByFragment:
|
||||
action: stash
|
||||
sceneByFragment:
|
||||
action: stash
|
||||
sceneByName:
|
||||
action: stash
|
||||
sceneByQueryFragment:
|
||||
action: stash
|
||||
stashServer:
|
||||
apiKey: <api key>
|
||||
url: http://stashserver.com:9999
|
||||
|
||||
Reference in New Issue
Block a user