mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Add gallery scraping (#862)
This commit is contained in:
@@ -69,6 +69,16 @@ func (s *xpathScraper) scrapeSceneByURL(url string) (*models.ScrapedScene, error
|
||||
return scraper.scrapeScene(q)
|
||||
}
|
||||
|
||||
func (s *xpathScraper) scrapeGalleryByURL(url string) (*models.ScrapedGallery, error) {
|
||||
doc, scraper, err := s.scrapeURL(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
q := s.getXPathQuery(doc)
|
||||
return scraper.scrapeGallery(q)
|
||||
}
|
||||
|
||||
func (s *xpathScraper) scrapeMovieByURL(url string) (*models.ScrapedMovie, error) {
|
||||
doc, scraper, err := s.scrapeURL(url)
|
||||
if err != nil {
|
||||
@@ -137,6 +147,35 @@ func (s *xpathScraper) scrapeSceneByFragment(scene models.SceneUpdateInput) (*mo
|
||||
return scraper.scrapeScene(q)
|
||||
}
|
||||
|
||||
func (s *xpathScraper) scrapeGalleryByFragment(gallery models.GalleryUpdateInput) (*models.ScrapedGallery, error) {
|
||||
storedGallery, err := galleryFromUpdateFragment(gallery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if storedGallery == nil {
|
||||
return nil, errors.New("no scene found")
|
||||
}
|
||||
|
||||
// construct the URL
|
||||
url := constructGalleryURL(s.scraper.QueryURL, storedGallery)
|
||||
|
||||
scraper := s.getXpathScraper()
|
||||
|
||||
if scraper == nil {
|
||||
return nil, errors.New("xpath scraper with name " + s.scraper.Scraper + " not found in config")
|
||||
}
|
||||
|
||||
doc, err := s.loadURL(url)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
q := s.getXPathQuery(doc)
|
||||
return scraper.scrapeGallery(q)
|
||||
}
|
||||
|
||||
func (s *xpathScraper) loadURL(url string) (*html.Node, error) {
|
||||
r, err := loadURL(url, s.config, s.globalConfig)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user