Skip to content

Commit

Permalink
feat: setPerformerImage handles performer.Images too
Browse files Browse the repository at this point in the history
fix: uses postScrape in ScrapeName (Scrape with name/query)
  • Loading branch information
TgSeed committed Jun 26, 2022
1 parent fd4e823 commit 2a232c1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
15 changes: 14 additions & 1 deletion pkg/scraper/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,20 @@ func (c Cache) ScrapeName(ctx context.Context, id, query string, ty models.Scrap
return nil, fmt.Errorf("%w: cannot use scraper %s to scrape by name", ErrNotSupported, id)
}

return ns.viaName(ctx, c.client, query, ty)
content, err := ns.viaName(ctx, c.client, query, ty)
if err != nil {
return nil, fmt.Errorf("error while name scraping with scraper %s: %w", id, err)
}

for i := 0; i < len(content); i++ {
postScrape, err := c.postScrape(ctx, content[i])
if err != nil {
return nil, fmt.Errorf("error while post scraping with scraper %s: %w", id, err)
}
content[i] = postScrape
}

return content, err
}

// ScrapeFragment uses the given fragment input to scrape
Expand Down
31 changes: 21 additions & 10 deletions pkg/scraper/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ import (
)

func setPerformerImage(ctx context.Context, client *http.Client, p *models.ScrapedPerformer, globalConfig GlobalConfig) error {
if p.Image == nil || !strings.HasPrefix(*p.Image, "http") {
// nothing to do
return nil
if p.Images != nil && len(p.Images) > 0 {
for i := 0; i < len(p.Images); i++ {
if strings.HasPrefix(p.Images[i], "http") {
img, err := getImage(ctx, p.Images[i], client, globalConfig)
if err != nil {
return err
}

p.Images[i] = *img
// Image is deprecated. Use images instead
}
}
}

img, err := getImage(ctx, *p.Image, client, globalConfig)
if err != nil {
return err
}
if p.Image != nil && strings.HasPrefix(*p.Image, "http") {
img, err := getImage(ctx, *p.Image, client, globalConfig)
if err != nil {
return err
}

p.Image = img
// Image is deprecated. Use images instead
p.Images = []string{*img}
p.Image = img
// Image is deprecated. Use images instead
p.Images = append([]string{*img}, p.Images...)
}

return nil
}
Expand Down

0 comments on commit 2a232c1

Please sign in to comment.