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

Tagger match performer by alias #4182

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions pkg/match/scraped.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions pkg/performer/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading