mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Fix and improve captions detection (#3276)
This commit is contained in:
@@ -156,6 +156,7 @@ type Finder interface {
|
|||||||
type Getter interface {
|
type Getter interface {
|
||||||
Finder
|
Finder
|
||||||
FindByPath(ctx context.Context, path string) (File, error)
|
FindByPath(ctx context.Context, path string) (File, error)
|
||||||
|
FindAllByPath(ctx context.Context, path string) ([]File, error)
|
||||||
FindByFingerprint(ctx context.Context, fp Fingerprint) ([]File, error)
|
FindByFingerprint(ctx context.Context, fp Fingerprint) ([]File, error)
|
||||||
FindByZipFileID(ctx context.Context, zipFileID ID) ([]File, error)
|
FindByZipFileID(ctx context.Context, zipFileID ID) ([]File, error)
|
||||||
FindAllInPaths(ctx context.Context, p []string, limit, offset int) ([]File, error)
|
FindAllInPaths(ctx context.Context, p []string, limit, offset int) ([]File, error)
|
||||||
|
|||||||
@@ -98,13 +98,22 @@ func AssociateCaptions(ctx context.Context, captionPath string, txnMgr txn.Manag
|
|||||||
captionPrefix := getCaptionPrefix(captionPath)
|
captionPrefix := getCaptionPrefix(captionPath)
|
||||||
if err := txn.WithTxn(ctx, txnMgr, func(ctx context.Context) error {
|
if err := txn.WithTxn(ctx, txnMgr, func(ctx context.Context) error {
|
||||||
var err error
|
var err error
|
||||||
f, er := fqb.FindByPath(ctx, captionPrefix+"*")
|
files, er := fqb.FindAllByPath(ctx, captionPrefix+"*")
|
||||||
|
|
||||||
if er != nil {
|
if er != nil {
|
||||||
return fmt.Errorf("searching for scene %s: %w", captionPrefix, er)
|
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
|
fileID := f.Base().ID
|
||||||
path := f.Base().Path
|
path := f.Base().Path
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
// 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) {
|
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
|
// separate basename from path
|
||||||
basename := filepath.Base(p)
|
basename := filepath.Base(p)
|
||||||
dirName := filepath.Dir(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) {
|
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||||
return nil, fmt.Errorf("getting file by path %s: %w", p, err)
|
return nil, fmt.Errorf("getting file by path %s: %w", p, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user