Add gallery scraping (#862)

This commit is contained in:
SpedNSFW
2020-10-21 09:24:32 +11:00
committed by GitHub
parent 872bb70f6e
commit 147d0067f5
19 changed files with 1296 additions and 1 deletions

View File

@@ -184,6 +184,68 @@ func (s *stashScraper) scrapeSceneByFragment(scene models.SceneUpdateInput) (*mo
return &ret, nil
}
func (s *stashScraper) scrapeGalleryByFragment(scene models.GalleryUpdateInput) (*models.ScrapedGallery, error) {
// query by MD5
// assumes that the gallery exists in the database
qb := models.NewGalleryQueryBuilder()
id, err := strconv.Atoi(scene.ID)
if err != nil {
return nil, err
}
storedGallery, err := qb.Find(id, nil)
if err != nil {
return nil, err
}
var q struct {
FindGallery *models.ScrapedGalleryStash `graphql:"findGalleryByHash(input: $c)"`
}
type GalleryHashInput struct {
Checksum *string `graphql:"checksum" json:"checksum"`
}
input := GalleryHashInput{
Checksum: &storedGallery.Checksum,
}
vars := map[string]interface{}{
"c": &input,
}
client := s.getStashClient()
err = client.Query(context.Background(), &q, vars)
if err != nil {
return nil, err
}
if q.FindGallery != nil {
// the ids of the studio, performers and tags must be nilled
if q.FindGallery.Studio != nil {
q.FindGallery.Studio.ID = nil
}
for _, p := range q.FindGallery.Performers {
p.ID = nil
}
for _, t := range q.FindGallery.Tags {
t.ID = nil
}
}
// need to copy back to a scraped scene
ret := models.ScrapedGallery{}
err = copier.Copy(&ret, q.FindGallery)
if err != nil {
return nil, err
}
return &ret, nil
}
func (s *stashScraper) scrapePerformerByURL(url string) (*models.ScrapedPerformer, error) {
return nil, errors.New("scrapePerformerByURL not supported for stash scraper")
}
@@ -192,6 +254,10 @@ func (s *stashScraper) scrapeSceneByURL(url string) (*models.ScrapedScene, error
return nil, errors.New("scrapeSceneByURL not supported for stash scraper")
}
func (s *stashScraper) scrapeGalleryByURL(url string) (*models.ScrapedGallery, error) {
return nil, errors.New("scrapeGalleryByURL not supported for stash scraper")
}
func (s *stashScraper) scrapeMovieByURL(url string) (*models.ScrapedMovie, error) {
return nil, errors.New("scrapeMovieByURL not supported for stash scraper")
}
@@ -206,3 +272,13 @@ func sceneFromUpdateFragment(scene models.SceneUpdateInput) (*models.Scene, erro
// TODO - should we modify it with the input?
return qb.Find(id)
}
func galleryFromUpdateFragment(gallery models.GalleryUpdateInput) (*models.Gallery, error) {
qb := models.NewGalleryQueryBuilder()
id, err := strconv.Atoi(gallery.ID)
if err != nil {
return nil, err
}
return qb.Find(id, nil)
}