mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Associate funscript files on scan (#2978)
This commit is contained in:
@@ -195,6 +195,7 @@ type Store interface {
|
|||||||
// Decorator wraps the Decorate method to add additional functionality while scanning files.
|
// Decorator wraps the Decorate method to add additional functionality while scanning files.
|
||||||
type Decorator interface {
|
type Decorator interface {
|
||||||
Decorate(ctx context.Context, fs FS, f File) (File, error)
|
Decorate(ctx context.Context, fs FS, f File) (File, error)
|
||||||
|
IsMissingMetadata(ctx context.Context, fs FS, f File) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type FilteredDecorator struct {
|
type FilteredDecorator struct {
|
||||||
@@ -209,3 +210,11 @@ func (d *FilteredDecorator) Decorate(ctx context.Context, fs FS, f File) (File,
|
|||||||
}
|
}
|
||||||
return f, nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,3 +37,17 @@ func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file
|
|||||||
Height: c.Height,
|
Height: c.Height,
|
||||||
}, nil
|
}, 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -807,24 +807,11 @@ func (s *scanJob) isHandlerRequired(ctx context.Context, f File) bool {
|
|||||||
// - file size
|
// - file size
|
||||||
// - image format, width or height
|
// - image format, width or height
|
||||||
// - video codec, audio codec, format, width, height, framerate or bitrate
|
// - video codec, audio codec, format, width, height, framerate or bitrate
|
||||||
func (s *scanJob) isMissingMetadata(existing File) bool {
|
func (s *scanJob) isMissingMetadata(ctx context.Context, f scanFile, existing File) bool {
|
||||||
const (
|
for _, h := range s.FileDecorators {
|
||||||
unsetString = "unset"
|
if h.IsMissingMetadata(ctx, f.fs, existing) {
|
||||||
unsetNumber = -1
|
return true
|
||||||
)
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
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) {
|
func (s *scanJob) setMissingMetadata(ctx context.Context, f scanFile, existing File) (File, error) {
|
||||||
path := existing.Base().Path
|
path := existing.Base().Path
|
||||||
logger.Infof("Setting missing metadata for %s", path)
|
logger.Infof("Updating metadata for %s", path)
|
||||||
|
|
||||||
existing.Base().Size = f.Size
|
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) {
|
func (s *scanJob) onUnchangedFile(ctx context.Context, f scanFile, existing File) (File, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
isMissingMetdata := s.isMissingMetadata(existing)
|
isMissingMetdata := s.isMissingMetadata(ctx, f, existing)
|
||||||
// set missing information
|
// set missing information
|
||||||
if isMissingMetdata {
|
if isMissingMetdata {
|
||||||
existing, err = s.setMissingMetadata(ctx, f, existing)
|
existing, err = s.setMissingMetadata(ctx, f, existing)
|
||||||
|
|||||||
@@ -55,3 +55,25 @@ func (d *Decorator) Decorate(ctx context.Context, fs file.FS, f file.File) (file
|
|||||||
Interactive: interactive,
|
Interactive: interactive,
|
||||||
}, nil
|
}, 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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user