2021-05-03 03:09:46 +00:00
|
|
|
package autotag
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stashapp/stash/pkg/image"
|
2022-03-09 01:01:56 +00:00
|
|
|
"github.com/stashapp/stash/pkg/match"
|
2021-05-03 03:09:46 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
)
|
|
|
|
|
2022-03-09 01:01:56 +00:00
|
|
|
func getImageFileTagger(s *models.Image, cache *match.Cache) tagger {
|
2021-05-03 03:09:46 +00:00
|
|
|
return tagger{
|
2022-03-09 01:01:56 +00:00
|
|
|
ID: s.ID,
|
|
|
|
Type: "image",
|
|
|
|
Name: s.GetTitle(),
|
|
|
|
Path: s.Path,
|
|
|
|
cache: cache,
|
2021-05-03 03:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImagePerformers tags the provided image with performers whose name matches the image's path.
|
2022-03-09 01:01:56 +00:00
|
|
|
func ImagePerformers(s *models.Image, rw models.ImageReaderWriter, performerReader models.PerformerReader, cache *match.Cache) error {
|
|
|
|
t := getImageFileTagger(s, cache)
|
2021-05-03 03:09:46 +00:00
|
|
|
|
|
|
|
return t.tagPerformers(performerReader, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return image.AddPerformer(rw, subjectID, otherID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImageStudios tags the provided image with the first studio whose name matches the image's path.
|
|
|
|
//
|
|
|
|
// Images will not be tagged if studio is already set.
|
2022-03-09 01:01:56 +00:00
|
|
|
func ImageStudios(s *models.Image, rw models.ImageReaderWriter, studioReader models.StudioReader, cache *match.Cache) error {
|
2021-05-03 03:09:46 +00:00
|
|
|
if s.StudioID.Valid {
|
|
|
|
// don't modify
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-09 01:01:56 +00:00
|
|
|
t := getImageFileTagger(s, cache)
|
2021-05-03 03:09:46 +00:00
|
|
|
|
|
|
|
return t.tagStudios(studioReader, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return addImageStudio(rw, subjectID, otherID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ImageTags tags the provided image with tags whose name matches the image's path.
|
2022-03-09 01:01:56 +00:00
|
|
|
func ImageTags(s *models.Image, rw models.ImageReaderWriter, tagReader models.TagReader, cache *match.Cache) error {
|
|
|
|
t := getImageFileTagger(s, cache)
|
2021-05-03 03:09:46 +00:00
|
|
|
|
|
|
|
return t.tagTags(tagReader, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return image.AddTag(rw, subjectID, otherID)
|
|
|
|
})
|
|
|
|
}
|