stash/pkg/manager/task_generate_sprite.go

50 lines
1.3 KiB
Go
Raw Normal View History

2019-02-10 10:57:56 +00:00
package manager
import (
"sync"
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 {
Scene models.Scene
Overwrite bool
2019-02-10 10:57:56 +00:00
}
func (t *GenerateSpriteTask) Start(wg *sync.WaitGroup) {
2019-02-10 20:15:36 +00:00
defer wg.Done()
if t.doesSpriteExist(t.Scene.Checksum) && !t.Overwrite {
2019-02-10 10:57:56 +00:00
return
}
videoFile, err := ffmpeg.NewVideoFile(instance.FFProbePath, t.Scene.Path)
2019-02-10 10:57:56 +00:00
if err != nil {
logger.Errorf("error reading video file: %s", err.Error())
return
}
imagePath := instance.Paths.Scene.GetSpriteImageFilePath(t.Scene.Checksum)
vttPath := instance.Paths.Scene.GetSpriteVttFilePath(t.Scene.Checksum)
generator, err := NewSpriteGenerator(*videoFile, imagePath, vttPath, 9, 9)
if err != nil {
logger.Errorf("error creating sprite generator: %s", err.Error())
return
}
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
}
}
func (t *GenerateSpriteTask) doesSpriteExist(sceneChecksum string) bool {
imageExists, _ := utils.FileExists(instance.Paths.Scene.GetSpriteImageFilePath(sceneChecksum))
vttExists, _ := utils.FileExists(instance.Paths.Scene.GetSpriteVttFilePath(sceneChecksum))
return imageExists && vttExists
}