2021-05-03 03:09:46 +00:00
|
|
|
package autotag
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stashapp/stash/pkg/gallery"
|
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 getGalleryFileTagger(s *models.Gallery, cache *match.Cache) tagger {
|
2022-06-07 23:02:11 +00:00
|
|
|
// only trim the extension if gallery is file-based
|
|
|
|
trimExt := s.Zip
|
|
|
|
|
2021-05-03 03:09:46 +00:00
|
|
|
return tagger{
|
2022-06-07 23:02:11 +00:00
|
|
|
ID: s.ID,
|
|
|
|
Type: "gallery",
|
|
|
|
Name: s.GetTitle(),
|
|
|
|
Path: s.Path.String,
|
|
|
|
trimExt: trimExt,
|
|
|
|
cache: cache,
|
2021-05-03 03:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GalleryPerformers tags the provided gallery with performers whose name matches the gallery's path.
|
2022-03-09 01:01:56 +00:00
|
|
|
func GalleryPerformers(s *models.Gallery, rw models.GalleryReaderWriter, performerReader models.PerformerReader, cache *match.Cache) error {
|
|
|
|
t := getGalleryFileTagger(s, cache)
|
2021-05-03 03:09:46 +00:00
|
|
|
|
|
|
|
return t.tagPerformers(performerReader, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return gallery.AddPerformer(rw, subjectID, otherID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GalleryStudios tags the provided gallery with the first studio whose name matches the gallery's path.
|
|
|
|
//
|
|
|
|
// Gallerys will not be tagged if studio is already set.
|
2022-03-09 01:01:56 +00:00
|
|
|
func GalleryStudios(s *models.Gallery, rw models.GalleryReaderWriter, 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 := getGalleryFileTagger(s, cache)
|
2021-05-03 03:09:46 +00:00
|
|
|
|
|
|
|
return t.tagStudios(studioReader, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return addGalleryStudio(rw, subjectID, otherID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GalleryTags tags the provided gallery with tags whose name matches the gallery's path.
|
2022-03-09 01:01:56 +00:00
|
|
|
func GalleryTags(s *models.Gallery, rw models.GalleryReaderWriter, tagReader models.TagReader, cache *match.Cache) error {
|
|
|
|
t := getGalleryFileTagger(s, cache)
|
2021-05-03 03:09:46 +00:00
|
|
|
|
|
|
|
return t.tagTags(tagReader, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return gallery.AddTag(rw, subjectID, otherID)
|
|
|
|
})
|
|
|
|
}
|