mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
Add missing group scraper fields (#5820)
This commit is contained in:
@@ -101,12 +101,12 @@ func (r *queryResolver) ScrapeMovieURL(ctx context.Context, url string) (*models
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *queryResolver) ScrapeGroupURL(ctx context.Context, url string) (*models.ScrapedGroup, error) {
|
func (r *queryResolver) ScrapeGroupURL(ctx context.Context, url string) (*models.ScrapedGroup, error) {
|
||||||
content, err := r.scraperCache().ScrapeURL(ctx, url, scraper.ScrapeContentTypeMovie)
|
content, err := r.scraperCache().ScrapeURL(ctx, url, scraper.ScrapeContentTypeGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, err := marshalScrapedMovie(content)
|
ret, err := marshalScrapedGroup(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,30 @@ func marshalScrapedMovies(content []scraper.ScrapedContent) ([]*models.ScrapedMo
|
|||||||
case models.ScrapedMovie:
|
case models.ScrapedMovie:
|
||||||
ret = append(ret, &m)
|
ret = append(ret, &m)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("%w: cannot turn ScrapedConetnt into ScrapedMovie", models.ErrConversion)
|
return nil, fmt.Errorf("%w: cannot turn ScrapedContent into ScrapedMovie", models.ErrConversion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// marshalScrapedMovies converts ScrapedContent into ScrapedMovie. If conversion
|
||||||
|
// fails, an error is returned.
|
||||||
|
func marshalScrapedGroups(content []scraper.ScrapedContent) ([]*models.ScrapedGroup, error) {
|
||||||
|
var ret []*models.ScrapedGroup
|
||||||
|
for _, c := range content {
|
||||||
|
if c == nil {
|
||||||
|
// graphql schema requires groups to be non-nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m := c.(type) {
|
||||||
|
case *models.ScrapedGroup:
|
||||||
|
ret = append(ret, m)
|
||||||
|
case models.ScrapedGroup:
|
||||||
|
ret = append(ret, &m)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("%w: cannot turn ScrapedContent into ScrapedGroup", models.ErrConversion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,3 +192,13 @@ func marshalScrapedMovie(content scraper.ScrapedContent) (*models.ScrapedMovie,
|
|||||||
|
|
||||||
return m[0], nil
|
return m[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// marshalScrapedMovie will marshal a single scraped movie
|
||||||
|
func marshalScrapedGroup(content scraper.ScrapedContent) (*models.ScrapedGroup, error) {
|
||||||
|
m, err := marshalScrapedGroups([]scraper.ScrapedContent{content})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m[0], nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -378,6 +378,11 @@ func (c config) matchesURL(url string, ty ScrapeContentType) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ScrapeContentTypeMovie, ScrapeContentTypeGroup:
|
case ScrapeContentTypeMovie, ScrapeContentTypeGroup:
|
||||||
|
for _, scraper := range c.GroupByURL {
|
||||||
|
if scraper.matchesURL(url) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, scraper := range c.MovieByURL {
|
for _, scraper := range c.MovieByURL {
|
||||||
if scraper.matchesURL(url) {
|
if scraper.matchesURL(url) {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -851,7 +851,10 @@ type mappedScraper struct {
|
|||||||
Gallery *mappedGalleryScraperConfig `yaml:"gallery"`
|
Gallery *mappedGalleryScraperConfig `yaml:"gallery"`
|
||||||
Image *mappedImageScraperConfig `yaml:"image"`
|
Image *mappedImageScraperConfig `yaml:"image"`
|
||||||
Performer *mappedPerformerScraperConfig `yaml:"performer"`
|
Performer *mappedPerformerScraperConfig `yaml:"performer"`
|
||||||
Movie *mappedMovieScraperConfig `yaml:"movie"`
|
Group *mappedMovieScraperConfig `yaml:"group"`
|
||||||
|
|
||||||
|
// deprecated
|
||||||
|
Movie *mappedMovieScraperConfig `yaml:"movie"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type mappedResult map[string]interface{}
|
type mappedResult map[string]interface{}
|
||||||
@@ -1247,24 +1250,29 @@ func (s mappedScraper) scrapeGallery(ctx context.Context, q mappedQuery) (*model
|
|||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s mappedScraper) scrapeGroup(ctx context.Context, q mappedQuery) (*models.ScrapedMovie, error) {
|
func (s mappedScraper) scrapeGroup(ctx context.Context, q mappedQuery) (*models.ScrapedGroup, error) {
|
||||||
var ret models.ScrapedMovie
|
var ret models.ScrapedGroup
|
||||||
|
|
||||||
movieScraperConfig := s.Movie
|
// try group scraper first, falling back to movie
|
||||||
if movieScraperConfig == nil {
|
groupScraperConfig := s.Group
|
||||||
|
|
||||||
|
if groupScraperConfig == nil {
|
||||||
|
groupScraperConfig = s.Movie
|
||||||
|
}
|
||||||
|
if groupScraperConfig == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
movieMap := movieScraperConfig.mappedConfig
|
groupMap := groupScraperConfig.mappedConfig
|
||||||
|
|
||||||
movieStudioMap := movieScraperConfig.Studio
|
groupStudioMap := groupScraperConfig.Studio
|
||||||
movieTagsMap := movieScraperConfig.Tags
|
groupTagsMap := groupScraperConfig.Tags
|
||||||
|
|
||||||
results := movieMap.process(ctx, q, s.Common, urlsIsMulti)
|
results := groupMap.process(ctx, q, s.Common, urlsIsMulti)
|
||||||
|
|
||||||
if movieStudioMap != nil {
|
if groupStudioMap != nil {
|
||||||
logger.Debug(`Processing movie studio:`)
|
logger.Debug(`Processing group studio:`)
|
||||||
studioResults := movieStudioMap.process(ctx, q, s.Common, nil)
|
studioResults := groupStudioMap.process(ctx, q, s.Common, nil)
|
||||||
|
|
||||||
if len(studioResults) > 0 {
|
if len(studioResults) > 0 {
|
||||||
studio := &models.ScrapedStudio{}
|
studio := &models.ScrapedStudio{}
|
||||||
@@ -1274,9 +1282,9 @@ func (s mappedScraper) scrapeGroup(ctx context.Context, q mappedQuery) (*models.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// now apply the tags
|
// now apply the tags
|
||||||
if movieTagsMap != nil {
|
if groupTagsMap != nil {
|
||||||
logger.Debug(`Processing movie tags:`)
|
logger.Debug(`Processing group tags:`)
|
||||||
tagResults := movieTagsMap.process(ctx, q, s.Common, nil)
|
tagResults := groupTagsMap.process(ctx, q, s.Common, nil)
|
||||||
|
|
||||||
for _, p := range tagResults {
|
for _, p := range tagResults {
|
||||||
tag := &models.ScrapedTag{}
|
tag := &models.ScrapedTag{}
|
||||||
|
|||||||
Reference in New Issue
Block a user