func (t *ScanTask) associateCaptions(ctx context.Context) {
	vExt := config.GetInstance().GetVideoExtensions()
	captionPath := t.file.Path()
	captionLang := scene.GetCaptionsLangFromPath(captionPath)

	relatedFiles := scene.GenerateCaptionCandidates(captionPath, vExt)
	if err := t.TxnManager.WithTxn(ctx, func(r models.Repository) error {
		var err error
		sqb := r.Scene()

		for _, scenePath := range relatedFiles {
			s, er := sqb.FindByPath(scenePath)

			if er != nil {
				logger.Errorf("Error searching for scene %s: %v", scenePath, er)
				continue
			}
			if s != nil { // found related Scene
				logger.Debugf("Matched captions to scene %s", s.Path)
				captions, er := sqb.GetCaptions(s.ID)
				if er == nil {
					fileExt := filepath.Ext(captionPath)
					ext := fileExt[1:]
					if !scene.IsLangInCaptions(captionLang, ext, captions) { // only update captions if language code is not present
						newCaption := &models.SceneCaption{
							LanguageCode: captionLang,
							Filename:     filepath.Base(captionPath),
							CaptionType:  ext,
						}
						captions = append(captions, newCaption)
						er = sqb.UpdateCaptions(s.ID, captions)
						if er == nil {
							logger.Debugf("Updated captions for scene %s. Added %s", s.Path, captionLang)
						}
					}
				}
			}
		}
		return err
	}); err != nil {
		logger.Error(err.Error())
	}
}
// associates captions to scene/s with the same basename
associates captions to scene/s with the same basename
// associates captions to scene / s with the same basename
func (t *ScanTask) associateCaptions(ctx context.Context) {
	vExt := config.GetInstance().GetVideoExtensions()
	captionPath := t.file.Path()
	captionLang := scene.GetCaptionsLangFromPath(captionPath)
	relatedFiles := scene.GenerateCaptionCandidates(captionPath, vExt)
	if err := t.TxnManager.WithTxn(ctx, func(r models.Repository) error {
		var err error
		sqb := r.Scene()
		for _, scenePath := range relatedFiles {
			s, er := sqb.FindByPath(scenePath)
			if er != nil {
				logger.Errorf("Error searching for scene %s: %v", scenePath, er)
				continue
			}
			if s != nil { 
				logger.Debugf("Matched captions to scene %s", s.Path)
				captions, er := sqb.GetCaptions(s.ID)
				if er == nil {
					fileExt := filepath.Ext(captionPath)
					ext := fileExt[1:]
					if !scene.IsLangInCaptions(captionLang, ext, captions) { 
						newCaption := &models.SceneCaption{
							LanguageCode: captionLang,
							Filename:     filepath.Base(captionPath),
							CaptionType:  ext,
						}
						captions = append(captions, newCaption)
						er = sqb.UpdateCaptions(s.ID, captions)
						if er == nil {
							logger.Debugf("Updated captions for scene %s. Added %s", s.Path, captionLang)
						}
					}
				}
			}
		}
		return err
	}); err != nil {
		logger.Error(err.Error())
	}
}
func ( t * ScanTask ) associateCaptions ( ctx context . Context ) { vExt := config . GetInstance ( ) . GetVideoExtensions ( ) captionPath := t . file . Path ( ) captionLang := scene . GetCaptionsLangFromPath ( captionPath ) relatedFiles := scene . GenerateCaptionCandidates ( captionPath , vExt ) if err := t . TxnManager . WithTxn ( ctx , func ( r models . Repository ) error { var err error sqb := r . Scene ( ) for _ , scenePath := range relatedFiles { s , er := sqb . FindByPath ( scenePath ) if er != nil { logger . Errorf ( " " , scenePath , er ) continue } if s != nil { logger . Debugf ( " " , s . Path ) captions , er := sqb . GetCaptions ( s . ID ) if er == nil { fileExt := filepath . Ext ( captionPath ) ext := fileExt [ 1 : ] if ! scene . IsLangInCaptions ( captionLang , ext , captions ) { newCaption := & models . SceneCaption { LanguageCode : captionLang , Filename : filepath . Base ( captionPath ) , CaptionType : ext , } captions = append ( captions , newCaption ) er = sqb . UpdateCaptions ( s . ID , captions ) if er == nil { logger . Debugf ( " " , s . Path , captionLang ) } } } } } return err } ) ; err != nil { logger . Error ( err . Error ( ) ) } }
associates captions to scene/s with the same basename
associates captions to scene / s with the same basename
// found related Scene // only update captions if language code is not present