|
|
@@ -4,10 +4,9 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
|
|
|
- "github.com/allanpk716/ChineseSubFinder/internal/pkg/debug_view"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
|
|
|
- "github.com/allanpk716/ChineseSubFinder/internal/pkg/vad"
|
|
|
+ "github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
|
|
|
"github.com/allanpk716/ChineseSubFinder/internal/types/sub_timeline_fiexer"
|
|
|
"github.com/james-bowman/nlp"
|
|
|
"github.com/james-bowman/nlp/measures/pairwise"
|
|
|
@@ -19,11 +18,9 @@ import (
|
|
|
|
|
|
func TestStopWordCounter(t *testing.T) {
|
|
|
|
|
|
- testRootDir := filepath.FromSlash("../../../TestData/FixTimeline")
|
|
|
-
|
|
|
+ testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"FixTimeline"}, 4, false)
|
|
|
subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
|
|
|
-
|
|
|
- bFind, info, err := subParserHub.DetermineFileTypeFromFile(filepath.Join(testRootDir, "yes", "R&M S05E01 - English.srt"))
|
|
|
+ bFind, info, err := subParserHub.DetermineFileTypeFromFile(filepath.Join(testRootDir, "org", "yes", "R&M S05E01 - English.srt"))
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
@@ -92,7 +89,8 @@ func TestTFIDF(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestGetOffsetTimeV1(t *testing.T) {
|
|
|
- testRootDir := filepath.FromSlash("../../../TestData/FixTimeline")
|
|
|
+
|
|
|
+ testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"FixTimeline"}, 4, true)
|
|
|
|
|
|
testRootDirYes := filepath.Join(testRootDir, "yes")
|
|
|
testRootDirNo := filepath.Join(testRootDir, "no")
|
|
|
@@ -372,523 +370,6 @@ func TestGetOffsetTimeV1(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestGetOffsetTimeV2_BaseSub(t *testing.T) {
|
|
|
- testRootDir := filepath.FromSlash("../../../TestData/FixTimeline")
|
|
|
-
|
|
|
- testRootDirYes := filepath.Join(testRootDir, "yes")
|
|
|
- testRootDirNo := filepath.Join(testRootDir, "no")
|
|
|
- subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
|
|
|
-
|
|
|
- type args struct {
|
|
|
- baseSubFile string
|
|
|
- srcSubFile string
|
|
|
- staticLineFileSavePath string
|
|
|
- }
|
|
|
- tests := []struct {
|
|
|
- name string
|
|
|
- args args
|
|
|
- want float64
|
|
|
- wantErr bool
|
|
|
- }{
|
|
|
- /*
|
|
|
- 这里有几个比较理想的字幕时间轴校正的示例
|
|
|
- */
|
|
|
- {name: "R&M S05E01", args: args{baseSubFile: filepath.Join(testRootDirYes, "R&M S05E01 - English.srt"),
|
|
|
- srcSubFile: filepath.Join(testRootDirYes, "R&M S05E01 - 简英.srt"),
|
|
|
- staticLineFileSavePath: "bar.html"}, want: -6.4, wantErr: false},
|
|
|
- {name: "R&M S05E01-1", args: args{baseSubFile: filepath.Join(testRootDirYes, "R&M S05E01 - English.srt"),
|
|
|
- srcSubFile: filepath.Join(testRootDirYes, "R&M S05E01 - English.srt"),
|
|
|
- staticLineFileSavePath: "bar.html"}, want: 0, wantErr: false},
|
|
|
-
|
|
|
- {name: "R&M S05E10-0", args: args{baseSubFile: filepath.Join(testRootDirYes, "R&M S05E10 - English.ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirYes, "R&M S05E10 - 简英.ass"),
|
|
|
- staticLineFileSavePath: "bar.html"}, want: -6.405985401459854, wantErr: false},
|
|
|
-
|
|
|
- {name: "R&M S05E10-1", args: args{baseSubFile: filepath.Join(testRootDirYes, "R&M S05E10 - 简英.ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirYes, "R&M S05E10 - English.ass"),
|
|
|
- staticLineFileSavePath: "bar.html"}, want: 6.405985401459854, wantErr: false},
|
|
|
- {name: "R&M S05E10-2", args: args{baseSubFile: filepath.Join(testRootDirYes, "R&M S05E10 - 简英.ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirYes, "R&M S05E10 - 简英.ass"),
|
|
|
- staticLineFileSavePath: "bar.html"}, want: 0, wantErr: false},
|
|
|
- /*
|
|
|
- 基地
|
|
|
- */
|
|
|
- {name: "Foundation (2021) - S01E01", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Foundation (2021) - S01E01.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Foundation (2021) - S01E01.chinese(简英,zimuku).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Foundation (2021) - S01E02", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E02.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E02.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: -30.624840, wantErr: false},
|
|
|
- {name: "Foundation (2021) - S01E03", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E03.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E03.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: -32.085037037037054, wantErr: false},
|
|
|
- {name: "Foundation (2021) - S01E04", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E04.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E04.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: -36.885074, wantErr: false},
|
|
|
- {name: "Foundation (2021) - S01E04", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Foundation (2021) - S01E04.chinese(inside).srt"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Foundation (2021) - S01E04.chinese(繁英,shooter).srt"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- /*
|
|
|
- Don't Breathe 2 (2021)
|
|
|
- */
|
|
|
- {name: "Don't Breathe 2 (2021) - zimuku-ass", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(简英,zimuku).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Don't Breathe 2 (2021) - shooter-srt", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(inside).srt"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(简英,shooter).srt"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- /*
|
|
|
- Only Murders in the Building
|
|
|
- */
|
|
|
- {name: "Only Murders in the Building - S01E06", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Only Murders in the Building - S01E06.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Only Murders in the Building - S01E06.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Only Murders in the Building - S01E08", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Only Murders in the Building - S01E08.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Only Murders in the Building - S01E08.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- /*
|
|
|
- Ted Lasso
|
|
|
- */
|
|
|
- {name: "Ted Lasso - S02E09", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E09.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E09.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Ted Lasso - S02E09", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E09.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E09.chinese(简英,zimuku).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Ted Lasso - S02E10", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Ted Lasso - S02E10", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(简英,zimuku).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Ted Lasso - S02E10", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(简英,shooter).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Ted Lasso - S02E11", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E11.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E11.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Ted Lasso - S02E11", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E11.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E11.chinese(简英,zimuku).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Ted Lasso - S02E12", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E12.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E12.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "Ted Lasso - S02E12", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E12.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E12.chinese(简英,shooter).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- /*
|
|
|
- The Protégé
|
|
|
- */
|
|
|
- {name: "The Protégé", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "The Protégé (2021).chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "The Protégé (2021).chinese(简英,zimuku).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "The Protégé", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "The Protégé (2021).chinese(inside).srt"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "The Protégé (2021).chinese(简英,shooter).srt"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- /*
|
|
|
- The Witcher Nightmare of the Wolf
|
|
|
- */
|
|
|
- {name: "The Witcher Nightmare of the Wolf", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "The Witcher Nightmare of the Wolf.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "The Witcher Nightmare of the Wolf.chinese(简英,zimuku).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- /*
|
|
|
- What If…!
|
|
|
- */
|
|
|
- {name: "What If…! - S01E01", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "What If…! - S01E01_英_2.srt"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "What If…! - S01E01 - (简英,shooter).srt"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "What If…! - S01E07", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "What If…! - S01E07.chinese(inside).ass"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "What If…! - S01E07.chinese(简英,subhd).ass"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- {name: "What If…! - S01E09", args: args{
|
|
|
- baseSubFile: filepath.Join(testRootDirNo, "What If…! - S01E09.chinese(inside).srt"),
|
|
|
- srcSubFile: filepath.Join(testRootDirNo, "What If…! - S01E09.chinese(简英,shooter).srt"),
|
|
|
- staticLineFileSavePath: "bar.html"},
|
|
|
- want: 0, wantErr: false},
|
|
|
- }
|
|
|
-
|
|
|
- for _, tt := range tests {
|
|
|
- t.Run(tt.name, func(t *testing.T) {
|
|
|
-
|
|
|
- bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(tt.args.baseSubFile)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if bFind == false {
|
|
|
- t.Fatal("sub not match")
|
|
|
- }
|
|
|
- /*
|
|
|
- 这里发现一个梗,内置的英文字幕导出的时候,有可能需要合并多个 Dialogue,见
|
|
|
- internal/pkg/sub_helper/sub_helper.go 中 MergeMultiDialogue4EngSubtitle 的实现
|
|
|
- */
|
|
|
- //sub_helper.MergeMultiDialogue4EngSubtitle(infoBase)
|
|
|
-
|
|
|
- bFind, infoSrc, err := subParserHub.DetermineFileTypeFromFile(tt.args.srcSubFile)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if bFind == false {
|
|
|
- t.Fatal("sub not match")
|
|
|
- }
|
|
|
- /*
|
|
|
- 这里发现一个梗,内置的英文字幕导出的时候,有可能需要合并多个 Dialogue,见
|
|
|
- internal/pkg/sub_helper/sub_helper.go 中 MergeMultiDialogue4EngSubtitle 的实现
|
|
|
- */
|
|
|
- //sub_helper.MergeMultiDialogue4EngSubtitle(infoSrc)
|
|
|
- // ---------------------------------------------------------------------------------------
|
|
|
- // Base,截取的部分要大于 Src 的部分
|
|
|
- //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.V2_FrontAndEndPerBase)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- // ---------------------------------------------------------------------------------------
|
|
|
- // Src,截取的部分要小于 Base 的部分
|
|
|
- //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.V2_FrontAndEndPerSrc)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- // ---------------------------------------------------------------------------------------
|
|
|
- //bok, got, sd, err := timelineFixer.GetOffsetTimeV2(&baseUnitOld, &srcUnitOld, nil, 0)
|
|
|
- bok, _, err := timelineFixer.GetOffsetTimeV2(baseUnitNew, srcUnitNew, nil)
|
|
|
- if (err != nil) != tt.wantErr {
|
|
|
- t.Errorf("GetOffsetTimeV2() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
- return
|
|
|
- }
|
|
|
- if bok == false {
|
|
|
- t.Fatal("GetOffsetTimeV2 return false")
|
|
|
- }
|
|
|
-
|
|
|
- //if got > -0.2 && got < 0.2 && tt.want == 0 {
|
|
|
- // // 如果 offset time > -0.2 且 < 0.2 则认为无需调整时间轴,为0
|
|
|
- //} else if got > tt.want-0.1 && got < tt.want+0.1 {
|
|
|
- // // 在一个正负范围内都可以接受
|
|
|
- //} else {
|
|
|
- // t.Errorf("GetOffsetTimeV2() got = %v, want %v", got, tt.want)
|
|
|
- //}
|
|
|
-
|
|
|
- debug_view.SaveDebugChart(*baseUnitNew, tt.name+" -- baseUnitNew", "baseUnitNew")
|
|
|
- debug_view.SaveDebugChart(*srcUnitNew, tt.name+" -- srcUnitNew", "srcUnitNew")
|
|
|
-
|
|
|
- //if bok == true && got != 0 {
|
|
|
- //_, err = timelineFixer.FixSubTimelineOneOffsetTime(infoSrc, got, tt.args.srcSubFile+FixMask+infoBase.Ext)
|
|
|
- //if err != nil {
|
|
|
- // t.Fatal(err)
|
|
|
- //}
|
|
|
- ////}
|
|
|
- //println(fmt.Sprintf("GetOffsetTimeV2: %fs SD:%f", got, sd))
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestGetOffsetTimeV2_BaseAudio(t *testing.T) {
|
|
|
-
|
|
|
- subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
|
|
|
-
|
|
|
- type fields struct {
|
|
|
- fixerConfig sub_timeline_fiexer.SubTimelineFixerConfig
|
|
|
- }
|
|
|
- type args struct {
|
|
|
- audioInfo vad.AudioInfo
|
|
|
- subFilePath string
|
|
|
- }
|
|
|
- tests := []struct {
|
|
|
- name string
|
|
|
- fields fields
|
|
|
- args args
|
|
|
- want bool
|
|
|
- want1 float64
|
|
|
- want2 float64
|
|
|
- wantErr bool
|
|
|
- }{
|
|
|
- // Rick and Morty - S05E01
|
|
|
- {name: "Rick and Morty - S05E01 -- 0",
|
|
|
- args: args{audioInfo: vad.AudioInfo{
|
|
|
- FileFullPath: "C:\\Tmp\\Rick and Morty - S05E01\\未知语言_1.pcm"},
|
|
|
- subFilePath: "C:\\Tmp\\Rick and Morty - S05E01\\英_2.ass"},
|
|
|
- want: true, want1: 0,
|
|
|
- },
|
|
|
- {name: "Rick and Morty - S05E01 -- 0",
|
|
|
- args: args{audioInfo: vad.AudioInfo{
|
|
|
- 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 {
|
|
|
- t.Run(tt.name, func(t *testing.T) {
|
|
|
-
|
|
|
- bFind, infoSrc, err := subParserHub.DetermineFileTypeFromFile(tt.args.subFilePath)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if bFind == false {
|
|
|
- t.Fatal("sub not match")
|
|
|
- }
|
|
|
- /*
|
|
|
- 这里发现一个梗,内置的英文字幕导出的时候,有可能需要合并多个 Dialogue,见
|
|
|
- internal/pkg/sub_helper/sub_helper.go 中 MergeMultiDialogue4EngSubtitle 的实现
|
|
|
- */
|
|
|
- //sub_helper.MergeMultiDialogue4EngSubtitle(infoSrc)
|
|
|
- // Src,截取的部分要小于 Base 的部分
|
|
|
- srcUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoSrc, timelineFixer.FixerConfig.V2_FrontAndEndPerSrc)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- audioVADInfos, err := vad.GetVADInfoFromAudio(vad.AudioInfo{
|
|
|
- FileFullPath: tt.args.audioInfo.FileFullPath,
|
|
|
- SampleRate: 16000,
|
|
|
- BitDepth: 16,
|
|
|
- }, true)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- println("-------New--------")
|
|
|
- bok, _, err := timelineFixer.GetOffsetTimeV2(nil, srcUnitNew, audioVADInfos)
|
|
|
- if (err != nil) != tt.wantErr {
|
|
|
- t.Errorf("GetOffsetTimeV2() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- //debug_view.SaveDebugChartBase(audioVADInfos, tt.name+" audioVADInfos", "audioVADInfos")
|
|
|
- //debug_view.SaveDebugChart(*srcUnitNew, tt.name+" srcUnitNew", "srcUnitNew")
|
|
|
- if bok != tt.want {
|
|
|
- t.Errorf("GetOffsetTimeV2() bok = %v, want %v", bok, tt.want)
|
|
|
- }
|
|
|
-
|
|
|
- //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 {
|
|
|
- // // 在一个正负范围内都可以接受
|
|
|
- //} else {
|
|
|
- // t.Errorf("GetOffsetTimeV2() bok = %v, want %v", offsetTime, tt.want1)
|
|
|
- //}
|
|
|
-
|
|
|
- //_, err = timelineFixer.FixSubTimelineOneOffsetTime(infoSrc, offsetTime, tt.args.subFilePath+FixMask+infoSrc.Ext)
|
|
|
- //if err != nil {
|
|
|
- // t.Fatal(err)
|
|
|
- //}
|
|
|
-
|
|
|
- //println(fmt.Sprintf("GetOffsetTimeV2: %vs SD:%v", offsetTime, sd))
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestGetOffsetTimeV2_MoreTest(t *testing.T) {
|
|
|
- subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
|
|
|
-
|
|
|
- type args struct {
|
|
|
- baseSubFile string
|
|
|
- srcSubFile string
|
|
|
- }
|
|
|
- tests := []struct {
|
|
|
- name string
|
|
|
- args args
|
|
|
- want float64
|
|
|
- wantErr bool
|
|
|
- }{
|
|
|
- {name: "BL S01E03", args: args{
|
|
|
- baseSubFile: "C:\\Tmp\\BL - S01E03\\英_2.ass",
|
|
|
- srcSubFile: "C:\\Tmp\\BL - S01E03\\org.ass",
|
|
|
- }, want: -4.1, wantErr: false},
|
|
|
- {name: "Rick and Morty - S05E10", args: args{
|
|
|
- baseSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\英_2.ass",
|
|
|
- srcSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\org.ass",
|
|
|
- }, want: -4.1, wantErr: false},
|
|
|
- {name: "mix", args: args{
|
|
|
- baseSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\英_2.ass",
|
|
|
- srcSubFile: "C:\\Tmp\\BL - S01E03\\org.ass",
|
|
|
- }, want: -4.1, wantErr: false},
|
|
|
- }
|
|
|
-
|
|
|
- for _, tt := range tests {
|
|
|
- t.Run(tt.name, func(t *testing.T) {
|
|
|
-
|
|
|
- bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(tt.args.baseSubFile)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if bFind == false {
|
|
|
- t.Fatal("sub not match")
|
|
|
- }
|
|
|
-
|
|
|
- bFind, infoSrc, err := subParserHub.DetermineFileTypeFromFile(tt.args.srcSubFile)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if bFind == false {
|
|
|
- t.Fatal("sub not match")
|
|
|
- }
|
|
|
- // ---------------------------------------------------------------------------------------
|
|
|
- // Base,截取的部分要大于 Src 的部分
|
|
|
- baseUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoBase, timelineFixer.FixerConfig.V2_FrontAndEndPerBase)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- // ---------------------------------------------------------------------------------------
|
|
|
- // Src,截取的部分要小于 Base 的部分
|
|
|
- srcUnitNew, err := sub_helper.GetVADInfoFeatureFromSubNew(infoSrc, timelineFixer.FixerConfig.V2_FrontAndEndPerSrc)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- // ---------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- //bok, got, sd, err := timelineFixer.GetOffsetTimeV1(infoBase, infoSrc, tt.args.srcSubFile+"-bar.html", tt.args.srcSubFile+".log")
|
|
|
- //if (err != nil) != tt.wantErr {
|
|
|
- // t.Errorf("GetOffsetTimeV1() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
- // return
|
|
|
- //}
|
|
|
- bok, fixedResults, err := timelineFixer.GetOffsetTimeV2(baseUnitNew, srcUnitNew, nil)
|
|
|
- if (err != nil) != tt.wantErr {
|
|
|
- t.Errorf("GetOffsetTimeV2() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
- return
|
|
|
- }
|
|
|
- if bok == false {
|
|
|
- t.Fatal("GetOffsetTimeV2 return false")
|
|
|
- }
|
|
|
-
|
|
|
- //debug_view.SaveDebugChart(*baseUnitNew, tt.name+" -- baseUnitNew", "baseUnitNew")
|
|
|
- //debug_view.SaveDebugChart(*srcUnitNew, tt.name+" -- srcUnitNew", "srcUnitNew")
|
|
|
-
|
|
|
- println("baseUnitNew:", fmt.Sprintf("%f", baseUnitNew.GetStartTimeNumber(true)))
|
|
|
- println("srcUnitNew:", fmt.Sprintf("%f", srcUnitNew.GetStartTimeNumber(true)))
|
|
|
-
|
|
|
- _, err = timelineFixer.FixSubTimelineByFixResults(infoSrc, srcUnitNew, fixedResults, tt.args.srcSubFile+FixMask+infoBase.Ext)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func TestGetOffsetTimeV3_MoreTest(t *testing.T) {
|
|
|
- subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
|
|
|
-
|
|
|
- type args struct {
|
|
|
- baseSubFile string
|
|
|
- orgFixSubFile string
|
|
|
- srcSubFile string
|
|
|
- }
|
|
|
- tests := []struct {
|
|
|
- name string
|
|
|
- args args
|
|
|
- want float64
|
|
|
- wantErr bool
|
|
|
- }{
|
|
|
- {name: "BL S01E03", args: args{
|
|
|
- baseSubFile: "C:\\Tmp\\BL - S01E03\\英_2.ass",
|
|
|
- orgFixSubFile: "C:\\Tmp\\BL - S01E03\\org-fix.ass",
|
|
|
- srcSubFile: "C:\\Tmp\\BL - S01E03\\org.ass",
|
|
|
- }, want: -4.1, wantErr: false},
|
|
|
- {name: "Rick and Morty - S05E10", args: args{
|
|
|
- baseSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\英_2.ass",
|
|
|
- orgFixSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\org-fix.ass",
|
|
|
- srcSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\org.ass",
|
|
|
- }, want: -4.1, wantErr: false},
|
|
|
- {name: "Foundation - S01E09", args: args{
|
|
|
- baseSubFile: "C:\\Tmp\\Foundation - S01E09\\英_2.ass",
|
|
|
- orgFixSubFile: "C:\\Tmp\\Foundation - S01E09\\org-fix.ass",
|
|
|
- srcSubFile: "C:\\Tmp\\Foundation - S01E09\\org.ass",
|
|
|
- }, want: -4.1, wantErr: false},
|
|
|
- {name: "mix", args: args{
|
|
|
- baseSubFile: "C:\\Tmp\\Rick and Morty - S05E10\\英_2.ass",
|
|
|
- srcSubFile: "C:\\Tmp\\BL - S01E03\\org.ass",
|
|
|
- }, want: -4.1, wantErr: false},
|
|
|
- }
|
|
|
-
|
|
|
- for _, tt := range tests {
|
|
|
- t.Run(tt.name, func(t *testing.T) {
|
|
|
-
|
|
|
- bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(tt.args.baseSubFile)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if bFind == false {
|
|
|
- t.Fatal("sub not match")
|
|
|
- }
|
|
|
-
|
|
|
- bFind, infoSrc, err := subParserHub.DetermineFileTypeFromFile(tt.args.srcSubFile)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if bFind == false {
|
|
|
- t.Fatal("sub not match")
|
|
|
- }
|
|
|
-
|
|
|
- bFind, orgFix, err := subParserHub.DetermineFileTypeFromFile(tt.args.orgFixSubFile)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- if bFind == false {
|
|
|
- t.Fatal("sub not match")
|
|
|
- }
|
|
|
- // ---------------------------------------------------------------------------------------
|
|
|
- err = timelineFixer.GetOffsetTimeV3(infoBase, infoSrc, orgFix, nil)
|
|
|
- if (err != nil) != tt.wantErr {
|
|
|
- t.Errorf("GetOffsetTimeV3() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
- return
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
var timelineFixer = NewSubTimelineFixer(sub_timeline_fiexer.SubTimelineFixerConfig{
|
|
|
// V1
|
|
|
V1_MaxCompareDialogue: 3,
|
|
|
@@ -901,7 +382,7 @@ var timelineFixer = NewSubTimelineFixer(sub_timeline_fiexer.SubTimelineFixerConf
|
|
|
V2_FrontAndEndPerSrc: 0.2,
|
|
|
V2_WindowMatchPer: 0.2,
|
|
|
V2_CompareParts: 3,
|
|
|
- V2_FixThreads: 1,
|
|
|
+ V2_FixThreads: 2,
|
|
|
V2_MaxStartTimeDiffSD: 0.1,
|
|
|
V2_MinOffset: 0.2,
|
|
|
})
|