2021-04-26 02:51:31 +00:00
|
|
|
package autotag
|
|
|
|
|
|
|
|
import (
|
2021-05-03 03:09:46 +00:00
|
|
|
"github.com/stashapp/stash/pkg/gallery"
|
|
|
|
"github.com/stashapp/stash/pkg/image"
|
2022-03-09 01:01:56 +00:00
|
|
|
"github.com/stashapp/stash/pkg/match"
|
2021-04-26 02:51:31 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
"github.com/stashapp/stash/pkg/scene"
|
|
|
|
)
|
|
|
|
|
2022-03-09 01:01:56 +00:00
|
|
|
func getTagTaggers(p *models.Tag, aliases []string, cache *match.Cache) []tagger {
|
2021-05-26 04:36:05 +00:00
|
|
|
ret := []tagger{{
|
2022-03-09 01:01:56 +00:00
|
|
|
ID: p.ID,
|
|
|
|
Type: "tag",
|
|
|
|
Name: p.Name,
|
|
|
|
cache: cache,
|
2021-05-26 04:36:05 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
for _, a := range aliases {
|
|
|
|
ret = append(ret, tagger{
|
2022-03-09 01:01:56 +00:00
|
|
|
ID: p.ID,
|
|
|
|
Type: "tag",
|
|
|
|
Name: a,
|
|
|
|
cache: cache,
|
2021-05-26 04:36:05 +00:00
|
|
|
})
|
2021-04-26 02:51:31 +00:00
|
|
|
}
|
2021-05-26 04:36:05 +00:00
|
|
|
|
|
|
|
return ret
|
2021-04-26 02:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TagScenes searches for scenes whose path matches the provided tag name and tags the scene with the tag.
|
2022-03-09 01:01:56 +00:00
|
|
|
func TagScenes(p *models.Tag, paths []string, aliases []string, rw models.SceneReaderWriter, cache *match.Cache) error {
|
|
|
|
t := getTagTaggers(p, aliases, cache)
|
2021-04-26 02:51:31 +00:00
|
|
|
|
2021-05-26 04:36:05 +00:00
|
|
|
for _, tt := range t {
|
|
|
|
if err := tt.tagScenes(paths, rw, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return scene.AddTag(rw, otherID, subjectID)
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2021-04-26 02:51:31 +00:00
|
|
|
}
|
2021-05-03 03:09:46 +00:00
|
|
|
|
|
|
|
// TagImages searches for images whose path matches the provided tag name and tags the image with the tag.
|
2022-03-09 01:01:56 +00:00
|
|
|
func TagImages(p *models.Tag, paths []string, aliases []string, rw models.ImageReaderWriter, cache *match.Cache) error {
|
|
|
|
t := getTagTaggers(p, aliases, cache)
|
2021-05-03 03:09:46 +00:00
|
|
|
|
2021-05-26 04:36:05 +00:00
|
|
|
for _, tt := range t {
|
|
|
|
if err := tt.tagImages(paths, rw, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return image.AddTag(rw, otherID, subjectID)
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2021-05-03 03:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TagGalleries searches for galleries whose path matches the provided tag name and tags the gallery with the tag.
|
2022-03-09 01:01:56 +00:00
|
|
|
func TagGalleries(p *models.Tag, paths []string, aliases []string, rw models.GalleryReaderWriter, cache *match.Cache) error {
|
|
|
|
t := getTagTaggers(p, aliases, cache)
|
2021-05-03 03:09:46 +00:00
|
|
|
|
2021-05-26 04:36:05 +00:00
|
|
|
for _, tt := range t {
|
|
|
|
if err := tt.tagGalleries(paths, rw, func(subjectID, otherID int) (bool, error) {
|
|
|
|
return gallery.AddTag(rw, otherID, subjectID)
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2021-05-03 03:09:46 +00:00
|
|
|
}
|