From 4f11a2820f1a1b99a3e8180165e68018e24e0708 Mon Sep 17 00:00:00 2001 From: DingDongSoLong4 <99329275+DingDongSoLong4@users.noreply.github.com> Date: Thu, 15 Jun 2023 05:34:49 +0200 Subject: [PATCH] Ignore video clips in zip files (#3826) --- pkg/file/image/scan.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pkg/file/image/scan.go b/pkg/file/image/scan.go index ec4ce542b..dbf272b19 100644 --- a/pkg/file/image/scan.go +++ b/pkg/file/image/scan.go @@ -12,6 +12,7 @@ import ( "github.com/stashapp/stash/pkg/ffmpeg" "github.com/stashapp/stash/pkg/file" "github.com/stashapp/stash/pkg/file/video" + "github.com/stashapp/stash/pkg/logger" _ "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) { base := f.Base() - r, err := fs.Open(base.Path) - if err != nil { - return f, fmt.Errorf("reading image file %q: %w", base.Path, err) - } - 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) + decorateFallback := func() (file.File, error) { + r, err := fs.Open(base.Path) + if err != nil { + return f, fmt.Errorf("reading image file %q: %w", base.Path, err) + } + defer r.Close() + c, format, err := image.DecodeConfig(r) if err != nil { 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 } + // 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 // 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"} {