mirror of
https://github.com/stashapp/stash.git
synced 2026-04-20 13:27:57 -05:00
Wrap CleanCaptions with database. Refactor AssociateCaptions.
This commit is contained in:
@@ -363,7 +363,9 @@ func (j *ScanJob) handleFile(ctx context.Context, f file.ScannedFile, progress *
|
||||
if videoFile != nil {
|
||||
txnMgr := j.scanner.Repository.TxnManager
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,21 +129,25 @@ func AssociateCaptions(ctx context.Context, captionPath string, txnMgr txn.Manag
|
||||
matched = true
|
||||
|
||||
captions, er := w.GetCaptions(ctx, fileID)
|
||||
if er == nil {
|
||||
fileExt := filepath.Ext(captionPath)
|
||||
ext := fileExt[1:]
|
||||
if !IsLangInCaptions(captionLang, ext, captions) { // only update captions if language code is not present
|
||||
newCaption := &models.VideoCaption{
|
||||
LanguageCode: captionLang,
|
||||
Filename: filepath.Base(captionPath),
|
||||
CaptionType: ext,
|
||||
}
|
||||
captions = append(captions, newCaption)
|
||||
er = w.UpdateCaptions(ctx, fileID, captions)
|
||||
if er == nil {
|
||||
logger.Debugf("Updated captions for file %s. Added %s", path, captionLang)
|
||||
}
|
||||
if er != nil {
|
||||
return fmt.Errorf("getting captions for file %s: %w", path, er)
|
||||
}
|
||||
|
||||
fileExt := filepath.Ext(captionPath)
|
||||
ext := fileExt[1:]
|
||||
if !IsLangInCaptions(captionLang, ext, captions) { // only update captions if language code is not present
|
||||
newCaption := &models.VideoCaption{
|
||||
LanguageCode: captionLang,
|
||||
Filename: filepath.Base(captionPath),
|
||||
CaptionType: ext,
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user