Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freeones scraper tweaks #509

Merged
merged 2 commits into from
May 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions pkg/scraper/freeones.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"time"

"github.com/PuerkitoBio/goquery"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
)

const freeonesTimeout = 45 * time.Second

const freeonesScraperID = "builtin_freeones"
const freeonesName = "Freeones"

Expand Down Expand Up @@ -44,9 +45,12 @@ func GetFreeonesScraper() scraperConfig {
func GetPerformerNames(c scraperTypeConfig, q string) ([]*models.ScrapedPerformer, error) {
// Request the HTML page.
queryURL := "https://www.freeones.com/suggestions.php?q=" + url.PathEscape(q) + "&t=1"
res, err := http.Get(queryURL)
client := http.Client{
Timeout: freeonesTimeout,
}
res, err := client.Get(queryURL)
if err != nil {
logger.Fatal(err)
return nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
Expand Down Expand Up @@ -74,7 +78,8 @@ func GetPerformerNames(c scraperTypeConfig, q string) ([]*models.ScrapedPerforme

func GetPerformerURL(c scraperTypeConfig, href string) (*models.ScrapedPerformer, error) {
// if we're already in the bio page, just scrape it
if regexp.MustCompile(`\/bio_.*\.php$`).MatchString(href) {
reg := regexp.MustCompile(`\/bio_.*\.php$`)
if reg.MatchString(href) {
return getPerformerBio(c, href)
}

Expand All @@ -85,11 +90,15 @@ func GetPerformerURL(c scraperTypeConfig, href string) (*models.ScrapedPerformer
return getPerformerBio(c, href)
}

return nil, nil
return nil, fmt.Errorf("Bio page not found in %s", href)
}

func getPerformerBio(c scraperTypeConfig, href string) (*models.ScrapedPerformer, error) {
bioRes, err := http.Get(href)
client := http.Client{
Timeout: freeonesTimeout,
}

bioRes, err := client.Get(href)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -230,6 +239,7 @@ func GetPerformer(c scraperTypeConfig, scrapedPerformer models.ScrapedPerformerI
href = "https://www.freeones.com" + href

return getPerformerBio(c, href)

}

func getIndexes(doc *goquery.Document) map[string]int {
Expand Down