mirror of https://github.com/stashapp/stash.git
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package video
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/stashapp/stash/pkg/ffmpeg"
|
|
"github.com/stashapp/stash/pkg/file"
|
|
)
|
|
|
|
// Decorator adds video specific fields to a File.
|
|
type Decorator struct {
|
|
FFProbe ffmpeg.FFProbe
|
|
}
|
|
|
|
func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file.File, error) {
|
|
if d.FFProbe == "" {
|
|
return f, errors.New("ffprobe not configured")
|
|
}
|
|
|
|
base := f.Base()
|
|
// TODO - copy to temp file if not an OsFS
|
|
if _, isOs := fs.(*file.OsFS); !isOs {
|
|
return f, fmt.Errorf("video.constructFile: only OsFS is supported")
|
|
}
|
|
|
|
probe := d.FFProbe
|
|
videoFile, err := probe.NewVideoFile(base.Path)
|
|
if err != nil {
|
|
return f, fmt.Errorf("running ffprobe on %q: %w", base.Path, err)
|
|
}
|
|
|
|
container, err := ffmpeg.MatchContainer(videoFile.Container, base.Path)
|
|
if err != nil {
|
|
return f, fmt.Errorf("matching container for %q: %w", base.Path, err)
|
|
}
|
|
|
|
// check if there is a funscript file
|
|
interactive := false
|
|
if _, err := fs.Lstat(GetFunscriptPath(base.Path)); err == nil {
|
|
interactive = true
|
|
}
|
|
|
|
return &file.VideoFile{
|
|
BaseFile: base,
|
|
Format: string(container),
|
|
VideoCodec: videoFile.VideoCodec,
|
|
AudioCodec: videoFile.AudioCodec,
|
|
Width: videoFile.Width,
|
|
Height: videoFile.Height,
|
|
Duration: videoFile.Duration,
|
|
FrameRate: videoFile.FrameRate,
|
|
BitRate: videoFile.Bitrate,
|
|
Interactive: interactive,
|
|
}, nil
|
|
}
|