mirror of
https://github.com/stashapp/stash.git
synced 2026-05-08 12:32:29 +02:00
Wrap CleanCaptions with database. Refactor AssociateCaptions.
This commit is contained in:
parent
bc75d47f15
commit
09e2b2bd4e
2 changed files with 21 additions and 15 deletions
|
|
@ -363,7 +363,9 @@ func (j *ScanJob) handleFile(ctx context.Context, f file.ScannedFile, progress *
|
||||||
if videoFile != nil {
|
if videoFile != nil {
|
||||||
txnMgr := j.scanner.Repository.TxnManager
|
txnMgr := j.scanner.Repository.TxnManager
|
||||||
fileRepo := j.scanner.Repository.File
|
fileRepo := j.scanner.Repository.File
|
||||||
if err := video.CleanCaptions(ctx, videoFile, txnMgr, fileRepo); err != nil {
|
if err := txn.WithDatabase(ctx, txnMgr, func(ctx context.Context) error {
|
||||||
|
return video.CleanCaptions(ctx, videoFile, txnMgr, fileRepo)
|
||||||
|
}); err != nil {
|
||||||
logger.Errorf("Error cleaning captions: %v", err)
|
logger.Errorf("Error cleaning captions: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,21 +129,25 @@ func AssociateCaptions(ctx context.Context, captionPath string, txnMgr txn.Manag
|
||||||
matched = true
|
matched = true
|
||||||
|
|
||||||
captions, er := w.GetCaptions(ctx, fileID)
|
captions, er := w.GetCaptions(ctx, fileID)
|
||||||
if er == nil {
|
if er != nil {
|
||||||
fileExt := filepath.Ext(captionPath)
|
return fmt.Errorf("getting captions for file %s: %w", path, er)
|
||||||
ext := fileExt[1:]
|
}
|
||||||
if !IsLangInCaptions(captionLang, ext, captions) { // only update captions if language code is not present
|
|
||||||
newCaption := &models.VideoCaption{
|
fileExt := filepath.Ext(captionPath)
|
||||||
LanguageCode: captionLang,
|
ext := fileExt[1:]
|
||||||
Filename: filepath.Base(captionPath),
|
if !IsLangInCaptions(captionLang, ext, captions) { // only update captions if language code is not present
|
||||||
CaptionType: ext,
|
newCaption := &models.VideoCaption{
|
||||||
}
|
LanguageCode: captionLang,
|
||||||
captions = append(captions, newCaption)
|
Filename: filepath.Base(captionPath),
|
||||||
er = w.UpdateCaptions(ctx, fileID, captions)
|
CaptionType: ext,
|
||||||
if er == nil {
|
|
||||||
logger.Debugf("Updated captions for file %s. Added %s", path, captionLang)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
captions = append(captions, newCaption)
|
||||||
|
er = w.UpdateCaptions(ctx, fileID, captions)
|
||||||
|
if er != nil {
|
||||||
|
return fmt.Errorf("updating captions for file %s: %w", path, er)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Debugf("Updated captions for file %s. Added %s", path, captionLang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue