Browse Source

修复,时间轴校正的细节问题

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

+ 1 - 1
internal/downloader.go

@@ -600,7 +600,7 @@ func (d Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSub
 
 // 在前面需要进行语言的筛选、排序,这里仅仅是存储, extraSubPreName 这里传递是字幕的网站,有就认为是多字幕的存储。空就是单字幕,单字幕就可以setDefault
 func (d Downloader) writeSubFile2VideoPath(videoFileFullPath string, finalSubFile subparser.FileInfo, extraSubPreName string, setDefault bool, skipExistFile bool) error {
-
+	defer d.log.Infoln("----------------------------------")
 	videoRootPath := filepath.Dir(videoFileFullPath)
 	subNewName, subNewNameWithDefault, _ := d.subFormatter.GenerateMixSubName(videoFileFullPath, finalSubFile.Ext, finalSubFile.Lang, extraSubPreName)
 

+ 6 - 4
internal/logic/sub_timeline_fixer/SubTimelineFixerHelperEx.go

@@ -170,7 +170,7 @@ func (s SubTimelineFixerHelperEx) processBySub(baseSubFileFPath, srcSubFileFPath
 		return false, nil, 0, err
 	}
 	if bok == false {
-		log_helper.GetLogger().Warnln("processSub.GetOffsetTimeV2 return false -- " + baseSubFileFPath)
+		log_helper.GetLogger().Warnln("processBySub.GetOffsetTimeV2 return false -- " + baseSubFileFPath)
 		return false, nil, 0, nil
 	}
 
@@ -211,7 +211,7 @@ func (s SubTimelineFixerHelperEx) processByAudio(baseAudioFileFPath, srcSubFileF
 		return false, nil, 0, err
 	}
 	if bok == false {
-		log_helper.GetLogger().Warnln("processSub.GetOffsetTimeV2 return false -- " + baseAudioFileFPath)
+		log_helper.GetLogger().Warnln("processByAudio.GetOffsetTimeV2 return false -- " + baseAudioFileFPath)
 		return false, nil, 0, nil
 	}
 
@@ -225,7 +225,7 @@ func (s SubTimelineFixerHelperEx) processByAudio(baseAudioFileFPath, srcSubFileF
 func (s SubTimelineFixerHelperEx) jugOffsetAndSD(processName string, offsetTime, sd float64) bool {
 	// SD 要达标
 	if sd > s.timelineFixer.FixerConfig.V2_MaxStartTimeDiffSD {
-		log_helper.GetLogger().Infoln(fmt.Sprintf("skip, %s sd: %v > %v", processName, sd, s.timelineFixer.FixerConfig.V2_MaxStartTimeDiffSD))
+		log_helper.GetLogger().Infoln(fmt.Sprintf("Skip, %s sd: %v > %v", processName, sd, s.timelineFixer.FixerConfig.V2_MaxStartTimeDiffSD))
 		return false
 	}
 	// 时间偏移的最小值才修正
@@ -237,7 +237,9 @@ func (s SubTimelineFixerHelperEx) jugOffsetAndSD(processName string, offsetTime,
 		return false
 	}
 	// sub_timeline_fixer.calcMeanAndSD 输出的可能的极小值
-	if offsetTime <= sub_timeline_fixer.MinValue+0.1 || offsetTime >= sub_timeline_fixer.MinValue-0.1 {
+
+	if my_util.IsEqual(offsetTime, sub_timeline_fixer.MinValue) == true {
+		log_helper.GetLogger().Infoln("Skip, offsetTime == -9999")
 		return false
 	}
 

+ 3 - 33
internal/logic/sub_timeline_fixer/SubTimelineFixerHelperEx_test.go

@@ -23,12 +23,6 @@ func TestSubTimelineFixerHelperEx_Process(t *testing.T) {
 		args    args
 		wantErr bool
 	}{
-		{
-			name: "R&M S05E01", args: args{
-				videoFileFullPath: "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv",
-				srcSubFPath:       "C:\\WorkSpace\\Go2Hell\\src\\github.com\\allanpk716\\ChineseSubFinder\\internal\\logic\\sub_timeline_fixer\\CSF-SubFixCache\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p\\R&M S05E01 - 简.ass"},
-			wantErr: false,
-		},
 		{
 			name: "Foundation (2021) - S01E09", args: args{
 				videoFileFullPath: "X:\\连续剧\\Foundation (2021)\\Season 1\\Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p.mkv",
@@ -36,33 +30,9 @@ func TestSubTimelineFixerHelperEx_Process(t *testing.T) {
 			wantErr: false,
 		},
 		{
-			name: "The Night House (2021)", args: args{
-				videoFileFullPath: "X:\\TestMovie\\The Night House (2021)\\The Night House (2021) Bluray-1080p.mkv",
-				srcSubFPath:       "X:\\TestMovie\\The Night House (2021)\\The Night House (2021) Bluray-1080p.chinese(简英,zimuku).ass"},
-			wantErr: false,
-		},
-		{
-			name: "龙猫 (1988)", args: args{
-				videoFileFullPath: "X:\\电影\\龙猫 (1988)\\龙猫 (1988) 1080p DTS.mkv",
-				srcSubFPath:       "X:\\电影\\龙猫 (1988)\\龙猫 (1988) 1080p DTS.chinese(简,zimuku).ass"},
-			wantErr: false,
-		},
-		{
-			name: "千与千寻 (2001)", args: args{
-				videoFileFullPath: "X:\\电影\\千与千寻 (2001)\\千与千寻 (2001) 1080p Opus.mkv",
-				srcSubFPath:       "X:\\电影\\千与千寻 (2001)\\千与千寻 (2001) 1080p Opus.chinese(简英,zimuku).ass"},
-			wantErr: false,
-		},
-		{
-			name: "Red Notice (2021)", args: args{
-				videoFileFullPath: "X:\\电影\\Red Notice (2021)\\Red Notice (2021) WEBRip-1080p.mp4",
-				srcSubFPath:       "X:\\电影\\Red Notice (2021)\\Red Notice (2021) WEBRip-1080p.chinese(简,xunlei).default.ass"},
-			wantErr: false,
-		},
-		{
-			name: "The Last Duel (2021)", args: args{
-				videoFileFullPath: "X:\\电影\\The Last Duel (2021)\\The Last Duel (2021) WEBRip-1080p.mp4",
-				srcSubFPath:       "X:\\电影\\The Last Duel (2021)\\The Last Duel (2021) WEBRip-1080p.chinese(简,shooter).default.srt"},
+			name: "Foundation (2021) - S01E09", args: args{
+				videoFileFullPath: "X:\\连续剧\\Foundation (2021)\\Season 1\\Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p.mkv",
+				srcSubFPath:       "C:\\WorkSpace\\Go2Hell\\src\\github.com\\allanpk716\\ChineseSubFinder\\internal\\logic\\sub_timeline_fixer\\CSF-SubFixCache\\Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p\\chinese(简英,zimuku).default.ass"},
 			wantErr: false,
 		},
 	}

+ 2 - 1
internal/pkg/emby_api/emby_api_test.go

@@ -58,7 +58,8 @@ func TestEmbyHelper_UpdateVideoSubList(t *testing.T) {
 	// 172412 -- Dan Brown's The Lost Symbol S01E01
 	// 194046 -- 窃贼军团
 	// 178071 -- The Night House
-	err := em.UpdateVideoSubList("145499")
+	// 215162 --  Black Lotus - S01E03
+	err := em.UpdateVideoSubList("215162")
 	if err != nil {
 		t.Fatal(err)
 	}

+ 2 - 1
internal/pkg/ffmpeg_helper/ffmpeg_helper_test.go

@@ -9,7 +9,8 @@ import (
 
 func TestGetFFMPEGInfo(t *testing.T) {
 	//videoFile := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E10 - Rickmurai Jack WEBRip-1080p.mkv"
-	videoFile := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv"
+	//videoFile := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv"
+	videoFile := "X:\\TestSeries\\Blade Runner - Black Lotus\\Season 1\\Blade Runner - Black Lotus - S01E03 - The Human Condition WEBDL-1080p.mkv"
 	//videoFile := "X:\\连续剧\\Foundation (2021)\\Season 1\\Foundation (2021) - S01E10 - The Leap WEBDL-1080p.mkv"
 
 	f := NewFFMPEGHelper()

+ 10 - 0
internal/pkg/my_util/util.go

@@ -447,3 +447,13 @@ func Time2SubTimeString(inTime time.Time, timeFormat string) string {
 		return outTimeString
 	}
 }
+
+// IsEqual 比较 float64
+func IsEqual(f1, f2 float64) bool {
+	const MIN = 0.000001
+	if f1 > f2 {
+		return math.Dim(f1, f2) < MIN
+	} else {
+		return math.Dim(f2, f1) < MIN
+	}
+}

+ 1 - 0
internal/pkg/sub_timeline_fixer/fixer.go

@@ -529,6 +529,7 @@ func (s *SubTimelineFixer) GetOffsetTimeV2(baseUnit, srcUnit *sub_helper.SubUnit
 	wg.Wait()
 	// 这里可能遇到匹配的时候没有能够执行够 V2_CompareParts 次,有可能是负数跳过或者时间转换失败导致,前者为主(可能是这两个就是一个东西的时候,或者说没有时间轴偏移的时候)
 	if insertIndex < s.FixerConfig.V2_CompareParts/2 {
+		log_helper.GetLogger().Infoln("Can't Match, Parts=", insertIndex, "At Least", s.FixerConfig.V2_CompareParts/2)
 		return false, 0, 0, nil
 	}
 	outCorrelationFixResult := s.calcMeanAndSD(tmpStartDiffTimeListEx, tmpStartDiffTimeList)

+ 21 - 75
internal/pkg/sub_timeline_fixer/fixer_test.go

@@ -563,6 +563,12 @@ func TestGetOffsetTimeV2_BaseSub(t *testing.T) {
 			srcSubFile:             filepath.Join(testRootDirNo, "What If…! - S01E09.chinese(简英,shooter).srt"),
 			staticLineFileSavePath: "bar.html"},
 			want: 0, wantErr: false},
+
+		{name: "What If…! - S01E09", args: args{
+			baseSubFile:            "C:\\WorkSpace\\Go2hell\\src\\github.com\\allanpk716\\ChineseSubFinder\\CSF-SubFixCache\\Blade Runner - Black Lotus - S01E03 - The Human Condition WEBDL-1080p\\英_2.ass",
+			srcSubFile:             "C:\\WorkSpace\\Go2hell\\src\\github.com\\allanpk716\\ChineseSubFinder\\CSF-SubFixCache\\Blade Runner - Black Lotus - S01E03 - The Human Condition WEBDL-1080p\\tar.ass",
+			staticLineFileSavePath: "bar.html"},
+			want: 0, wantErr: false},
 	}
 
 	for _, tt := range tests {
@@ -638,10 +644,10 @@ func TestGetOffsetTimeV2_BaseSub(t *testing.T) {
 			debug_view.SaveDebugChart(*srcUnitNew, tt.name+" -- srcUnitNew", "srcUnitNew")
 
 			//if bok == true && got != 0 {
-			//	_, err = timelineFixer.FixSubTimeline(infoSrc, got, tt.args.srcSubFile+FixMask+infoBase.Ext)
-			//	if err != nil {
-			//		t.Fatal(err)
-			//	}
+			_, err = timelineFixer.FixSubTimeline(infoSrc, got, tt.args.srcSubFile+FixMask+infoBase.Ext)
+			if err != nil {
+				t.Fatal(err)
+			}
 			//}
 			println(fmt.Sprintf("GetOffsetTimeV2: %fs SD:%f", got, sd))
 		})
@@ -675,67 +681,11 @@ func TestGetOffsetTimeV2_BaseAudio(t *testing.T) {
 				subFilePath: "C:\\Tmp\\Rick and Morty - S05E01\\英_2.ass"},
 			want: true, want1: 0,
 		},
-		{name: "Rick and Morty - S05E01 -- 1",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Rick and Morty - S05E01\\未知语言_1.pcm"},
-				subFilePath: "C:\\Tmp\\Rick and Morty - S05E01\\英_2.srt"},
-			want: true, want1: 0,
-		},
-		{name: "Rick and Morty - S05E01 -- 2",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Rick and Morty - S05E01\\未知语言_1.pcm"},
-				subFilePath: "C:\\Tmp\\Rick and Morty - S05E01\\R&M S05E01 - 简英.srt"},
-			want: true, want1: -6.1,
-		},
-		{name: "Rick and Morty - S05E01 -- 3",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Rick and Morty - S05E01\\未知语言_1.pcm"},
-				subFilePath: "C:\\Tmp\\Rick and Morty - S05E01\\R&M S05E01 - 简.ass"},
-			want: true, want1: -6.1,
-		},
-		// Rick and Morty - S05E10
-		{name: "Rick and Morty - S05E10 -- 0",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm"},
-				subFilePath: "C:\\Tmp\\Rick and Morty - S05E10\\英_2.ass"},
-			want: true, want1: 0,
-		},
-		{name: "Rick and Morty - S05E10 -- 1",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm"},
-				subFilePath: "C:\\Tmp\\Rick and Morty - S05E10\\英_2.srt"},
-			want: true, want1: 0,
-		},
-		{name: "Rick and Morty - S05E10 -- 2",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm"},
-				subFilePath: "C:\\Tmp\\Rick and Morty - S05E10\\R&M S05E10 - 简英.ass"},
-			want: true, want1: -6.0,
-		},
-		// Foundation - S01E09
-		{name: "Foundation - S01E09 -- 0",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Foundation - S01E09\\英_1.pcm"},
-				subFilePath: "C:\\Tmp\\Foundation - S01E09\\英_2.ass"},
-			want: true, want1: 0,
-		},
-		{name: "Foundation - S01E09 -- 1",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Foundation - S01E09\\英_1.pcm"},
-				subFilePath: "C:\\Tmp\\Foundation - S01E09\\简_6.srt"},
-			want: true, want1: 0,
-		},
-		{name: "Foundation - S01E09 -- 2",
-			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Foundation - S01E09\\英_1.pcm"},
-				subFilePath: "C:\\Tmp\\Foundation - S01E09\\chinese(简英,zimuku).default.ass"},
-			want: true, want1: -30,
-		},
-		{name: "Foundation - S01E09 -- 3",
+		{name: "Rick and Morty - S05E01 -- 0",
 			args: args{audioInfo: vad.AudioInfo{
-				FileFullPath: "C:\\Tmp\\Foundation - S01E09\\英_1.pcm"},
-				subFilePath: "C:\\Tmp\\Foundation - S01E09\\chinese(简英,zimuku-fix).ass"},
-			want: true, want1: 0,
+				FileFullPath: "C:\\WorkSpace\\Go2hell\\src\\github.com\\allanpk716\\ChineseSubFinder\\internal\\pkg\\ffmpeg_helper\\CSF-SubFixCache\\Blade Runner - Black Lotus - S01E03 - The Human Condition WEBDL-1080p\\日_1.pcm"},
+				subFilePath: "C:\\WorkSpace\\Go2hell\\src\\github.com\\allanpk716\\ChineseSubFinder\\CSF-SubFixCache\\Blade Runner - Black Lotus - S01E03 - The Human Condition WEBDL-1080p\\tar.ass"},
+			want: true, want1: -5.1,
 		},
 	}
 	for _, tt := range tests {
@@ -780,10 +730,6 @@ func TestGetOffsetTimeV2_BaseAudio(t *testing.T) {
 				t.Errorf("GetOffsetTimeV2() bok = %v, want %v", bok, tt.want)
 			}
 
-			if sd > timelineFixer.FixerConfig.V2_MaxStartTimeDiffSD {
-
-			}
-
 			if offsetTime > -0.2 && offsetTime < 0.2 && tt.want1 == 0 {
 				// 如果 offset time > -0.2 且 < 0.2 则认为无需调整时间轴,为0
 			} else if offsetTime > tt.want1-0.1 && offsetTime < tt.want1+0.1 {
@@ -792,10 +738,10 @@ func TestGetOffsetTimeV2_BaseAudio(t *testing.T) {
 				t.Errorf("GetOffsetTimeV2() bok = %v, want %v", offsetTime, tt.want1)
 			}
 
-			//_, err = timelineFixer.FixSubTimeline(infoSrc, offsetTime, tt.args.subFilePath+FixMask+infoSrc.Ext)
-			//if err != nil {
-			//	t.Fatal(err)
-			//}
+			_, err = timelineFixer.FixSubTimeline(infoSrc, offsetTime, tt.args.subFilePath+FixMask+infoSrc.Ext)
+			if err != nil {
+				t.Fatal(err)
+			}
 
 			println(fmt.Sprintf("GetOffsetTimeV2: %vs SD:%v", offsetTime, sd))
 		})
@@ -810,10 +756,10 @@ var timelineFixer = NewSubTimelineFixer(sub_timeline_fiexer.SubTimelineFixerConf
 	V1_MinOffset:          0.1,
 	// V2
 	V2_SubOneUnitProcessTimeOut: 5 * 60,
-	V2_FrontAndEndPerBase:       0.15,
+	V2_FrontAndEndPerBase:       0.0,
 	V2_FrontAndEndPerSrc:        0.0,
-	V2_WindowMatchPer:           0.7,
-	V2_CompareParts:             5,
+	V2_WindowMatchPer:           0.8,
+	V2_CompareParts:             8,
 	V2_FixThreads:               3,
 	V2_MaxStartTimeDiffSD:       0.1,
 	V2_MinOffset:                0.2,