2019-02-10 10:57:56 +00:00
|
|
|
package manager
|
|
|
|
|
|
|
|
import (
|
2020-11-25 01:45:10 +00:00
|
|
|
"github.com/remeh/sizedwaitgroup"
|
2020-07-19 01:59:18 +00:00
|
|
|
|
2019-02-14 23:42:52 +00:00
|
|
|
"github.com/stashapp/stash/pkg/ffmpeg"
|
|
|
|
"github.com/stashapp/stash/pkg/logger"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
"github.com/stashapp/stash/pkg/utils"
|
2019-02-10 10:57:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type GenerateSpriteTask struct {
|
2020-08-06 01:21:14 +00:00
|
|
|
Scene models.Scene
|
|
|
|
Overwrite bool
|
|
|
|
fileNamingAlgorithm models.HashAlgorithm
|
2019-02-10 10:57:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 01:45:10 +00:00
|
|
|
func (t *GenerateSpriteTask) Start(wg *sizedwaitgroup.SizedWaitGroup) {
|
2019-02-10 20:15:36 +00:00
|
|
|
defer wg.Done()
|
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
if !t.Overwrite && !t.required() {
|
2019-02-10 10:57:56 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-07 00:38:30 +00:00
|
|
|
videoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.Scene.Path, false)
|
2019-02-10 10:57:56 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Errorf("error reading video file: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
sceneHash := t.Scene.GetHash(t.fileNamingAlgorithm)
|
|
|
|
imagePath := instance.Paths.Scene.GetSpriteImageFilePath(sceneHash)
|
|
|
|
vttPath := instance.Paths.Scene.GetSpriteVttFilePath(sceneHash)
|
2020-11-25 01:45:10 +00:00
|
|
|
generator, err := NewSpriteGenerator(*videoFile, sceneHash, imagePath, vttPath, 9, 9)
|
|
|
|
|
2019-02-10 10:57:56 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Errorf("error creating sprite generator: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
2020-07-23 23:20:34 +00:00
|
|
|
generator.Overwrite = t.Overwrite
|
2019-02-10 10:57:56 +00:00
|
|
|
|
|
|
|
if err := generator.Generate(); err != nil {
|
|
|
|
logger.Errorf("error generating sprite: %s", err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
// required returns true if the sprite needs to be generated
|
|
|
|
func (t GenerateSpriteTask) required() bool {
|
|
|
|
sceneHash := t.Scene.GetHash(t.fileNamingAlgorithm)
|
|
|
|
return !t.doesSpriteExist(sceneHash)
|
|
|
|
}
|
|
|
|
|
2019-02-10 10:57:56 +00:00
|
|
|
func (t *GenerateSpriteTask) doesSpriteExist(sceneChecksum string) bool {
|
2020-08-06 01:21:14 +00:00
|
|
|
if sceneChecksum == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-10 10:57:56 +00:00
|
|
|
imageExists, _ := utils.FileExists(instance.Paths.Scene.GetSpriteImageFilePath(sceneChecksum))
|
|
|
|
vttExists, _ := utils.FileExists(instance.Paths.Scene.GetSpriteVttFilePath(sceneChecksum))
|
|
|
|
return imageExists && vttExists
|
2019-02-14 22:53:32 +00:00
|
|
|
}
|