mirror of
https://github.com/stashapp/stash.git
synced 2025-12-15 04:44:28 +01:00
Associate funscript files on scan (#2978)
This commit is contained in:
parent
55001ddcf1
commit
b160c3bb97
4 changed files with 52 additions and 20 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue