Fix and improve captions detection (#3276)

This commit is contained in:
puc9 2023-01-26 16:52:56 -08:00 committed by GitHub
parent 08560923d2
commit cf0ce6cb08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)
}