Pārlūkot izejas kodu

调整设置的细节

Signed-off-by: allan716 <[email protected]>
allan716 4 gadi atpakaļ
vecāks
revīzija
195c894ff1

+ 2 - 2
internal/logic/sub_timeline_fixer/sub_timeline_fixer_helper_test.go

@@ -8,7 +8,7 @@ import (
 func TestSubTimelineFixerHelper_FixRecentlyItemsSubTimeline(t *testing.T) {
 	// 单独执行这个,第一次是有效的,第二次,就没得效果了,原因是已经替换字幕了啊,当然就不会修正了啊。你懂的
 	config := pkg.GetConfig()
-	fixer := NewSubTimelineFixerHelper(config.EmbyConfig)
+	fixer := NewSubTimelineFixerHelper(config.EmbyConfig, config.SubTimelineFixerConfig)
 	err := fixer.FixRecentlyItemsSubTimeline(config.MovieFolder, config.SeriesFolder)
 	if err != nil {
 		t.Fatal(err)
@@ -23,7 +23,7 @@ func TestSubTimelineFixerHelper_fixOneVideoSub(t *testing.T) {
 	// 81873 -- R&M - S05E01
 	// 145499 -- R&M - S05E10
 	config := pkg.GetConfig()
-	fixer := NewSubTimelineFixerHelper(config.EmbyConfig)
+	fixer := NewSubTimelineFixerHelper(config.EmbyConfig, config.SubTimelineFixerConfig)
 	err := fixer.fixOneVideoSub("173354", "")
 	if err != nil {
 		t.Fatal(err)

+ 3 - 0
internal/pkg/config.go

@@ -23,6 +23,9 @@ func GetConfig() *types.Config {
 		for _, customExt := range strings.Split(config.CustomVideoExts, ",") {
 			customVideoExts = append(customVideoExts, "."+customExt)
 		}
+
+		// 这里进行 Default 值的判断
+		config.SubTimelineFixerConfig.CheckDefault()
 	})
 	return config
 }

+ 1 - 3
internal/pkg/sub_timeline_fixer/fixer_test.go

@@ -126,7 +126,7 @@ func TestGetOffsetTime(t *testing.T) {
 			staticLineFileSavePath: "bar.html"},
 			want: 0, wantErr: false},
 		/*
-			只有一个是字幕下载了一个错误的,其他的无需修正
+			基地
 		*/
 		{name: "Foundation (2021) - S01E01", args: args{
 			enSubFile:              path.Join(testRootDirNo, "Foundation (2021) - S01E01.chinese(inside).ass"),
@@ -271,5 +271,3 @@ func TestTFIDF(t *testing.T) {
 	fmt.Printf("Matched '%s'", testCorpus[matched])
 	// Output: Matched 'The quick brown fox jumped over the lazy dog'
 }
-
-const tmpSubDataFolderName = "SubFixCache"

+ 17 - 1
internal/types/sub_timeline_fiexer/sub_timeline_fixer_config.go

@@ -3,6 +3,22 @@ package sub_timeline_fiexer
 type SubTimelineFixerConfig struct {
 	MaxCompareDialogue int     // 最大需要匹配的连续对白,默认5
 	MaxStartTimeDiffSD float64 // 对白开始时间的统计 SD 最大误差,超过则不进行修正
-	MinMatchedPercent  float64 // 两个文件的匹配百分比(src/base),低于这个部进行修正
+	MinMatchedPercent  float64 // 两个文件的匹配百分比(src/base),高于这个才比例进行修正
 	MinOffset          float64 // 超过这个(+-)偏移的时间轴才校正,否则跳过,单位秒
 }
+
+// CheckDefault 检测默认值(比如某些之默认不能为0),不对就重置到默认值上
+func (s *SubTimelineFixerConfig) CheckDefault() {
+	if s.MaxCompareDialogue == 0 {
+		s.MaxCompareDialogue = 5
+	}
+	if s.MaxStartTimeDiffSD == 0 {
+		s.MaxStartTimeDiffSD = 0.1
+	}
+	if s.MinMatchedPercent == 0 {
+		s.MinMatchedPercent = 0.1
+	}
+	if s.MinOffset == 0 {
+		s.MinOffset = 0.1
+	}
+}