From 01a5c84b52e9e96ea1e1183b2f2a1cfa3ab47725 Mon Sep 17 00:00:00 2001 From: Flashy78 <90150289+Flashy78@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:44:08 -0700 Subject: [PATCH] Tagger match performer by alias --- pkg/match/scraped.go | 16 +++++++++++++--- pkg/performer/query.go | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/pkg/match/scraped.go b/pkg/match/scraped.go index 675a8d7fcdd..012cb749569 100644 --- a/pkg/match/scraped.go +++ b/pkg/match/scraped.go @@ -5,11 +5,13 @@ import ( "strconv" "github.com/stashapp/stash/pkg/models" + "github.com/stashapp/stash/pkg/performer" "github.com/stashapp/stash/pkg/studio" "github.com/stashapp/stash/pkg/tag" ) type PerformerFinder interface { + models.PerformerQueryer FindByNames(ctx context.Context, names []string, nocase bool) ([]*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 } - if len(performers) != 1 { - // ignore - cannot match - return nil + if performers == nil || len(performers) != 1 { + // try matching a single performer by exact alias + 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) diff --git a/pkg/performer/query.go b/pkg/performer/query.go index d85fa514866..6fbfeef4647 100644 --- a/pkg/performer/query.go +++ b/pkg/performer/query.go @@ -41,3 +41,24 @@ func CountByAppearsWith(ctx context.Context, r models.PerformerQueryer, id int) 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 +}