diff --git a/pkg/file/file.go b/pkg/file/file.go index 525c0f329..55b1f2e67 100644 --- a/pkg/file/file.go +++ b/pkg/file/file.go @@ -156,6 +156,7 @@ type Finder interface { type Getter interface { Finder FindByPath(ctx context.Context, path string) (File, error) + FindAllByPath(ctx context.Context, path string) ([]File, error) FindByFingerprint(ctx context.Context, fp Fingerprint) ([]File, error) FindByZipFileID(ctx context.Context, zipFileID ID) ([]File, error) FindAllInPaths(ctx context.Context, p []string, limit, offset int) ([]File, error) diff --git a/pkg/file/video/caption.go b/pkg/file/video/caption.go index 2820caee4..d2f8e79a5 100644 --- a/pkg/file/video/caption.go +++ b/pkg/file/video/caption.go @@ -98,13 +98,22 @@ func AssociateCaptions(ctx context.Context, captionPath string, txnMgr txn.Manag captionPrefix := getCaptionPrefix(captionPath) if err := txn.WithTxn(ctx, txnMgr, func(ctx context.Context) error { var err error - f, er := fqb.FindByPath(ctx, captionPrefix+"*") + files, er := fqb.FindAllByPath(ctx, captionPrefix+"*") if er != nil { return fmt.Errorf("searching for scene %s: %w", captionPrefix, er) } - if f != nil { // found related Scene + for _, f := range files { + // found some files + // filter out non video files + switch f.(type) { + case *file.VideoFile: + break + default: + continue + } + fileID := f.Base().ID path := f.Base().Path diff --git a/pkg/sqlite/file.go b/pkg/sqlite/file.go index 0cd21ee4b..ba971c018 100644 --- a/pkg/sqlite/file.go +++ b/pkg/sqlite/file.go @@ -575,6 +575,23 @@ func (qb *FileStore) find(ctx context.Context, id file.ID) (file.File, error) { // FindByPath returns the first file that matches the given path. Wildcard characters are supported. func (qb *FileStore) FindByPath(ctx context.Context, p string) (file.File, error) { + + ret, err := qb.FindAllByPath(ctx, p) + + if err != nil { + return nil, err + } + + if len(ret) == 0 { + return nil, nil + } + + return ret[0], nil +} + +// FindAllByPath returns all the files that match the given path. +// Wildcard characters are supported. +func (qb *FileStore) FindAllByPath(ctx context.Context, p string) ([]file.File, error) { // separate basename from path basename := filepath.Base(p) dirName := filepath.Dir(p) @@ -601,7 +618,7 @@ func (qb *FileStore) FindByPath(ctx context.Context, p string) (file.File, error ) } - ret, err := qb.get(ctx, q) + ret, err := qb.getMany(ctx, q) if err != nil && !errors.Is(err, sql.ErrNoRows) { return nil, fmt.Errorf("getting file by path %s: %w", p, err) }