-
-
Notifications
You must be signed in to change notification settings - Fork 792
/
task_autotag.go
874 lines (722 loc) · 20.1 KB
/
task_autotag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
package manager
import (
"context"
"fmt"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
"github.com/stashapp/stash/internal/autotag"
"github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/job"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/match"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene"
)
type autoTagJob struct {
repository models.Repository
input AutoTagMetadataInput
cache match.Cache
}
func (j *autoTagJob) Execute(ctx context.Context, progress *job.Progress) {
begin := time.Now()
input := j.input
if j.isFileBasedAutoTag(input) {
// doing file-based auto-tag
j.autoTagFiles(ctx, progress, input.Paths, len(input.Performers) > 0, len(input.Studios) > 0, len(input.Tags) > 0)
} else {
// doing specific performer/studio/tag auto-tag
j.autoTagSpecific(ctx, progress)
}
logger.Infof("Finished auto-tag after %s", time.Since(begin).String())
}
func (j *autoTagJob) isFileBasedAutoTag(input AutoTagMetadataInput) bool {
const wildcard = "*"
performerIds := input.Performers
studioIds := input.Studios
tagIds := input.Tags
return (len(performerIds) == 0 || performerIds[0] == wildcard) && (len(studioIds) == 0 || studioIds[0] == wildcard) && (len(tagIds) == 0 || tagIds[0] == wildcard)
}
func (j *autoTagJob) autoTagFiles(ctx context.Context, progress *job.Progress, paths []string, performers, studios, tags bool) {
t := autoTagFilesTask{
paths: paths,
performers: performers,
studios: studios,
tags: tags,
progress: progress,
repository: j.repository,
cache: &j.cache,
}
t.process(ctx)
}
func (j *autoTagJob) autoTagSpecific(ctx context.Context, progress *job.Progress) {
input := j.input
performerIds := input.Performers
studioIds := input.Studios
tagIds := input.Tags
performerCount := len(performerIds)
studioCount := len(studioIds)
tagCount := len(tagIds)
r := j.repository
if err := r.WithReadTxn(ctx, func(ctx context.Context) error {
performerQuery := r.Performer
studioQuery := r.Studio
tagQuery := r.Tag
const wildcard = "*"
var err error
if performerCount == 1 && performerIds[0] == wildcard {
performerCount, err = performerQuery.Count(ctx)
if err != nil {
return fmt.Errorf("getting performer count: %v", err)
}
}
if studioCount == 1 && studioIds[0] == wildcard {
studioCount, err = studioQuery.Count(ctx)
if err != nil {
return fmt.Errorf("getting studio count: %v", err)
}
}
if tagCount == 1 && tagIds[0] == wildcard {
tagCount, err = tagQuery.Count(ctx)
if err != nil {
return fmt.Errorf("getting tag count: %v", err)
}
}
return nil
}); err != nil {
if !job.IsCancelled(ctx) {
logger.Errorf("auto-tag error: %v", err)
}
return
}
total := performerCount + studioCount + tagCount
progress.SetTotal(total)
logger.Infof("Starting auto-tag of %d performers, %d studios, %d tags", performerCount, studioCount, tagCount)
j.autoTagPerformers(ctx, progress, input.Paths, performerIds)
j.autoTagStudios(ctx, progress, input.Paths, studioIds)
j.autoTagTags(ctx, progress, input.Paths, tagIds)
}
func (j *autoTagJob) autoTagPerformers(ctx context.Context, progress *job.Progress, paths []string, performerIds []string) {
if job.IsCancelled(ctx) {
return
}
r := j.repository
tagger := autotag.Tagger{
TxnManager: r.TxnManager,
Cache: &j.cache,
}
for _, performerId := range performerIds {
var performers []*models.Performer
if err := r.WithDB(ctx, func(ctx context.Context) error {
performerQuery := r.Performer
ignoreAutoTag := false
perPage := -1
if performerId == "*" {
var err error
performers, _, err = performerQuery.Query(ctx, &models.PerformerFilterType{
IgnoreAutoTag: &ignoreAutoTag,
}, &models.FindFilterType{
PerPage: &perPage,
})
if err != nil {
return fmt.Errorf("querying performers: %w", err)
}
} else {
performerIdInt, err := strconv.Atoi(performerId)
if err != nil {
return fmt.Errorf("parsing performer id %s: %w", performerId, err)
}
performer, err := performerQuery.Find(ctx, performerIdInt)
if err != nil {
return fmt.Errorf("finding performer id %s: %w", performerId, err)
}
if performer == nil {
return fmt.Errorf("performer with id %s not found", performerId)
}
if performer.IgnoreAutoTag {
logger.Infof("Skipping performer %s because auto-tag is disabled", performer.Name)
return nil
}
if err := performer.LoadAliases(ctx, r.Performer); err != nil {
return fmt.Errorf("loading aliases for performer %d: %w", performer.ID, err)
}
performers = append(performers, performer)
}
for _, performer := range performers {
if job.IsCancelled(ctx) {
return nil
}
err := func() error {
if err := tagger.PerformerScenes(ctx, performer, paths, r.Scene); err != nil {
return fmt.Errorf("processing scenes: %w", err)
}
if err := tagger.PerformerImages(ctx, performer, paths, r.Image); err != nil {
return fmt.Errorf("processing images: %w", err)
}
if err := tagger.PerformerGalleries(ctx, performer, paths, r.Gallery); err != nil {
return fmt.Errorf("processing galleries: %w", err)
}
return nil
}()
if job.IsCancelled(ctx) {
return nil
}
if err != nil {
return fmt.Errorf("tagging performer '%s': %s", performer.Name, err.Error())
}
progress.Increment()
}
return nil
}); err != nil {
logger.Errorf("auto-tag error: %v", err)
}
if job.IsCancelled(ctx) {
logger.Info("Stopping performer auto-tag due to user request")
return
}
}
}
func (j *autoTagJob) autoTagStudios(ctx context.Context, progress *job.Progress, paths []string, studioIds []string) {
if job.IsCancelled(ctx) {
return
}
r := j.repository
tagger := autotag.Tagger{
TxnManager: r.TxnManager,
Cache: &j.cache,
}
for _, studioId := range studioIds {
var studios []*models.Studio
if err := r.WithDB(ctx, func(ctx context.Context) error {
studioQuery := r.Studio
ignoreAutoTag := false
perPage := -1
if studioId == "*" {
var err error
studios, _, err = studioQuery.Query(ctx, &models.StudioFilterType{
IgnoreAutoTag: &ignoreAutoTag,
}, &models.FindFilterType{
PerPage: &perPage,
})
if err != nil {
return fmt.Errorf("querying studios: %v", err)
}
} else {
studioIdInt, err := strconv.Atoi(studioId)
if err != nil {
return fmt.Errorf("parsing studio id %s: %s", studioId, err.Error())
}
studio, err := studioQuery.Find(ctx, studioIdInt)
if err != nil {
return fmt.Errorf("finding studio id %s: %s", studioId, err.Error())
}
if studio == nil {
return fmt.Errorf("studio with id %s not found", studioId)
}
if studio.IgnoreAutoTag {
logger.Infof("Skipping studio %s because auto-tag is disabled", studio.Name)
return nil
}
studios = append(studios, studio)
}
for _, studio := range studios {
if job.IsCancelled(ctx) {
return nil
}
err := func() error {
aliases, err := r.Studio.GetAliases(ctx, studio.ID)
if err != nil {
return fmt.Errorf("getting studio aliases: %w", err)
}
if err := tagger.StudioScenes(ctx, studio, paths, aliases, r.Scene); err != nil {
return fmt.Errorf("processing scenes: %w", err)
}
if err := tagger.StudioImages(ctx, studio, paths, aliases, r.Image); err != nil {
return fmt.Errorf("processing images: %w", err)
}
if err := tagger.StudioGalleries(ctx, studio, paths, aliases, r.Gallery); err != nil {
return fmt.Errorf("processing galleries: %w", err)
}
return nil
}()
if job.IsCancelled(ctx) {
return nil
}
if err != nil {
return fmt.Errorf("tagging studio '%s': %s", studio.Name, err.Error())
}
progress.Increment()
}
return nil
}); err != nil {
logger.Errorf("auto-tag error: %v", err)
}
if job.IsCancelled(ctx) {
logger.Info("Stopping studio auto-tag due to user request")
return
}
}
}
func (j *autoTagJob) autoTagTags(ctx context.Context, progress *job.Progress, paths []string, tagIds []string) {
if job.IsCancelled(ctx) {
return
}
r := j.repository
tagger := autotag.Tagger{
TxnManager: r.TxnManager,
Cache: &j.cache,
}
for _, tagId := range tagIds {
var tags []*models.Tag
if err := r.WithDB(ctx, func(ctx context.Context) error {
tagQuery := r.Tag
ignoreAutoTag := false
perPage := -1
if tagId == "*" {
var err error
tags, _, err = tagQuery.Query(ctx, &models.TagFilterType{
IgnoreAutoTag: &ignoreAutoTag,
}, &models.FindFilterType{
PerPage: &perPage,
})
if err != nil {
return fmt.Errorf("querying tags: %v", err)
}
} else {
tagIdInt, err := strconv.Atoi(tagId)
if err != nil {
return fmt.Errorf("parsing tag id %s: %s", tagId, err.Error())
}
tag, err := tagQuery.Find(ctx, tagIdInt)
if err != nil {
return fmt.Errorf("finding tag id %s: %s", tagId, err.Error())
}
if tag == nil {
return fmt.Errorf("tag with id %s not found", tagId)
}
if tag.IgnoreAutoTag {
logger.Infof("Skipping tag %s because auto-tag is disabled", tag.Name)
return nil
}
tags = append(tags, tag)
}
for _, tag := range tags {
if job.IsCancelled(ctx) {
return nil
}
err := func() error {
aliases, err := r.Tag.GetAliases(ctx, tag.ID)
if err != nil {
return fmt.Errorf("getting tag aliases: %w", err)
}
if err := tagger.TagScenes(ctx, tag, paths, aliases, r.Scene); err != nil {
return fmt.Errorf("processing scenes: %w", err)
}
if err := tagger.TagImages(ctx, tag, paths, aliases, r.Image); err != nil {
return fmt.Errorf("processing images: %w", err)
}
if err := tagger.TagGalleries(ctx, tag, paths, aliases, r.Gallery); err != nil {
return fmt.Errorf("processing galleries: %w", err)
}
return nil
}()
if job.IsCancelled(ctx) {
return nil
}
if err != nil {
return fmt.Errorf("tagging tag '%s': %s", tag.Name, err.Error())
}
progress.Increment()
}
return nil
}); err != nil {
logger.Errorf("auto-tag error: %v", err)
}
if job.IsCancelled(ctx) {
logger.Info("Stopping tag auto-tag due to user request")
return
}
}
}
type autoTagFilesTask struct {
paths []string
performers bool
studios bool
tags bool
progress *job.Progress
repository models.Repository
cache *match.Cache
}
func (t *autoTagFilesTask) makeSceneFilter() *models.SceneFilterType {
ret := scene.FilterFromPaths(t.paths)
organized := false
ret.Organized = &organized
return ret
}
func (t *autoTagFilesTask) makeImageFilter() *models.ImageFilterType {
ret := &models.ImageFilterType{}
or := ret
sep := string(filepath.Separator)
for _, p := range t.paths {
if !strings.HasSuffix(p, sep) {
p += sep
}
if ret.Path == nil {
or = ret
} else {
newOr := &models.ImageFilterType{}
or.Or = newOr
or = newOr
}
or.Path = &models.StringCriterionInput{
Modifier: models.CriterionModifierEquals,
Value: p + "%",
}
}
organized := false
ret.Organized = &organized
return ret
}
func (t *autoTagFilesTask) makeGalleryFilter() *models.GalleryFilterType {
ret := &models.GalleryFilterType{}
or := ret
sep := string(filepath.Separator)
if len(t.paths) == 0 {
ret.Path = &models.StringCriterionInput{
Modifier: models.CriterionModifierNotNull,
}
}
for _, p := range t.paths {
if !strings.HasSuffix(p, sep) {
p += sep
}
if ret.Path == nil {
or = ret
} else {
newOr := &models.GalleryFilterType{}
or.Or = newOr
or = newOr
}
or.Path = &models.StringCriterionInput{
Modifier: models.CriterionModifierEquals,
Value: p + "%",
}
}
organized := false
ret.Organized = &organized
return ret
}
func (t *autoTagFilesTask) getCount(ctx context.Context) (int, error) {
r := t.repository
pp := 0
findFilter := &models.FindFilterType{
PerPage: &pp,
}
sceneResults, err := r.Scene.Query(ctx, models.SceneQueryOptions{
QueryOptions: models.QueryOptions{
FindFilter: findFilter,
Count: true,
},
SceneFilter: t.makeSceneFilter(),
})
if err != nil {
return 0, fmt.Errorf("getting scene count: %w", err)
}
sceneCount := sceneResults.Count
imageResults, err := r.Image.Query(ctx, models.ImageQueryOptions{
QueryOptions: models.QueryOptions{
FindFilter: findFilter,
Count: true,
},
ImageFilter: t.makeImageFilter(),
})
if err != nil {
return 0, fmt.Errorf("getting image count: %w", err)
}
imageCount := imageResults.Count
_, galleryCount, err := r.Gallery.Query(ctx, t.makeGalleryFilter(), findFilter)
if err != nil {
return 0, fmt.Errorf("getting gallery count: %w", err)
}
return sceneCount + imageCount + galleryCount, nil
}
func (t *autoTagFilesTask) processScenes(ctx context.Context) {
if job.IsCancelled(ctx) {
return
}
logger.Info("Auto-tagging scenes...")
batchSize := 1000
findFilter := models.BatchFindFilter(batchSize)
sceneFilter := t.makeSceneFilter()
r := t.repository
more := true
for more {
var scenes []*models.Scene
if err := r.WithReadTxn(ctx, func(ctx context.Context) error {
var err error
scenes, err = scene.Query(ctx, r.Scene, sceneFilter, findFilter)
return err
}); err != nil {
if !job.IsCancelled(ctx) {
logger.Errorf("error querying scenes for auto-tag: %w", err)
}
return
}
for _, ss := range scenes {
if job.IsCancelled(ctx) {
logger.Info("Stopping auto-tag due to user request")
return
}
tt := autoTagSceneTask{
repository: r,
scene: ss,
performers: t.performers,
studios: t.studios,
tags: t.tags,
cache: t.cache,
}
var wg sync.WaitGroup
wg.Add(1)
go tt.Start(ctx, &wg)
wg.Wait()
t.progress.Increment()
}
if len(scenes) != batchSize {
more = false
} else {
*findFilter.Page++
if *findFilter.Page%10 == 1 {
logger.Infof("Processed %d scenes...", (*findFilter.Page-1)*batchSize)
}
}
}
}
func (t *autoTagFilesTask) processImages(ctx context.Context) {
if job.IsCancelled(ctx) {
return
}
logger.Info("Auto-tagging images...")
batchSize := 1000
findFilter := models.BatchFindFilter(batchSize)
imageFilter := t.makeImageFilter()
r := t.repository
more := true
for more {
var images []*models.Image
if err := r.WithReadTxn(ctx, func(ctx context.Context) error {
var err error
images, err = image.Query(ctx, r.Image, imageFilter, findFilter)
return err
}); err != nil {
if !job.IsCancelled(ctx) {
logger.Errorf("error querying images for auto-tag: %w", err)
}
return
}
for _, ss := range images {
if job.IsCancelled(ctx) {
logger.Info("Stopping auto-tag due to user request")
return
}
tt := autoTagImageTask{
repository: t.repository,
image: ss,
performers: t.performers,
studios: t.studios,
tags: t.tags,
cache: t.cache,
}
var wg sync.WaitGroup
wg.Add(1)
go tt.Start(ctx, &wg)
wg.Wait()
t.progress.Increment()
}
if len(images) != batchSize {
more = false
} else {
*findFilter.Page++
if *findFilter.Page%10 == 1 {
logger.Infof("Processed %d images...", (*findFilter.Page-1)*batchSize)
}
}
}
}
func (t *autoTagFilesTask) processGalleries(ctx context.Context) {
if job.IsCancelled(ctx) {
return
}
logger.Info("Auto-tagging galleries...")
batchSize := 1000
findFilter := models.BatchFindFilter(batchSize)
galleryFilter := t.makeGalleryFilter()
r := t.repository
more := true
for more {
var galleries []*models.Gallery
if err := r.WithReadTxn(ctx, func(ctx context.Context) error {
var err error
galleries, _, err = r.Gallery.Query(ctx, galleryFilter, findFilter)
return err
}); err != nil {
if !job.IsCancelled(ctx) {
logger.Errorf("error querying galleries for auto-tag: %w", err)
}
return
}
for _, ss := range galleries {
if job.IsCancelled(ctx) {
logger.Info("Stopping auto-tag due to user request")
return
}
tt := autoTagGalleryTask{
repository: t.repository,
gallery: ss,
performers: t.performers,
studios: t.studios,
tags: t.tags,
cache: t.cache,
}
var wg sync.WaitGroup
wg.Add(1)
go tt.Start(ctx, &wg)
wg.Wait()
t.progress.Increment()
}
if len(galleries) != batchSize {
more = false
} else {
*findFilter.Page++
if *findFilter.Page%10 == 1 {
logger.Infof("Processed %d galleries...", (*findFilter.Page-1)*batchSize)
}
}
}
}
func (t *autoTagFilesTask) process(ctx context.Context) {
if err := t.repository.WithReadTxn(ctx, func(ctx context.Context) error {
total, err := t.getCount(ctx)
if err != nil {
return err
}
t.progress.SetTotal(total)
logger.Infof("Starting auto-tag of %d files", total)
return nil
}); err != nil {
if !job.IsCancelled(ctx) {
logger.Errorf("error getting file count for auto-tag task: %v", err)
}
return
}
t.processScenes(ctx)
t.processImages(ctx)
t.processGalleries(ctx)
}
type autoTagSceneTask struct {
repository models.Repository
scene *models.Scene
performers bool
studios bool
tags bool
cache *match.Cache
}
func (t *autoTagSceneTask) Start(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
r := t.repository
if err := r.WithTxn(ctx, func(ctx context.Context) error {
if t.scene.Path == "" {
// nothing to do
return nil
}
if t.performers {
if err := autotag.ScenePerformers(ctx, t.scene, r.Scene, r.Performer, t.cache); err != nil {
return fmt.Errorf("tagging scene performers for %s: %v", t.scene.DisplayName(), err)
}
}
if t.studios {
if err := autotag.SceneStudios(ctx, t.scene, r.Scene, r.Studio, t.cache); err != nil {
return fmt.Errorf("tagging scene studio for %s: %v", t.scene.DisplayName(), err)
}
}
if t.tags {
if err := autotag.SceneTags(ctx, t.scene, r.Scene, r.Tag, t.cache); err != nil {
return fmt.Errorf("tagging scene tags for %s: %v", t.scene.DisplayName(), err)
}
}
return nil
}); err != nil {
if !job.IsCancelled(ctx) {
logger.Errorf("auto-tag error: %v", err)
}
}
}
type autoTagImageTask struct {
repository models.Repository
image *models.Image
performers bool
studios bool
tags bool
cache *match.Cache
}
func (t *autoTagImageTask) Start(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
r := t.repository
if err := r.WithTxn(ctx, func(ctx context.Context) error {
if t.performers {
if err := autotag.ImagePerformers(ctx, t.image, r.Image, r.Performer, t.cache); err != nil {
return fmt.Errorf("tagging image performers for %s: %v", t.image.DisplayName(), err)
}
}
if t.studios {
if err := autotag.ImageStudios(ctx, t.image, r.Image, r.Studio, t.cache); err != nil {
return fmt.Errorf("tagging image studio for %s: %v", t.image.DisplayName(), err)
}
}
if t.tags {
if err := autotag.ImageTags(ctx, t.image, r.Image, r.Tag, t.cache); err != nil {
return fmt.Errorf("tagging image tags for %s: %v", t.image.DisplayName(), err)
}
}
return nil
}); err != nil {
if !job.IsCancelled(ctx) {
logger.Errorf("auto-tag error: %v", err)
}
}
}
type autoTagGalleryTask struct {
repository models.Repository
gallery *models.Gallery
performers bool
studios bool
tags bool
cache *match.Cache
}
func (t *autoTagGalleryTask) Start(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
r := t.repository
if err := r.WithTxn(ctx, func(ctx context.Context) error {
if t.performers {
if err := autotag.GalleryPerformers(ctx, t.gallery, r.Gallery, r.Performer, t.cache); err != nil {
return fmt.Errorf("tagging gallery performers for %s: %v", t.gallery.DisplayName(), err)
}
}
if t.studios {
if err := autotag.GalleryStudios(ctx, t.gallery, r.Gallery, r.Studio, t.cache); err != nil {
return fmt.Errorf("tagging gallery studio for %s: %v", t.gallery.DisplayName(), err)
}
}
if t.tags {
if err := autotag.GalleryTags(ctx, t.gallery, r.Gallery, r.Tag, t.cache); err != nil {
return fmt.Errorf("tagging gallery tags for %s: %v", t.gallery.DisplayName(), err)
}
}
return nil
}); err != nil {
if !job.IsCancelled(ctx) {
logger.Errorf("auto-tag error: %v", err)
}
}
}