mirror of
https://github.com/stashapp/stash.git
synced 2025-12-09 18:04:33 +01:00
Rather than passing a pointer to a waitgroup into task.Start(..) functions, handle the waitgroup.Done() at the callsite. This makes waitgroup handling local to its definition rather than it being spread out over multiple files. Tasks now simply execute, and the policy of waiting on them is handled by the caller.
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package manager
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/stashapp/stash/pkg/ffmpeg"
|
|
"github.com/stashapp/stash/pkg/logger"
|
|
"github.com/stashapp/stash/pkg/models"
|
|
)
|
|
|
|
type GeneratePhashTask struct {
|
|
Scene models.Scene
|
|
Overwrite bool
|
|
fileNamingAlgorithm models.HashAlgorithm
|
|
txnManager models.TransactionManager
|
|
}
|
|
|
|
func (t *GeneratePhashTask) Start() {
|
|
if !t.shouldGenerate() {
|
|
return
|
|
}
|
|
|
|
videoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.Scene.Path, false)
|
|
if err != nil {
|
|
logger.Errorf("error reading video file: %s", err.Error())
|
|
return
|
|
}
|
|
|
|
sceneHash := t.Scene.GetHash(t.fileNamingAlgorithm)
|
|
generator, err := NewPhashGenerator(*videoFile, sceneHash)
|
|
|
|
if err != nil {
|
|
logger.Errorf("error creating phash generator: %s", err.Error())
|
|
return
|
|
}
|
|
hash, err := generator.Generate()
|
|
if err != nil {
|
|
logger.Errorf("error generating phash: %s", err.Error())
|
|
return
|
|
}
|
|
|
|
if err := t.txnManager.WithTxn(context.TODO(), func(r models.Repository) error {
|
|
qb := r.Scene()
|
|
hashValue := sql.NullInt64{Int64: int64(*hash), Valid: true}
|
|
scenePartial := models.ScenePartial{
|
|
ID: t.Scene.ID,
|
|
Phash: &hashValue,
|
|
}
|
|
_, err := qb.Update(scenePartial)
|
|
return err
|
|
}); err != nil {
|
|
logger.Error(err.Error())
|
|
}
|
|
}
|
|
|
|
func (t *GeneratePhashTask) shouldGenerate() bool {
|
|
return t.Overwrite || !t.Scene.Phash.Valid
|
|
}
|