diff --git a/pkg/file/file.go b/pkg/file/file.go index 91c1cc448..c5de0b8a9 100644 --- a/pkg/file/file.go +++ b/pkg/file/file.go @@ -195,6 +195,7 @@ type Store interface { // Decorator wraps the Decorate method to add additional functionality while scanning files. type Decorator interface { Decorate(ctx context.Context, fs FS, f File) (File, error) + IsMissingMetadata(ctx context.Context, fs FS, f File) bool } type FilteredDecorator struct { @@ -209,3 +210,11 @@ func (d *FilteredDecorator) Decorate(ctx context.Context, fs FS, f File) (File, } return f, nil } + +func (d *FilteredDecorator) IsMissingMetadata(ctx context.Context, fs FS, f File) bool { + if d.Accept(ctx, f) { + return d.Decorator.IsMissingMetadata(ctx, fs, f) + } + + return false +} diff --git a/pkg/file/image/scan.go b/pkg/file/image/scan.go index 2de4bbcea..a029f5cce 100644 --- a/pkg/file/image/scan.go +++ b/pkg/file/image/scan.go @@ -37,3 +37,17 @@ func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file Height: c.Height, }, nil } + +func (d *Decorator) IsMissingMetadata(ctx context.Context, fs file.FS, f file.File) bool { + const ( + unsetString = "unset" + unsetNumber = -1 + ) + + imf, ok := f.(*file.ImageFile) + if !ok { + return true + } + + return imf.Format == unsetString || imf.Width == unsetNumber || imf.Height == unsetNumber +} diff --git a/pkg/file/scan.go b/pkg/file/scan.go index a631b9ca7..df88505ef 100644 --- a/pkg/file/scan.go +++ b/pkg/file/scan.go @@ -807,24 +807,11 @@ func (s *scanJob) isHandlerRequired(ctx context.Context, f File) bool { // - file size // - image format, width or height // - video codec, audio codec, format, width, height, framerate or bitrate -func (s *scanJob) isMissingMetadata(existing File) bool { - const ( - unsetString = "unset" - unsetNumber = -1 - ) - - if existing.Base().Size == unsetNumber { - return true - } - - switch f := existing.(type) { - case *ImageFile: - return f.Format == unsetString || f.Width == unsetNumber || f.Height == unsetNumber - case *VideoFile: - return f.VideoCodec == unsetString || f.AudioCodec == unsetString || - f.Format == unsetString || f.Width == unsetNumber || - f.Height == unsetNumber || f.FrameRate == unsetNumber || - f.BitRate == unsetNumber +func (s *scanJob) isMissingMetadata(ctx context.Context, f scanFile, existing File) bool { + for _, h := range s.FileDecorators { + if h.IsMissingMetadata(ctx, f.fs, existing) { + return true + } } return false @@ -832,7 +819,7 @@ func (s *scanJob) isMissingMetadata(existing File) bool { func (s *scanJob) setMissingMetadata(ctx context.Context, f scanFile, existing File) (File, error) { path := existing.Base().Path - logger.Infof("Setting missing metadata for %s", path) + logger.Infof("Updating metadata for %s", path) existing.Base().Size = f.Size @@ -962,7 +949,7 @@ func (s *scanJob) removeOutdatedFingerprints(existing File, fp Fingerprints) { func (s *scanJob) onUnchangedFile(ctx context.Context, f scanFile, existing File) (File, error) { var err error - isMissingMetdata := s.isMissingMetadata(existing) + isMissingMetdata := s.isMissingMetadata(ctx, f, existing) // set missing information if isMissingMetdata { existing, err = s.setMissingMetadata(ctx, f, existing) diff --git a/pkg/file/video/scan.go b/pkg/file/video/scan.go index 4faea85aa..b1ddf2d83 100644 --- a/pkg/file/video/scan.go +++ b/pkg/file/video/scan.go @@ -55,3 +55,25 @@ func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file Interactive: interactive, }, nil } + +func (d *Decorator) IsMissingMetadata(ctx context.Context, fs file.FS, f file.File) bool { + const ( + unsetString = "unset" + unsetNumber = -1 + ) + + vf, ok := f.(*file.VideoFile) + if !ok { + return true + } + + interactive := false + if _, err := fs.Lstat(GetFunscriptPath(vf.Base().Path)); err == nil { + interactive = true + } + + return vf.VideoCodec == unsetString || vf.AudioCodec == unsetString || + vf.Format == unsetString || vf.Width == unsetNumber || + vf.Height == unsetNumber || vf.FrameRate == unsetNumber || + vf.BitRate == unsetNumber || interactive != vf.Interactive +}