Tagger match performer by alias (#4182)

This commit is contained in:
Flashy78 2023-10-15 20:39:41 -07:00 committed by GitHub
parent 409f8fc70c
commit e5af37efbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View File

@ -5,11 +5,13 @@ import (
"strconv" "strconv"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/performer"
"github.com/stashapp/stash/pkg/studio" "github.com/stashapp/stash/pkg/studio"
"github.com/stashapp/stash/pkg/tag" "github.com/stashapp/stash/pkg/tag"
) )
type PerformerFinder interface { type PerformerFinder interface {
models.PerformerQueryer
FindByNames(ctx context.Context, names []string, nocase bool) ([]*models.Performer, error) FindByNames(ctx context.Context, names []string, nocase bool) ([]*models.Performer, error)
FindByStashID(ctx context.Context, stashID models.StashID) ([]*models.Performer, error) FindByStashID(ctx context.Context, stashID models.StashID) ([]*models.Performer, error)
} }
@ -47,9 +49,17 @@ func ScrapedPerformer(ctx context.Context, qb PerformerFinder, p *models.Scraped
return err return err
} }
if len(performers) != 1 { if performers == nil || len(performers) != 1 {
// ignore - cannot match // try matching a single performer by exact alias
return nil performers, err = performer.ByAlias(ctx, qb, *p.Name)
if err != nil {
return err
}
if performers == nil || len(performers) != 1 {
// ignore - cannot match
return nil
}
} }
id := strconv.Itoa(performers[0].ID) id := strconv.Itoa(performers[0].ID)

View File

@ -41,3 +41,24 @@ func CountByAppearsWith(ctx context.Context, r models.PerformerQueryer, id int)
return r.QueryCount(ctx, filter, nil) return r.QueryCount(ctx, filter, nil)
} }
func ByAlias(ctx context.Context, r models.PerformerQueryer, alias string) ([]*models.Performer, error) {
f := &models.PerformerFilterType{
Aliases: &models.StringCriterionInput{
Value: alias,
Modifier: models.CriterionModifierEquals,
},
}
ret, count, err := r.Query(ctx, f, nil)
if err != nil {
return nil, err
}
if count > 0 {
return ret, nil
}
return nil, nil
}