Ignore video clips in zip files (#3826)

This commit is contained in:
DingDongSoLong4 2023-06-15 05:34:49 +02:00 committed by GitHub
parent d81a0fcffb
commit 4f11a2820f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,7 @@ import (
"github.com/stashapp/stash/pkg/ffmpeg" "github.com/stashapp/stash/pkg/ffmpeg"
"github.com/stashapp/stash/pkg/file" "github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/file/video" "github.com/stashapp/stash/pkg/file/video"
"github.com/stashapp/stash/pkg/logger"
_ "golang.org/x/image/webp" _ "golang.org/x/image/webp"
) )
@ -22,15 +23,14 @@ type Decorator struct {
func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file.File, error) { func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file.File, error) {
base := f.Base() base := f.Base()
decorateFallback := func() (file.File, error) {
r, err := fs.Open(base.Path) r, err := fs.Open(base.Path)
if err != nil { if err != nil {
return f, fmt.Errorf("reading image file %q: %w", base.Path, err) return f, fmt.Errorf("reading image file %q: %w", base.Path, err)
} }
defer r.Close() defer r.Close()
probe, err := d.FFProbe.NewVideoFile(base.Path)
if err != nil {
fmt.Printf("Warning: File %q could not be read with ffprobe: %s, assuming ImageFile", base.Path, err)
c, format, err := image.DecodeConfig(r) c, format, err := image.DecodeConfig(r)
if err != nil { if err != nil {
return f, fmt.Errorf("decoding image file %q: %w", base.Path, err) return f, fmt.Errorf("decoding image file %q: %w", base.Path, err)
@ -43,6 +43,19 @@ func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file
}, nil }, nil
} }
// ignore clips in non-OsFS filesystems as ffprobe cannot read them
// TODO - copy to temp file if not an OsFS
if _, isOs := fs.(*file.OsFS); !isOs {
logger.Debugf("assuming ImageFile for non-OsFS file %q", base.Path)
return decorateFallback()
}
probe, err := d.FFProbe.NewVideoFile(base.Path)
if err != nil {
logger.Warnf("File %q could not be read with ffprobe: %s, assuming ImageFile", base.Path, err)
return decorateFallback()
}
isClip := true isClip := true
// This list is derived from ffmpegImageThumbnail in pkg/image/thumbnail. If one gets updated, the other should be as well // This list is derived from ffmpegImageThumbnail in pkg/image/thumbnail. If one gets updated, the other should be as well
for _, item := range []string{"png", "mjpeg", "webp"} { for _, item := range []string{"png", "mjpeg", "webp"} {