Add JSON scrape support (#717)

* Add support for scene fragment scrape in xpath
This commit is contained in:
WithoutPants
2020-08-10 14:21:50 +10:00
committed by GitHub
parent 470a2b5833
commit 7158e83b75
28 changed files with 5005 additions and 14 deletions

View File

@@ -10,6 +10,7 @@ import (
"net/http"
"net/http/cookiejar"
"os"
"path/filepath"
"strings"
"time"
@@ -18,10 +19,25 @@ import (
"github.com/chromedp/chromedp"
jsoniter "github.com/json-iterator/go"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"golang.org/x/net/html/charset"
"golang.org/x/net/publicsuffix"
)
// Timeout for the scrape http request. Includes transfer time. May want to make this
// configurable at some point.
const scrapeGetTimeout = time.Second * 30
func constructSceneURL(url string, scene *models.Scene) string {
// support checksum, title and filename
ret := strings.Replace(url, "{checksum}", scene.Checksum.String, -1)
ret = strings.Replace(url, "{oshash}", scene.OSHash.String, -1)
ret = strings.Replace(ret, "{filename}", filepath.Base(scene.Path), -1)
ret = strings.Replace(ret, "{title}", scene.Title.String, -1)
return ret
}
func loadURL(url string, scraperConfig config, globalConfig GlobalConfig) (io.Reader, error) {
driverOptions := scraperConfig.DriverOptions
if driverOptions != nil && driverOptions.UseCDP {