@@ -40,7 +40,7 @@ func (w *Vision) originalsPath() string {
4040}
4141
4242// Start runs the specified model types for the photos that match the search query.
43- func (w * Vision ) Start (q string , models []string , force bool ) (err error ) {
43+ func (w * Vision ) Start (q string , models []string , customSrc string , force bool ) (err error ) {
4444 defer func () {
4545 if r := recover (); r != nil {
4646 err = fmt .Errorf ("vision: %s (worker panic)\n stack: %s" , r , debug .Stack ())
@@ -68,6 +68,15 @@ func (w *Vision) Start(q string, models []string, force bool) (err error) {
6868 log .Infof ("vision: running %s models" , strings .Join (models , " and " ))
6969 }
7070
71+ // Source type for AI generated data.
72+ var dataSrc string
73+
74+ if customSrc = clean .ShortTypeLower (customSrc ); customSrc != "" {
75+ dataSrc = customSrc
76+ } else {
77+ dataSrc = entity .SrcImage
78+ }
79+
7180 // Check time when worker was last executed.
7281 updateIndex := false
7382
@@ -128,13 +137,15 @@ func (w *Vision) Start(q string, models []string, force bool) (err error) {
128137
129138 changed := false
130139
140+ // Generate labels.
131141 if updateLabels && (len (m .Labels ) == 0 || force ) {
132142 if labels := ind .Labels (file ); len (labels ) > 0 {
133143 m .AddLabels (labels )
134144 changed = true
135145 }
136146 }
137147
148+ // Detect NSFW content.
138149 if updateNsfw && (! photo .PhotoPrivate || force ) {
139150 if isNsfw := ind .IsNsfw (file ); photo .PhotoPrivate != isNsfw {
140151 photo .PhotoPrivate = isNsfw
@@ -143,19 +154,15 @@ func (w *Vision) Start(q string, models []string, force bool) (err error) {
143154 }
144155 }
145156
146- if updateCaptions && (m .PhotoCaption == "" || force ) {
157+ // Generate a caption if none exists or the force flag is used,
158+ // and only if no caption was set or removed by a higher-priority source.
159+ if updateCaptions && entity .SrcPriority [dataSrc ] >= entity .SrcPriority [m .CaptionSrc ] && (m .NoCaption () || force ) {
147160 if caption , captionErr := ind .Caption (file ); captionErr != nil {
148161 log .Warnf ("vision: %s in %s (generate caption)" , clean .Error (captionErr ), photoName )
149- } else if caption .Text != "" {
150- if caption .Source == "" {
151- caption .Source = entity .SrcImage
152- }
153-
154- if (entity .SrcPriority [caption .Source ] >= entity .SrcPriority [m .CaptionSrc ]) || ! m .HasCaption () {
155- m .SetCaption (caption .Text , caption .Source )
156- changed = true
157- log .Infof ("vision: changed caption of %s to %s" , photoName , clean .Log (m .PhotoCaption ))
158- }
162+ } else if caption .Text = strings .TrimSpace (caption .Text ); caption .Text != "" {
163+ m .SetCaption (caption .Text , dataSrc )
164+ changed = true
165+ log .Infof ("vision: changed caption of %s to %s" , photoName , clean .Log (m .PhotoCaption ))
159166 }
160167 }
161168
0 commit comments