Clean missing captions during scan (#3240)

This commit is contained in:
WithoutPants
2022-12-06 12:04:40 +11:00
committed by GitHub
parent b5b9023b3e
commit dc875ed5d7
4 changed files with 82 additions and 20 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/file/video"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/paths"
@@ -36,6 +37,7 @@ type ScanHandler struct {
CoverGenerator CoverGenerator
ScanGenerator ScanGenerator
CaptionUpdater video.CaptionUpdater
PluginCache *plugin.Cache
FileNamingAlgorithm models.HashAlgorithm
@@ -52,6 +54,9 @@ func (h *ScanHandler) validate() error {
if h.ScanGenerator == nil {
return errors.New("ScanGenerator is required")
}
if h.CaptionUpdater == nil {
return errors.New("CaptionUpdater is required")
}
if !h.FileNamingAlgorithm.IsValid() {
return errors.New("FileNamingAlgorithm is required")
}
@@ -72,6 +77,12 @@ func (h *ScanHandler) Handle(ctx context.Context, f file.File, oldFile file.File
return ErrNotVideoFile
}
if oldFile != nil {
if err := video.CleanCaptions(ctx, videoFile, nil, h.CaptionUpdater); err != nil {
return fmt.Errorf("cleaning captions: %w", err)
}
}
// try to match the file to a scene
existing, err := h.CreatorUpdater.FindByFileID(ctx, f.Base().ID)
if err != nil {