فهرست منبع

新增测试代码,准备尝试判断视频与字幕是否匹配

Signed-off-by: allan716 <[email protected]>
allan716 3 سال پیش
والد
کامیت
9dd9173fd3

+ 134 - 0
TestCode/test_statistics_subs_score.go

@@ -0,0 +1,134 @@
+package TestCode
+
+import (
+	"fmt"
+	"os"
+	"path/filepath"
+
+	"github.com/allanpk716/ChineseSubFinder/pkg/types/subparser"
+	"github.com/huandu/go-clone"
+
+	"github.com/xuri/excelize/v2"
+
+	"github.com/allanpk716/ChineseSubFinder/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/pkg/logic/sub_parser/ass"
+	"github.com/allanpk716/ChineseSubFinder/pkg/logic/sub_parser/srt"
+	"github.com/allanpk716/ChineseSubFinder/pkg/logic/sub_timeline_fixer"
+	"github.com/allanpk716/ChineseSubFinder/pkg/settings"
+	"github.com/allanpk716/ChineseSubFinder/pkg/sub_parser_hub"
+	"github.com/allanpk716/ChineseSubFinder/pkg/vad"
+)
+
+func statistics_subs_score(baseAudioFileFPath, baseSubFileFPath, subSearchRootPath string) {
+
+	f := excelize.NewFile()
+	// Create a new sheet.
+	sheetName := filepath.Base(subSearchRootPath)
+	newSheet := f.NewSheet(sheetName)
+	err := f.SetCellValue(sheetName, fmt.Sprintf("A%d", 1), "SubFPath")
+	if err != nil {
+		return
+	}
+	err = f.SetCellValue(sheetName, fmt.Sprintf("B%d", 1), "Score")
+	if err != nil {
+		return
+	}
+	err = f.SetCellValue(sheetName, fmt.Sprintf("C%d", 1), "Offset")
+	if err != nil {
+		return
+	}
+
+	audioVADInfos, err := vad.GetVADInfoFromAudio(vad.AudioInfo{
+		FileFullPath: baseAudioFileFPath,
+		SampleRate:   16000,
+		BitDepth:     16,
+	}, true)
+	if err != nil {
+		return
+	}
+
+	subParserHub := sub_parser_hub.NewSubParserHub(
+		log_helper.GetLogger4Tester(),
+		ass.NewParser(log_helper.GetLogger4Tester()),
+		srt.NewParser(log_helper.GetLogger4Tester()),
+	)
+	bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(baseSubFileFPath)
+	if err != nil {
+		return
+	}
+	if bFind == false {
+		return
+	}
+
+	subCounter := 1
+	err = filepath.Walk(subSearchRootPath,
+		func(path string, info os.FileInfo, err error) error {
+			if err != nil {
+				return err
+			}
+
+			if info.IsDir() == true {
+				return nil
+			}
+			if sub_parser_hub.IsSubExtWanted(info.Name()) == false {
+				return nil
+			}
+
+			bFind, srcBase, err := subParserHub.DetermineFileTypeFromFile(path)
+			if err != nil {
+				return nil
+			}
+			if bFind == false {
+				return nil
+			}
+
+			s := sub_timeline_fixer.NewSubTimelineFixerHelperEx(log_helper.GetLogger4Tester(), *settings.NewTimelineFixerSettings())
+			// path X:\电影\21座桥 (2019)\21座桥 (2019) 720p AAC.chinese(简,subhd).ass
+			// 音频处理
+			cloneSrcBase := clone.Clone(srcBase).(*subparser.FileInfo)
+			bok, _, pipeResult, err := s.ProcessByAudioVAD(audioVADInfos, cloneSrcBase)
+			if err != nil {
+				return nil
+			}
+			if bok == false {
+				return nil
+			}
+			// 字幕处理
+			cloneSrcBase = clone.Clone(srcBase).(*subparser.FileInfo)
+			bok, _, pipeResult, err = s.ProcessBySubFileInfo(infoBase, cloneSrcBase)
+			if err != nil {
+				return nil
+			}
+			if bok == false {
+				return nil
+			}
+
+			subCounter++
+			err = f.SetCellValue(sheetName, fmt.Sprintf("A%d", subCounter+1), info.Name())
+			if err != nil {
+				return nil
+			}
+			err = f.SetCellValue(sheetName, fmt.Sprintf("B%d", subCounter+1), pipeResult.Score)
+			if err != nil {
+				return nil
+			}
+			err = f.SetCellValue(sheetName, fmt.Sprintf("C%d", subCounter+1), pipeResult.GetOffsetTime())
+			if err != nil {
+				return nil
+			}
+			fmt.Println(subCounter, path, info.Size())
+
+			return nil
+		})
+	if err != nil {
+		fmt.Println("Walk", err)
+		return
+	}
+
+	f.SetActiveSheet(newSheet)
+	err = f.SaveAs(fmt.Sprintf("%s.xlsx", filepath.Dir(baseSubFileFPath)))
+	if err != nil {
+		fmt.Println("SaveAs", err)
+		return
+	}
+}

+ 29 - 0
TestCode/test_statistics_subs_score_test.go

@@ -0,0 +1,29 @@
+package TestCode
+
+import "testing"
+
+func Test_statistics_subs_score(t *testing.T) {
+	type args struct {
+		baseAudioFileFPath string
+		baseSubFileFPath   string
+		subSearchRootPath  string
+	}
+	tests := []struct {
+		name string
+		args args
+	}{
+		{
+			name: "Test_statistics_subs_score",
+			args: args{
+				baseAudioFileFPath: "C:\\temp\\video\\base\\RM-S05E01\\未知语言_1.pcm",
+				baseSubFileFPath:   "C:\\temp\\video\\base\\RM-S05E01\\英_2.srt",
+				subSearchRootPath:  "X:\\电影",
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			statistics_subs_score(tt.args.baseAudioFileFPath, tt.args.baseSubFileFPath, tt.args.subSearchRootPath)
+		})
+	}
+}

+ 8 - 2
go.mod

@@ -54,8 +54,8 @@ require (
 	github.com/tidwall/gjson v1.9.4
 	github.com/ulikunitz/xz v0.5.10 // indirect
 	github.com/ysmood/gson v0.7.1 // indirect
-	golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
-	golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d
+	golang.org/x/crypto v0.0.0-20220408190544-5352b0902921
+	golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3
 	golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
 	golang.org/x/text v0.3.7
 	gonum.org/v1/gonum v0.9.3
@@ -116,9 +116,12 @@ require (
 	github.com/mitchellh/go-homedir v1.1.0 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
+	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
 	github.com/nwaples/rardecode v1.1.0 // indirect
 	github.com/pierrec/lz4/v4 v4.0.3 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
+	github.com/richardlehane/mscfb v1.0.4 // indirect
+	github.com/richardlehane/msoleps v1.0.1 // indirect
 	github.com/russross/blackfriday/v2 v2.1.0 // indirect
 	github.com/sergi/go-diff v1.2.0 // indirect
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
@@ -128,6 +131,9 @@ require (
 	github.com/ugorji/go/codec v1.2.6 // indirect
 	github.com/xanzy/ssh-agent v0.3.0 // indirect
 	github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
+	github.com/xuri/efp v0.0.0-20220407160117-ad0f7a785be8 // indirect
+	github.com/xuri/excelize/v2 v2.6.0 // indirect
+	github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
 	github.com/ysmood/goob v0.4.0 // indirect
 	github.com/ysmood/leakless v0.7.0 // indirect
 	go4.org v0.0.0-20200411211856-f5505b9728dd // indirect

+ 19 - 0
go.sum

@@ -426,6 +426,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
 github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
 github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
+github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
+github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
 github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
@@ -506,6 +508,10 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
 github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
 github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
+github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
+github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
+github.com/richardlehane/msoleps v1.0.1 h1:RfrALnSNXzmXLbGct/P2b4xkFz4e8Gmj/0Vj9M9xC1o=
+github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
 github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E=
 github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
@@ -609,6 +615,12 @@ github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6e
 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
+github.com/xuri/efp v0.0.0-20220407160117-ad0f7a785be8 h1:3X7aE0iLKJ5j+tz58BpvIZkXNV7Yq4jC93Z/rbN2Fxk=
+github.com/xuri/efp v0.0.0-20220407160117-ad0f7a785be8/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
+github.com/xuri/excelize/v2 v2.6.0 h1:m/aXAzSAqxgt74Nfd+sNzpzVKhTGl7+S9nbG4A57mF4=
+github.com/xuri/excelize/v2 v2.6.0/go.mod h1:Q1YetlHesXEKwGFfeJn7PfEZz2IvHb6wdOeYjBxVcVs=
+github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 h1:OAmKAfT06//esDdpi/DZ8Qsdt4+M5+ltca05dA5bG2M=
+github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
 github.com/ysmood/goob v0.4.0 h1:HsxXhyLBeGzWXnqVKtmT9qM7EuVs/XOgkX7T6r1o1AQ=
 github.com/ysmood/goob v0.4.0/go.mod h1:u6yx7ZhS4Exf2MwciFr6nIM8knHQIE22lFpWHnfql18=
 github.com/ysmood/got v0.29.1 h1:7TNTm3Bw5kdBGXFp04qnZ9DqlZ1XS1z1JdeobeJY6Mo=
@@ -667,6 +679,8 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
+golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 h1:iU7T1X1J6yxDr0rda54sWGkHgOp5XJrqm79gcNlC2VM=
+golang.org/x/crypto v0.0.0-20220408190544-5352b0902921/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -692,6 +706,7 @@ golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+o
 golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
 golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
 golang.org/x/image v0.0.0-20210216034530-4410531fe030/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
+golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
 golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
 golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
 golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -746,6 +761,8 @@ golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qx
 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d h1:1n1fc535VhN8SYtD4cDUyNlfpAF2ROMM9+11equK3hs=
 golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3 h1:EN5+DfgmRMvRUrMGERW2gQl3Vc+Z7ZMnI/xdEpPSf0c=
+golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -803,10 +820,12 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

+ 45 - 14
pkg/logic/sub_timeline_fixer/SubTimelineFixerHelperEx.go

@@ -111,7 +111,7 @@ func (s SubTimelineFixerHelperEx) Process(videoFileFullPath, srcSubFPath string)
 			s.log.Warnln("Can`t find audio info, skip time fix --", videoFileFullPath)
 			return nil
 		}
-		bProcess, infoSrc, pipeResultMax, err = s.processByAudio(ffmpegInfo.AudioInfoList[0].FullPath, srcSubFPath)
+		bProcess, infoSrc, pipeResultMax, err = s.ProcessByAudioFile(ffmpegInfo.AudioInfoList[0].FullPath, srcSubFPath)
 		if err != nil {
 			return err
 		}
@@ -130,7 +130,7 @@ func (s SubTimelineFixerHelperEx) Process(videoFileFullPath, srcSubFPath string)
 		}
 		_, index := fileSizes.Max()
 		baseSubFPath := ffmpegInfo.SubtitleInfoList[index.(int)].FullPath
-		bProcess, infoSrc, pipeResultMax, err = s.processBySub(baseSubFPath, srcSubFPath)
+		bProcess, infoSrc, pipeResultMax, err = s.ProcessBySubFile(baseSubFPath, srcSubFPath)
 		if err != nil {
 			return err
 		}
@@ -145,32 +145,51 @@ func (s SubTimelineFixerHelperEx) Process(videoFileFullPath, srcSubFPath string)
 	if err != nil {
 		return err
 	}
+	s.log.Infoln("TimeLine Fix -- Score:", pipeResultMax.Score, srcSubFPath)
 	s.log.Infoln("Fix Offset:", pipeResultMax.GetOffsetTime(), srcSubFPath)
 	s.log.Infoln("BackUp Org SubFile:", pipeResultMax.GetOffsetTime(), srcSubFPath+sub_timeline_fixer.BackUpExt)
 
 	return nil
 }
 
-func (s SubTimelineFixerHelperEx) processBySub(baseSubFileFPath, srcSubFileFPath string) (bool, *subparser.FileInfo, sub_timeline_fixer.PipeResult, error) {
+func (s SubTimelineFixerHelperEx) ProcessBySubFileInfo(infoBase *subparser.FileInfo, infoSrc *subparser.FileInfo) (bool, *subparser.FileInfo, sub_timeline_fixer.PipeResult, error) {
+
+	// ---------------------------------------------------------------------------------------
+	pipeResult, err := s.timelineFixPipeLine.CalcOffsetTime(infoBase, infoSrc, nil, false)
+	if err != nil {
+		return false, nil, sub_timeline_fixer.PipeResult{}, err
+	}
+
+	return true, infoSrc, pipeResult, nil
+}
+
+func (s SubTimelineFixerHelperEx) ProcessBySubFile(baseSubFileFPath, srcSubFileFPath string) (bool, *subparser.FileInfo, sub_timeline_fixer.PipeResult, error) {
 
 	bFind, infoBase, err := s.subParserHub.DetermineFileTypeFromFile(baseSubFileFPath)
 	if err != nil {
 		return false, nil, sub_timeline_fixer.PipeResult{}, err
 	}
 	if bFind == false {
-		s.log.Warnln("processBySub.DetermineFileTypeFromFile sub not match --", baseSubFileFPath)
+		s.log.Warnln("ProcessBySubFile.DetermineFileTypeFromFile sub not match --", baseSubFileFPath)
 		return false, nil, sub_timeline_fixer.PipeResult{}, nil
 	}
+
 	bFind, infoSrc, err := s.subParserHub.DetermineFileTypeFromFile(srcSubFileFPath)
 	if err != nil {
 		return false, nil, sub_timeline_fixer.PipeResult{}, err
 	}
 	if bFind == false {
-		s.log.Warnln("processBySub.DetermineFileTypeFromFile sub not match --", srcSubFileFPath)
+		s.log.Warnln("ProcessBySubFile.DetermineFileTypeFromFile sub not match --", srcSubFileFPath)
 		return false, nil, sub_timeline_fixer.PipeResult{}, nil
 	}
+
+	return s.ProcessBySubFileInfo(infoBase, infoSrc)
+}
+
+func (s SubTimelineFixerHelperEx) ProcessByAudioVAD(audioVADInfos []vad.VADInfo, infoSrc *subparser.FileInfo) (bool, *subparser.FileInfo, sub_timeline_fixer.PipeResult, error) {
+
 	// ---------------------------------------------------------------------------------------
-	pipeResult, err := s.timelineFixPipeLine.CalcOffsetTime(infoBase, infoSrc, nil, false)
+	pipeResult, err := s.timelineFixPipeLine.CalcOffsetTime(nil, infoSrc, audioVADInfos, false)
 	if err != nil {
 		return false, nil, sub_timeline_fixer.PipeResult{}, err
 	}
@@ -178,7 +197,7 @@ func (s SubTimelineFixerHelperEx) processBySub(baseSubFileFPath, srcSubFileFPath
 	return true, infoSrc, pipeResult, nil
 }
 
-func (s SubTimelineFixerHelperEx) processByAudio(baseAudioFileFPath, srcSubFileFPath string) (bool, *subparser.FileInfo, sub_timeline_fixer.PipeResult, error) {
+func (s SubTimelineFixerHelperEx) ProcessByAudioFile(baseAudioFileFPath, srcSubFileFPath string) (bool, *subparser.FileInfo, sub_timeline_fixer.PipeResult, error) {
 
 	audioVADInfos, err := vad.GetVADInfoFromAudio(vad.AudioInfo{
 		FileFullPath: baseAudioFileFPath,
@@ -194,16 +213,28 @@ func (s SubTimelineFixerHelperEx) processByAudio(baseAudioFileFPath, srcSubFileF
 		return false, nil, sub_timeline_fixer.PipeResult{}, err
 	}
 	if bFind == false {
-		s.log.Warnln("processByAudio.DetermineFileTypeFromFile sub not match --", srcSubFileFPath)
+		s.log.Warnln("ProcessByAudioFile.DetermineFileTypeFromFile sub not match --", srcSubFileFPath)
 		return false, nil, sub_timeline_fixer.PipeResult{}, nil
 	}
-	// ---------------------------------------------------------------------------------------
-	pipeResult, err := s.timelineFixPipeLine.CalcOffsetTime(nil, infoSrc, audioVADInfos, false)
-	if err != nil {
-		return false, nil, sub_timeline_fixer.PipeResult{}, err
-	}
 
-	return true, infoSrc, pipeResult, nil
+	return s.ProcessByAudioVAD(audioVADInfos, infoSrc)
+}
+
+func (s SubTimelineFixerHelperEx) IsMatchBySubFile(baseSubFileFPath, srcSubFileFPath string) (bool, error) {
+
+	//bProcess, _, pipeResultMax, err := s.ProcessBySubFile(baseSubFileFPath, srcSubFileFPath)
+	//if err != nil {
+	//	return false, fmt.Errorf("ProcessBySubFile error: %v", err)
+	//}
+	//if bProcess == false {
+	//	return false, nil
+	//}
+	return false, nil
+}
+
+func (s SubTimelineFixerHelperEx) IsMatchBySubFileInfo(infoBase *subparser.FileInfo, srcSubFileFPath string) (bool, error) {
+
+	return false, nil
 }
 
 func (s SubTimelineFixerHelperEx) changeTimeLineAndSave(infoSrc *subparser.FileInfo, pipeResult sub_timeline_fixer.PipeResult, desSubSaveFPath string) error {

+ 36 - 27
pkg/logic/sub_timeline_fixer/SubTimelineFixerHelperEx_test.go

@@ -2,6 +2,10 @@ package sub_timeline_fixer
 
 import (
 	"testing"
+
+	"github.com/allanpk716/ChineseSubFinder/pkg/log_helper"
+
+	"github.com/allanpk716/ChineseSubFinder/pkg/settings"
 )
 
 // TODO 暂不方便在其他环境进行单元测试
@@ -16,31 +20,36 @@ func TestSubTimelineFixerHelperEx_Check(t *testing.T) {
 func TestSubTimelineFixerHelperEx_Process(t *testing.T) {
 
 	//rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_timeline_fixer"}, 4, true)
-	//type args struct {
-	//	videoFileFullPath string
-	//	srcSubFPath       string
-	//}
-	//tests := []struct {
-	//	name    string
-	//	args    args
-	//	wantErr bool
-	//}{
-	//	{
-	//		name: "Foundation (2021) - S01E09", args: args{
-	//			videoFileFullPath: "X:\\连续剧\\Foundation (2021)\\Season 1\\Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p.mkv",
-	//			srcSubFPath:       filepath.Join(rootDir, "series", "Foundation (2021)", "Season 1", "Foundation (2021) - S01E09 - The First Crisis WEBDL-1080p.chinese(简英,zimuku).ass")},
-	//		wantErr: false,
-	//	},
-	//}
-	//
-	//s := NewSubTimelineFixerHelperEx(*settings.NewTimelineFixerSettings())
-	//s.Check()
-	//for _, tt := range tests {
-	//	t.Run(tt.name, func(t *testing.T) {
-	//
-	//		if err := s.Process(tt.args.videoFileFullPath, tt.args.srcSubFPath); (err != nil) != tt.wantErr {
-	//			t.Errorf("Process() error = %v, wantErr %v", err, tt.wantErr)
-	//		}
-	//	})
-	//}
+	type args struct {
+		videoFileFullPath string
+		srcSubFPath       string
+	}
+	tests := []struct {
+		name    string
+		args    args
+		wantErr bool
+	}{
+		{
+			name: "Foundation (2021) - S01E09", args: args{
+				//videoFileFullPath: "C:\\temp\\video\\瑞克和莫蒂 - S04E05 - Rick and Morty.mp4",
+				videoFileFullPath: "C:\\temp\\video\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv",
+				srcSubFPath:       "C:\\temp\\video\\瑞克和莫蒂 - S04E05 - Rick and Morty.chinese(简英,zimuku).org.ass"}, // Score,48281
+			//srcSubFPath: "C:\\temp\\video\\The Boys - S03E01 - Payback WEBRip-1080p.chinese(简英,subhd).ass"}, // Score,19796
+			//srcSubFPath: "C:\\temp\\video\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.chinese(简英,fix).srt"}, // Score,2
+			//srcSubFPath: "C:\\temp\\video\\Quo Vadis, Aida! (2021) Bluray-1080p.chinese(简,csf).default.srt"}, // Score,2
+			wantErr: false,
+		},
+	}
+
+	s := NewSubTimelineFixerHelperEx(log_helper.GetLogger4Tester(), *settings.NewTimelineFixerSettings())
+	s.Check()
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+
+			if err := s.Process(tt.args.videoFileFullPath, tt.args.srcSubFPath); (err != nil) != tt.wantErr {
+				t.Errorf("Process() error = %v, wantErr %v", err, tt.wantErr)
+			}
+		})
+	}
 }

+ 5 - 5
pkg/settings/timeline_fixer_settings.go

@@ -7,17 +7,17 @@ type TimelineFixerSettings struct {
 
 func NewTimelineFixerSettings() *TimelineFixerSettings {
 	return &TimelineFixerSettings{
-		MaxOffsetTime: 120,
-		MinOffset:     0.1,
+		MaxOffsetTime: 700,
+		MinOffset:     0.2,
 	}
 }
 
 func (t *TimelineFixerSettings) Check() {
-	if t.MaxOffsetTime <= 0 || t.MaxOffsetTime > 600 {
-		t.MaxOffsetTime = 60 // 60s
+	if t.MaxOffsetTime <= 0 || t.MaxOffsetTime > 700 {
+		t.MaxOffsetTime = 700 // 60s
 	}
 
 	if t.MinOffset <= 0 || t.MinOffset > 1 {
-		t.MinOffset = 0.1 // 100ms
+		t.MinOffset = 0.2 // 100ms
 	}
 }