Browse Source

重构设置的名称

Signed-off-by: allan716 <[email protected]>
allan716 4 years ago
parent
commit
b007d884f2

+ 3 - 3
internal/logic/sub_timeline_fixer/sub_timeline_fixer_helper.go

@@ -250,7 +250,7 @@ func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, containCh
 		log_helper.GetLogger().Infoln(infoSrc.Name, "offset time is", fmt.Sprintf("%f", offsetTime), "s")
 	}
 	// 超过 SD 阈值了
-	if sd > s.FixerConfig.MaxStartTimeDiffSD {
+	if sd > s.FixerConfig.V1_MaxStartTimeDiffSD {
 		log_helper.GetLogger().Infoln(infoSrc.Name, "Start Time Diff SD, skip", fmt.Sprintf("%f", sd))
 		return false, nil, fixedSubName, nil
 	} else {
@@ -262,8 +262,8 @@ func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, containCh
 	}
 
 	// 偏移很小就无视了
-	if offsetTime < s.FixerConfig.MinOffset && offsetTime > -s.FixerConfig.MinOffset {
-		log_helper.GetLogger().Infoln(infoSrc.Name, fmt.Sprintf("Min Offset Config is %f, skip ", s.FixerConfig.MinOffset), fmt.Sprintf("now is %f", offsetTime))
+	if offsetTime < s.FixerConfig.V1_MinOffset && offsetTime > -s.FixerConfig.V1_MinOffset {
+		log_helper.GetLogger().Infoln(infoSrc.Name, fmt.Sprintf("Min Offset Config is %f, skip ", s.FixerConfig.V1_MinOffset), fmt.Sprintf("now is %f", offsetTime))
 		return false, nil, fixedSubName, nil
 	}
 	// 写入校准时间轴后的字幕

+ 13 - 13
internal/pkg/sub_timeline_fixer/fixer.go

@@ -143,7 +143,7 @@ func (s *SubTimelineFixer) GetOffsetTimeV1(infoBase, infoSrc *subparser.FileInfo
 	/*
 		确认两个字幕间的偏移,暂定的方案是两边都连续匹配上 5 个索引,再抽取一个对话的时间进行修正计算
 	*/
-	maxCompareDialogue := s.FixerConfig.MaxCompareDialogue
+	maxCompareDialogue := s.FixerConfig.V1_MaxCompareDialogue
 	// 基线的长度
 	_, docsLength := tfidf.Dims()
 	var matchIndexList = make([]MatchIndex, 0)
@@ -337,14 +337,14 @@ func (s *SubTimelineFixer) GetOffsetTimeV1(infoBase, infoSrc *subparser.FileInfo
 	matchIndexLineCount := len(matchIndexList) * maxCompareDialogue
 	//perMatch := float64(matchIndexLineCount) / float64(len(infoSrc.DialoguesEx))
 	perMatch := float64(matchIndexLineCount) / float64(len(baseCorpus))
-	if perMatch < s.FixerConfig.MinMatchedPercent {
-		tmpContent := infoSrc.Name + fmt.Sprintf(" Sequence match %d dialogues (< %f%%), Skip,", s.FixerConfig.MaxCompareDialogue, s.FixerConfig.MinMatchedPercent*100) + fmt.Sprintf(" %f%% ", perMatch*100)
+	if perMatch < s.FixerConfig.V1_MinMatchedPercent {
+		tmpContent := infoSrc.Name + fmt.Sprintf(" Sequence match %d dialogues (< %f%%), Skip,", s.FixerConfig.V1_MaxCompareDialogue, s.FixerConfig.V1_MinMatchedPercent*100) + fmt.Sprintf(" %f%% ", perMatch*100)
 
 		debugInfos = append(debugInfos, tmpContent)
 
 		log_helper.GetLogger().Infoln(tmpContent)
 	} else {
-		tmpContent := infoSrc.Name + fmt.Sprintf(" Sequence match %d dialogues,", s.FixerConfig.MaxCompareDialogue) + fmt.Sprintf(" %f%% ", perMatch*100)
+		tmpContent := infoSrc.Name + fmt.Sprintf(" Sequence match %d dialogues,", s.FixerConfig.V1_MaxCompareDialogue) + fmt.Sprintf(" %f%% ", perMatch*100)
 
 		debugInfos = append(debugInfos, tmpContent)
 
@@ -359,7 +359,7 @@ func (s *SubTimelineFixer) GetOffsetTimeV1(infoBase, infoSrc *subparser.FileInfo
 		}
 	}
 	// 虽然有条件判断是认为有问题的,但是返回值还是要填写除去的
-	if perMatch < s.FixerConfig.MinMatchedPercent {
+	if perMatch < s.FixerConfig.V1_MinMatchedPercent {
 		return false, newMean, newSd, nil
 	}
 
@@ -396,12 +396,12 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
 
 	srcVADLen := len(srcUnit.VADList)
 	// 滑动窗口的长度
-	srcWindowLen := int(float64(srcVADLen) * s.FixerConfig.WindowMatchPer)
+	srcWindowLen := int(float64(srcVADLen) * s.FixerConfig.V2_WindowMatchPer)
 	srcSlideLen := srcVADLen - srcWindowLen
 	// 窗口可以滑动的长度
 	srcSlideLenHalf := srcSlideLen / 2
 	//
-	oneStep := srcSlideLenHalf / s.FixerConfig.CompareParts
+	oneStep := srcSlideLenHalf / s.FixerConfig.V2_CompareParts
 	if srcSlideLen <= 0 {
 		srcSlideLen = 1
 	}
@@ -424,8 +424,8 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
 		// 图解,参考 Step 3
 		if bUseSubOrAudioAsBase == false {
 			// 使用 音频 来进行匹配
-			// 去掉头和尾,具体百分之多少,见 FrontAndEndPerBase
-			audioCutLen := int(float64(len(inData.AudioVADList)) * s.FixerConfig.FrontAndEndPerBase)
+			// 去掉头和尾,具体百分之多少,见 V2_FrontAndEndPerBase
+			audioCutLen := int(float64(len(inData.AudioVADList)) * s.FixerConfig.V2_FrontAndEndPerBase)
 
 			offsetIndex, score = fffAligner.Fit(inData.AudioVADList[audioCutLen:len(inData.AudioVADList)-audioCutLen], inData.SrcUnit.GetVADFloatSlice()[inData.OffsetIndex:srcWindowLen+inData.OffsetIndex])
 			realOffsetIndex := offsetIndex + audioCutLen
@@ -466,10 +466,10 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
 		return nil
 	}
 	// -------------------------------------------------
-	antPool, err := ants.NewPoolWithFunc(s.FixerConfig.FixThreads, func(inData interface{}) {
+	antPool, err := ants.NewPoolWithFunc(s.FixerConfig.V2_FixThreads, func(inData interface{}) {
 		data := inData.(InputData)
 		defer data.Wg.Done()
-		ctx, cancel := context.WithTimeout(context.Background(), time.Duration(s.FixerConfig.SubOneUnitProcessTimeOut)*time.Second)
+		ctx, cancel := context.WithTimeout(context.Background(), time.Duration(s.FixerConfig.V2_SubOneUnitProcessTimeOut)*time.Second)
 		defer cancel()
 
 		done := make(chan error, 1)
@@ -522,8 +522,8 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
 		i += oneStep
 	}
 	wg.Wait()
-	// 这里可能遇到匹配的时候没有能够执行够 CompareParts 次,有可能是负数跳过或者时间转换失败导致,前者为主(可能是这两个就是一个东西的时候,或者说没有时间轴偏移的时候)
-	if insertIndex < s.FixerConfig.CompareParts/2 {
+	// 这里可能遇到匹配的时候没有能够执行够 V2_CompareParts 次,有可能是负数跳过或者时间转换失败导致,前者为主(可能是这两个就是一个东西的时候,或者说没有时间轴偏移的时候)
+	if insertIndex < s.FixerConfig.V2_CompareParts/2 {
 		return false, 0, 0, nil
 	}
 	outCorrelationFixResult := s.calcMeanAndSD(tmpStartDiffTimeListEx, tmpStartDiffTimeList)

+ 17 - 15
internal/pkg/sub_timeline_fixer/fixer_test.go

@@ -590,23 +590,23 @@ func TestGetOffsetTimeV2_BaseSub(t *testing.T) {
 			//sub_helper.MergeMultiDialogue4EngSubtitle(infoSrc)
 			// ---------------------------------------------------------------------------------------
 			// Base,截取的部分要大于 Src 的部分
-			//baseUnitListOld, err := sub_helper.GetVADInfoFeatureFromSub(infoBase, FrontAndEndPerBase, 100000, true)
+			//baseUnitListOld, err := sub_helper.GetVADInfoFeatureFromSub(infoBase, V2_FrontAndEndPerBase, 100000, true)
 			//if err != nil {
 			//	t.Fatal(err)
 			//}
 			//baseUnitOld := baseUnitListOld[0]
-			baseUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoBase, timelineFixer.FixerConfig.FrontAndEndPerBase)
+			baseUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoBase, timelineFixer.FixerConfig.V2_FrontAndEndPerBase)
 			if err != nil {
 				t.Fatal(err)
 			}
 			// ---------------------------------------------------------------------------------------
 			// Src,截取的部分要小于 Base 的部分
-			//srcUnitListOld, err := sub_helper.GetVADInfoFeatureFromSub(infoSrc, FrontAndEndPerSrc, 100000, true)
+			//srcUnitListOld, err := sub_helper.GetVADInfoFeatureFromSub(infoSrc, V2_FrontAndEndPerSrc, 100000, true)
 			//if err != nil {
 			//	t.Fatal(err)
 			//}
 			//srcUnitOld := srcUnitListOld[0]
-			srcUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoSrc, timelineFixer.FixerConfig.FrontAndEndPerSrc)
+			srcUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoSrc, timelineFixer.FixerConfig.V2_FrontAndEndPerSrc)
 			if err != nil {
 				t.Fatal(err)
 			}
@@ -745,7 +745,7 @@ func TestGetOffsetTimeV2_BaseAudio(t *testing.T) {
 			*/
 			//sub_helper.MergeMultiDialogue4EngSubtitle(infoSrc)
 			// Src,截取的部分要小于 Base 的部分
-			srcUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoSrc, timelineFixer.FixerConfig.FrontAndEndPerSrc)
+			srcUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoSrc, timelineFixer.FixerConfig.V2_FrontAndEndPerSrc)
 			if err != nil {
 				t.Fatal(err)
 			}
@@ -790,15 +790,17 @@ func TestGetOffsetTimeV2_BaseAudio(t *testing.T) {
 
 var timelineFixer = NewSubTimelineFixer(sub_timeline_fiexer.SubTimelineFixerConfig{
 	// V1
-	MaxCompareDialogue: 3,
-	MaxStartTimeDiffSD: 0.1,
-	MinMatchedPercent:  0.1,
-	MinOffset:          0.1,
+	V1_MaxCompareDialogue: 3,
+	V1_MaxStartTimeDiffSD: 0.1,
+	V1_MinMatchedPercent:  0.1,
+	V1_MinOffset:          0.1,
 	// V2
-	SubOneUnitProcessTimeOut: 5 * 60,
-	FrontAndEndPerBase:       0.15,
-	FrontAndEndPerSrc:        0.0,
-	WindowMatchPer:           0.7,
-	CompareParts:             5,
-	FixThreads:               3,
+	V2_SubOneUnitProcessTimeOut: 5 * 60,
+	V2_FrontAndEndPerBase:       0.15,
+	V2_FrontAndEndPerSrc:        0.0,
+	V2_WindowMatchPer:           0.7,
+	V2_CompareParts:             5,
+	V2_FixThreads:               3,
+	V2_MaxStartTimeDiffSD:       0.1,
+	V2_MinOffset:                0.1,
 })

+ 38 - 30
internal/types/sub_timeline_fiexer/sub_timeline_fixer_config.go

@@ -2,51 +2,59 @@ package sub_timeline_fiexer
 
 type SubTimelineFixerConfig struct {
 	// V1 的设置
-	MaxCompareDialogue int     // 最大需要匹配的连续对白,默认3
-	MaxStartTimeDiffSD float64 // 对白开始时间的统计 SD 最大误差,超过则不进行修正
-	MinMatchedPercent  float64 // 两个文件的匹配百分比(src/base),高于这个才比例进行修正
-	MinOffset          float64 // 超过这个(+-)偏移的时间轴才校正,否则跳过,单位秒
+	V1_MaxCompareDialogue int     // 最大需要匹配的连续对白,默认3
+	V1_MaxStartTimeDiffSD float64 // 对白开始时间的统计 SD 最大误差,超过则不进行修正
+	V1_MinMatchedPercent  float64 // 两个文件的匹配百分比(src/base),高于这个才比例进行修正
+	V1_MinOffset          float64 // 超过这个(+-)偏移的时间轴才校正,否则跳过,单位秒
 	// V2 的设置
-	SubOneUnitProcessTimeOut int     // 字幕时间轴校正一个单元的超时时间,单位秒
-	FrontAndEndPerBase       float64 // 前百分之 15 和后百分之 15 都不进行识别
-	FrontAndEndPerSrc        float64 // 前百分之 20 和后百分之 20 都不进行识别
-	WindowMatchPer           float64 // SrcSub 滑动窗体的占比
-	CompareParts             int     // 滑动窗体分段次数
-	FixThreads               int     // 字幕校正的并发线程
+	V2_SubOneUnitProcessTimeOut int     // 字幕时间轴校正一个单元的超时时间,单位秒
+	V2_FrontAndEndPerBase       float64 // 前百分之 15 和后百分之 15 都不进行识别
+	V2_FrontAndEndPerSrc        float64 // 前百分之 20 和后百分之 20 都不进行识别
+	V2_WindowMatchPer           float64 // SrcSub 滑动窗体的占比
+	V2_CompareParts             int     // 滑动窗体分段次数
+	V2_FixThreads               int     // 字幕校正的并发线程
+	V2_MaxStartTimeDiffSD       float64 // 对白开始时间的统计 SD 最大误差,超过则不进行修正
+	V2_MinOffset                float64 // 超过这个(+-)偏移的时间轴才校正,否则跳过,单位秒
 }
 
 // CheckDefault 检测默认值(比如某些之默认不能为0),不对就重置到默认值上
 func (s *SubTimelineFixerConfig) CheckDefault() {
 	// V1
-	if s.MaxCompareDialogue <= 0 {
-		s.MaxCompareDialogue = 3
+	if s.V1_MaxCompareDialogue <= 0 {
+		s.V1_MaxCompareDialogue = 3
 	}
-	if s.MaxStartTimeDiffSD <= 0 {
-		s.MaxStartTimeDiffSD = 0.1
+	if s.V1_MaxStartTimeDiffSD <= 0 {
+		s.V1_MaxStartTimeDiffSD = 0.1
 	}
-	if s.MinMatchedPercent <= 0 {
-		s.MinMatchedPercent = 0.1
+	if s.V1_MinMatchedPercent <= 0 {
+		s.V1_MinMatchedPercent = 0.1
 	}
-	if s.MinOffset <= 0 {
-		s.MinOffset = 0.1
+	if s.V1_MinOffset <= 0 {
+		s.V1_MinOffset = 0.1
 	}
 	// V2
-	if s.SubOneUnitProcessTimeOut <= 0 {
-		s.SubOneUnitProcessTimeOut = 30
+	if s.V2_SubOneUnitProcessTimeOut <= 0 {
+		s.V2_SubOneUnitProcessTimeOut = 30
 	}
-	if s.FrontAndEndPerBase <= 0 || s.FrontAndEndPerBase >= 1.0 {
-		s.FrontAndEndPerBase = 0.15
+	if s.V2_FrontAndEndPerBase <= 0 || s.V2_FrontAndEndPerBase >= 1.0 {
+		s.V2_FrontAndEndPerBase = 0.15
 	}
-	if s.FrontAndEndPerSrc <= 0 || s.FrontAndEndPerSrc >= 1.0 {
-		s.FrontAndEndPerSrc = 0.0
+	if s.V2_FrontAndEndPerSrc <= 0 || s.V2_FrontAndEndPerSrc >= 1.0 {
+		s.V2_FrontAndEndPerSrc = 0.0
 	}
-	if s.WindowMatchPer <= 0 || s.WindowMatchPer >= 1.0 {
-		s.WindowMatchPer = 0.7
+	if s.V2_WindowMatchPer <= 0 || s.V2_WindowMatchPer >= 1.0 {
+		s.V2_WindowMatchPer = 0.7
 	}
-	if s.CompareParts <= 0 {
-		s.CompareParts = 5
+	if s.V2_CompareParts <= 0 {
+		s.V2_CompareParts = 5
 	}
-	if s.CompareParts <= 0 {
-		s.CompareParts = 3
+	if s.V2_FixThreads <= 0 {
+		s.V2_FixThreads = 3
+	}
+	if s.V2_MaxStartTimeDiffSD <= 0 {
+		s.V2_MaxStartTimeDiffSD = 0.1
+	}
+	if s.V2_MinOffset <= 0 {
+		s.V2_MinOffset = 0.1
 	}
 }