mirror of https://github.com/stashapp/stash.git
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
![]() |
package manager
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/stashapp/stash/pkg/file"
|
||
|
"github.com/stashapp/stash/pkg/fsutil"
|
||
|
"github.com/stashapp/stash/pkg/image"
|
||
|
"github.com/stashapp/stash/pkg/logger"
|
||
|
"github.com/stashapp/stash/pkg/models"
|
||
|
)
|
||
|
|
||
|
type GenerateClipPreviewTask struct {
|
||
|
Image models.Image
|
||
|
Overwrite bool
|
||
|
}
|
||
|
|
||
|
func (t *GenerateClipPreviewTask) GetDescription() string {
|
||
|
return fmt.Sprintf("Generating Preview for image Clip %s", t.Image.Path)
|
||
|
}
|
||
|
|
||
|
func (t *GenerateClipPreviewTask) Start(ctx context.Context) {
|
||
|
if !t.required() {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
prevPath := GetInstance().Paths.Generated.GetClipPreviewPath(t.Image.Checksum, models.DefaultGthumbWidth)
|
||
|
filePath := t.Image.Files.Primary().Base().Path
|
||
|
|
||
|
clipPreviewOptions := image.ClipPreviewOptions{
|
||
|
InputArgs: GetInstance().Config.GetTranscodeInputArgs(),
|
||
|
OutputArgs: GetInstance().Config.GetTranscodeOutputArgs(),
|
||
|
Preset: GetInstance().Config.GetPreviewPreset().String(),
|
||
|
}
|
||
|
|
||
|
encoder := image.NewThumbnailEncoder(GetInstance().FFMPEG, GetInstance().FFProbe, clipPreviewOptions)
|
||
|
data, err := encoder.GetPreview(t.Image.Files.Primary(), models.DefaultGthumbWidth)
|
||
|
if err != nil {
|
||
|
logger.Errorf("getting preview for image %s: %w", filePath, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err = fsutil.WriteFile(prevPath, data)
|
||
|
if err != nil {
|
||
|
logger.Errorf("writing preview for image %s: %w", filePath, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
func (t *GenerateClipPreviewTask) required() bool {
|
||
|
_, ok := t.Image.Files.Primary().(*file.VideoFile)
|
||
|
if !ok {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
if t.Overwrite {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
prevPath := GetInstance().Paths.Generated.GetClipPreviewPath(t.Image.Checksum, models.DefaultGthumbWidth)
|
||
|
if exists, _ := fsutil.FileExists(prevPath); exists {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|