fixer_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. package sub_timeline_fixer
  2. import (
  3. "fmt"
  4. "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
  5. "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
  6. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  7. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
  8. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
  9. "github.com/allanpk716/ChineseSubFinder/internal/pkg/vad"
  10. "github.com/allanpk716/ChineseSubFinder/internal/types/sub_timeline_fiexer"
  11. "github.com/james-bowman/nlp"
  12. "github.com/james-bowman/nlp/measures/pairwise"
  13. "gonum.org/v1/gonum/mat"
  14. "path/filepath"
  15. "strings"
  16. "testing"
  17. )
  18. func TestStopWordCounter(t *testing.T) {
  19. testDataPath := "../../../TestData/FixTimeline"
  20. testRootDir, err := my_util.CopyTestData(testDataPath)
  21. if err != nil {
  22. t.Fatal(err)
  23. }
  24. subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
  25. bFind, info, err := subParserHub.DetermineFileTypeFromFile(filepath.Join(testRootDir, "R&M S05E10 - English.srt"))
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. if bFind == false {
  30. t.Fatal("not match sub types")
  31. }
  32. allString := strings.Join(info.OtherLines, " ")
  33. s := SubTimelineFixer{}
  34. stopWords := s.StopWordCounter(strings.ToLower(allString), 5)
  35. print(len(stopWords))
  36. println(info.Name)
  37. }
  38. func TestGetOffsetTimeV1(t *testing.T) {
  39. testDataPath := "../../../TestData/FixTimeline"
  40. testRootDir, err := my_util.CopyTestData(testDataPath)
  41. if err != nil {
  42. t.Fatal(err)
  43. }
  44. testRootDirYes := filepath.Join(testRootDir, "yes")
  45. testRootDirNo := filepath.Join(testRootDir, "no")
  46. subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
  47. type args struct {
  48. enSubFile string
  49. ch_enSubFile string
  50. staticLineFileSavePath string
  51. }
  52. tests := []struct {
  53. name string
  54. args args
  55. want float64
  56. wantErr bool
  57. }{
  58. /*
  59. 这里有几个比较理想的字幕时间轴校正的示例
  60. */
  61. {name: "R&M S05E01", args: args{enSubFile: filepath.Join(testRootDirYes, "R&M S05E01 - English.srt"),
  62. ch_enSubFile: filepath.Join(testRootDirYes, "R&M S05E01 - 简英.srt"),
  63. staticLineFileSavePath: "bar.html"}, want: -6.42981818181818, wantErr: false},
  64. {name: "R&M S05E10", args: args{enSubFile: filepath.Join(testRootDirYes, "R&M S05E10 - English.ass"),
  65. ch_enSubFile: filepath.Join(testRootDirYes, "R&M S05E10 - 简英.ass"),
  66. staticLineFileSavePath: "bar.html"}, want: -6.335985401459854, wantErr: false},
  67. {name: "基地 S01E03", args: args{enSubFile: filepath.Join(testRootDirYes, "基地 S01E03 - English.ass"),
  68. ch_enSubFile: filepath.Join(testRootDirYes, "基地 S01E03 - 简英.ass"),
  69. staticLineFileSavePath: "bar.html"}, want: -32.09061538461539, wantErr: false},
  70. /*
  71. WTF,这部剧集
  72. Dan Brown's The Lost Symbol
  73. 内置的英文字幕时间轴是歪的,所以修正完了就错了
  74. */
  75. {name: "Dan Brown's The Lost Symbol - S01E01", args: args{
  76. enSubFile: filepath.Join(testRootDirNo, "Dan Brown's The Lost Symbol - S01E01.chinese(inside).ass"),
  77. ch_enSubFile: filepath.Join(testRootDirNo, "Dan Brown's The Lost Symbol - S01E01.chinese(简英,shooter).ass"),
  78. staticLineFileSavePath: "bar.html"},
  79. want: 1.3217821782178225, wantErr: false},
  80. {name: "Dan Brown's The Lost Symbol - S01E02", args: args{
  81. enSubFile: filepath.Join(testRootDirNo, "Dan Brown's The Lost Symbol - S01E02.chinese(inside).ass"),
  82. ch_enSubFile: filepath.Join(testRootDirNo, "Dan Brown's The Lost Symbol - S01E02.chinese(简英,subhd).ass"),
  83. staticLineFileSavePath: "bar.html"},
  84. want: -0.5253383458646617, wantErr: false},
  85. {name: "Dan Brown's The Lost Symbol - S01E03", args: args{
  86. enSubFile: filepath.Join(testRootDirNo, "Dan Brown's The Lost Symbol - S01E03.chinese(inside).ass"),
  87. ch_enSubFile: filepath.Join(testRootDirNo, "Dan Brown's The Lost Symbol - S01E03.chinese(繁英,xunlei).ass"),
  88. staticLineFileSavePath: "bar.html"},
  89. want: -0.505656, wantErr: false},
  90. {name: "Dan Brown's The Lost Symbol - S01E04", args: args{
  91. enSubFile: filepath.Join(testRootDirNo, "Dan Brown's The Lost Symbol - S01E04.chinese(inside).ass"),
  92. ch_enSubFile: filepath.Join(testRootDirNo, "Dan Brown's The Lost Symbol - S01E04.chinese(简英,zimuku).ass"),
  93. staticLineFileSavePath: "bar.html"},
  94. want: -0.633415, wantErr: false},
  95. /*
  96. 只有一个是字幕下载了一个错误的,其他的无需修正
  97. */
  98. {name: "Don't Breathe 2 (2021) - shooter-srt", args: args{
  99. enSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(inside).srt"),
  100. ch_enSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(简英,shooter).srt"),
  101. staticLineFileSavePath: "bar.html"},
  102. want: 0, wantErr: false},
  103. {name: "Don't Breathe 2 (2021) - subhd-srt error matched sub", args: args{
  104. enSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(inside).srt"),
  105. ch_enSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(简英,subhd).srt"),
  106. staticLineFileSavePath: "bar.html"},
  107. want: 0, wantErr: false},
  108. {name: "Don't Breathe 2 (2021) - xunlei-ass", args: args{
  109. enSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(inside).ass"),
  110. ch_enSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(简英,xunlei).ass"),
  111. staticLineFileSavePath: "bar.html"},
  112. want: 0, wantErr: false},
  113. {name: "Don't Breathe 2 (2021) - zimuku-ass", args: args{
  114. enSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(inside).ass"),
  115. ch_enSubFile: filepath.Join(testRootDirNo, "Don't Breathe 2 (2021).chinese(简英,zimuku).ass"),
  116. staticLineFileSavePath: "bar.html"},
  117. want: 0, wantErr: false},
  118. /*
  119. 基地
  120. */
  121. {name: "Foundation (2021) - S01E01", args: args{
  122. enSubFile: filepath.Join(testRootDirNo, "Foundation (2021) - S01E01.chinese(inside).ass"),
  123. ch_enSubFile: filepath.Join(testRootDirNo, "Foundation (2021) - S01E01.chinese(简英,zimuku).ass"),
  124. staticLineFileSavePath: "bar.html"},
  125. want: 0, wantErr: false},
  126. {name: "Foundation (2021) - S01E02", args: args{
  127. enSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E02.chinese(inside).ass"),
  128. ch_enSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E02.chinese(简英,subhd).ass"),
  129. staticLineFileSavePath: "bar.html"},
  130. want: -30.624840, wantErr: false},
  131. {name: "Foundation (2021) - S01E03", args: args{
  132. enSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E03.chinese(inside).ass"),
  133. ch_enSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E03.chinese(简英,subhd).ass"),
  134. staticLineFileSavePath: "bar.html"},
  135. want: -32.085037037037054, wantErr: false},
  136. {name: "Foundation (2021) - S01E04", args: args{
  137. enSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E04.chinese(inside).ass"),
  138. ch_enSubFile: filepath.Join(testRootDirYes, "Foundation (2021) - S01E04.chinese(简英,subhd).ass"),
  139. staticLineFileSavePath: "bar.html"},
  140. want: -36.885074, wantErr: false},
  141. {name: "Foundation (2021) - S01E04", args: args{
  142. enSubFile: filepath.Join(testRootDirNo, "Foundation (2021) - S01E04.chinese(inside).srt"),
  143. ch_enSubFile: filepath.Join(testRootDirNo, "Foundation (2021) - S01E04.chinese(繁英,shooter).srt"),
  144. staticLineFileSavePath: "bar.html"},
  145. want: 0, wantErr: false},
  146. /*
  147. The Card Counter
  148. */
  149. {name: "The Card Counter", args: args{
  150. enSubFile: filepath.Join(testRootDirNo, "The Card Counter (2021).chinese(inside).ass"),
  151. ch_enSubFile: filepath.Join(testRootDirNo, "The Card Counter (2021).chinese(简英,xunlei).ass"),
  152. staticLineFileSavePath: "bar.html"},
  153. want: 0, wantErr: false},
  154. {name: "The Card Counter", args: args{
  155. enSubFile: filepath.Join(testRootDirNo, "The Card Counter (2021).chinese(inside).ass"),
  156. ch_enSubFile: filepath.Join(testRootDirNo, "The Card Counter (2021).chinese(简英,shooter).ass"),
  157. staticLineFileSavePath: "bar.html"},
  158. want: 0.224844, wantErr: false},
  159. /*
  160. Kingdom Ashin of the North
  161. */
  162. {name: "Kingdom Ashin of the North - error matched sub", args: args{
  163. enSubFile: filepath.Join(testRootDirNo, "Kingdom Ashin of the North (2021).chinese(inside).ass"),
  164. ch_enSubFile: filepath.Join(testRootDirNo, "Kingdom Ashin of the North (2021).chinese(简英,subhd).ass"),
  165. staticLineFileSavePath: "bar.html"},
  166. want: 0, wantErr: false},
  167. /*
  168. Only Murders in the Building
  169. */
  170. {name: "Only Murders in the Building - S01E06", args: args{
  171. enSubFile: filepath.Join(testRootDirNo, "Only Murders in the Building - S01E06.chinese(inside).ass"),
  172. ch_enSubFile: filepath.Join(testRootDirNo, "Only Murders in the Building - S01E06.chinese(简英,subhd).ass"),
  173. staticLineFileSavePath: "bar.html"},
  174. want: 0, wantErr: false},
  175. {name: "Only Murders in the Building - S01E08", args: args{
  176. enSubFile: filepath.Join(testRootDirNo, "Only Murders in the Building - S01E08.chinese(inside).ass"),
  177. ch_enSubFile: filepath.Join(testRootDirNo, "Only Murders in the Building - S01E08.chinese(简英,subhd).ass"),
  178. staticLineFileSavePath: "bar.html"},
  179. want: 0, wantErr: false},
  180. /*
  181. Ted Lasso
  182. */
  183. {name: "Ted Lasso - S02E09", args: args{
  184. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E09.chinese(inside).ass"),
  185. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E09.chinese(简英,subhd).ass"),
  186. staticLineFileSavePath: "bar.html"},
  187. want: 0, wantErr: false},
  188. {name: "Ted Lasso - S02E09", args: args{
  189. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E09.chinese(inside).ass"),
  190. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E09.chinese(简英,zimuku).ass"),
  191. staticLineFileSavePath: "bar.html"},
  192. want: 0, wantErr: false},
  193. {name: "Ted Lasso - S02E10", args: args{
  194. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(inside).ass"),
  195. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(简英,subhd).ass"),
  196. staticLineFileSavePath: "bar.html"},
  197. want: 0, wantErr: false},
  198. {name: "Ted Lasso - S02E10", args: args{
  199. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(inside).ass"),
  200. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(简英,zimuku).ass"),
  201. staticLineFileSavePath: "bar.html"},
  202. want: 0, wantErr: false},
  203. {name: "Ted Lasso - S02E10", args: args{
  204. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(inside).ass"),
  205. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E10.chinese(简英,shooter).ass"),
  206. staticLineFileSavePath: "bar.html"},
  207. want: 0, wantErr: false},
  208. {name: "Ted Lasso - S02E11", args: args{
  209. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E11.chinese(inside).ass"),
  210. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E11.chinese(简英,subhd).ass"),
  211. staticLineFileSavePath: "bar.html"},
  212. want: 0, wantErr: false},
  213. {name: "Ted Lasso - S02E11", args: args{
  214. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E11.chinese(inside).ass"),
  215. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E11.chinese(简英,zimuku).ass"),
  216. staticLineFileSavePath: "bar.html"},
  217. want: 0, wantErr: false},
  218. {name: "Ted Lasso - S02E12", args: args{
  219. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E12.chinese(inside).ass"),
  220. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E12.chinese(简英,subhd).ass"),
  221. staticLineFileSavePath: "bar.html"},
  222. want: 0, wantErr: false},
  223. {name: "Ted Lasso - S02E12", args: args{
  224. enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E12.chinese(inside).ass"),
  225. ch_enSubFile: filepath.Join(testRootDirNo, "Ted Lasso - S02E12.chinese(简英,shooter).ass"),
  226. staticLineFileSavePath: "bar.html"},
  227. want: 0, wantErr: false},
  228. /*
  229. The Protégé
  230. */
  231. {name: "The Protégé", args: args{
  232. enSubFile: filepath.Join(testRootDirNo, "The Protégé (2021).chinese(inside).ass"),
  233. ch_enSubFile: filepath.Join(testRootDirNo, "The Protégé (2021).chinese(简英,zimuku).ass"),
  234. staticLineFileSavePath: "bar.html"},
  235. want: 0, wantErr: false},
  236. {name: "The Protégé", args: args{
  237. enSubFile: filepath.Join(testRootDirNo, "The Protégé (2021).chinese(inside).srt"),
  238. ch_enSubFile: filepath.Join(testRootDirNo, "The Protégé (2021).chinese(简英,shooter).srt"),
  239. staticLineFileSavePath: "bar.html"},
  240. want: 0, wantErr: false},
  241. /*
  242. The Witcher Nightmare of the Wolf
  243. */
  244. {name: "The Witcher Nightmare of the Wolf", args: args{
  245. enSubFile: filepath.Join(testRootDirNo, "The Witcher Nightmare of the Wolf.chinese(inside).ass"),
  246. ch_enSubFile: filepath.Join(testRootDirNo, "The Witcher Nightmare of the Wolf.chinese(简英,zimuku).ass"),
  247. staticLineFileSavePath: "bar.html"},
  248. want: 0, wantErr: false},
  249. /*
  250. What If…!
  251. */
  252. {name: "What If…! - S01E07", args: args{
  253. enSubFile: filepath.Join(testRootDirNo, "What If…! - S01E07.chinese(inside).ass"),
  254. ch_enSubFile: filepath.Join(testRootDirNo, "What If…! - S01E07.chinese(简英,subhd).ass"),
  255. staticLineFileSavePath: "bar.html"},
  256. want: 0, wantErr: false},
  257. {name: "What If…! - S01E09", args: args{
  258. enSubFile: filepath.Join(testRootDirNo, "What If…! - S01E09.chinese(inside).srt"),
  259. ch_enSubFile: filepath.Join(testRootDirNo, "What If…! - S01E09.chinese(简英,shooter).srt"),
  260. staticLineFileSavePath: "bar.html"},
  261. want: 0, wantErr: false},
  262. }
  263. s := NewSubTimelineFixer(sub_timeline_fiexer.SubTimelineFixerConfig{
  264. MaxCompareDialogue: 3,
  265. MaxStartTimeDiffSD: 0.1,
  266. MinMatchedPercent: 0.1,
  267. MinOffset: 0.1,
  268. })
  269. for _, tt := range tests {
  270. t.Run(tt.name, func(t *testing.T) {
  271. bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(tt.args.enSubFile)
  272. if err != nil {
  273. t.Fatal(err)
  274. }
  275. if bFind == false {
  276. t.Fatal("sub not match")
  277. }
  278. /*
  279. 这里发现一个梗,内置的英文字幕导出的时候,有可能需要合并多个 Dialogue,见
  280. internal/pkg/sub_helper/sub_helper.go 中 MergeMultiDialogue4EngSubtitle 的实现
  281. */
  282. sub_helper.MergeMultiDialogue4EngSubtitle(infoBase)
  283. bFind, infoSrc, err := subParserHub.DetermineFileTypeFromFile(tt.args.ch_enSubFile)
  284. if err != nil {
  285. t.Fatal(err)
  286. }
  287. if bFind == false {
  288. t.Fatal("sub not match")
  289. }
  290. /*
  291. 这里发现一个梗,内置的英文字幕导出的时候,有可能需要合并多个 Dialogue,见
  292. internal/pkg/sub_helper/sub_helper.go 中 MergeMultiDialogue4EngSubtitle 的实现
  293. */
  294. sub_helper.MergeMultiDialogue4EngSubtitle(infoSrc)
  295. bok, got, sd, err := s.GetOffsetTimeV1(infoBase, infoSrc, tt.args.ch_enSubFile+"-bar.html", tt.args.ch_enSubFile+".log")
  296. if (err != nil) != tt.wantErr {
  297. t.Errorf("GetOffsetTimeV1() error = %v, wantErr %v", err, tt.wantErr)
  298. return
  299. }
  300. // 在一个正负范围内都可以接受
  301. if got > tt.want-0.1 && got < tt.want+0.1 {
  302. } else {
  303. t.Errorf("GetOffsetTimeV1() got = %v, want %v", got, tt.want)
  304. }
  305. //if got != tt.want {
  306. // t.Errorf("GetOffsetTimeV1() got = %v, want %v", got, tt.want)
  307. //}
  308. if bok == true && got != 0 {
  309. _, err = s.FixSubTimeline(infoSrc, got, tt.args.ch_enSubFile+FixMask+infoBase.Ext)
  310. if err != nil {
  311. t.Fatal(err)
  312. }
  313. }
  314. println(fmt.Sprintf("GetOffsetTimeV1: %fs SD:%f", got, sd))
  315. })
  316. }
  317. }
  318. func TestTFIDF(t *testing.T) {
  319. testCorpus := []string{
  320. "The quick brown fox jumped over the lazy dog",
  321. "hey diddle diddle, the cat and the fiddle",
  322. "the cow jumped over the moon",
  323. "the little dog laughed to see such fun",
  324. "and the dish ran away with the spoon",
  325. }
  326. query := "the brown fox ran around the dog"
  327. vectoriser := nlp.NewCountVectoriser(StopWords...)
  328. transformer := nlp.NewTfidfTransformer()
  329. // set k (the number of dimensions following truncation) to 4
  330. reducer := nlp.NewTruncatedSVD(4)
  331. lsiPipeline := nlp.NewPipeline(vectoriser, transformer, reducer)
  332. // Transform the corpus into an LSI fitting the model to the documents in the process
  333. lsi, err := lsiPipeline.FitTransform(testCorpus...)
  334. if err != nil {
  335. fmt.Printf("Failed to process documents because %v", err)
  336. return
  337. }
  338. // run the query through the same pipeline that was fitted to the corpus and
  339. // to project it into the same dimensional space
  340. queryVector, err := lsiPipeline.Transform(query)
  341. if err != nil {
  342. fmt.Printf("Failed to process documents because %v", err)
  343. return
  344. }
  345. // iterate over document feature vectors (columns) in the LSI matrix and compare
  346. // with the query vector for similarity. Similarity is determined by the difference
  347. // between the angles of the vectors known as the cosine similarity
  348. highestSimilarity := -1.0
  349. var matched int
  350. _, docs := lsi.Dims()
  351. for i := 0; i < docs; i++ {
  352. similarity := pairwise.CosineSimilarity(queryVector.(mat.ColViewer).ColView(0), lsi.(mat.ColViewer).ColView(i))
  353. if similarity > highestSimilarity {
  354. matched = i
  355. highestSimilarity = similarity
  356. }
  357. }
  358. fmt.Printf("Matched '%s'", testCorpus[matched])
  359. // Output: Matched 'The quick brown fox jumped over the lazy dog'
  360. }
  361. func TestSubTimelineFixer_GetOffsetTimeV2(t *testing.T) {
  362. subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
  363. type fields struct {
  364. fixerConfig sub_timeline_fiexer.SubTimelineFixerConfig
  365. }
  366. type args struct {
  367. audioInfo vad.AudioInfo
  368. subFilePath string
  369. staticLineFileSavePath string
  370. debugInfoFileSavePath string
  371. }
  372. tests := []struct {
  373. name string
  374. fields fields
  375. args args
  376. want bool
  377. want1 float64
  378. want2 float64
  379. wantErr bool
  380. }{
  381. {name: "Rick and Morty - S05E10", args: args{audioInfo: vad.AudioInfo{FileFullPath: "C:\\Tmp\\Rick and Morty - S05E10\\英_1.pcm"}, subFilePath: "C:\\Tmp\\Rick and Morty - S05E10\\英_2.ass"}},
  382. }
  383. for _, tt := range tests {
  384. t.Run(tt.name, func(t *testing.T) {
  385. s := &SubTimelineFixer{
  386. fixerConfig: tt.fields.fixerConfig,
  387. }
  388. bok, fileInfo, err := subParserHub.DetermineFileTypeFromFile(tt.args.subFilePath)
  389. if err != nil {
  390. t.Fatal(err)
  391. }
  392. if bok == false {
  393. t.Fatal("DetermineFileTypeFromFile == false")
  394. }
  395. /*
  396. 这里发现一个梗,内置的英文字幕导出的时候,有可能需要合并多个 Dialogue,见
  397. internal/pkg/sub_helper/sub_helper.go 中 MergeMultiDialogue4EngSubtitle 的实现
  398. */
  399. sub_helper.MergeMultiDialogue4EngSubtitle(fileInfo)
  400. got, got1, got2, err := s.GetOffsetTimeV2(tt.args.audioInfo, fileInfo, tt.args.staticLineFileSavePath, tt.args.debugInfoFileSavePath)
  401. if (err != nil) != tt.wantErr {
  402. t.Errorf("GetOffsetTimeV2() error = %v, wantErr %v", err, tt.wantErr)
  403. return
  404. }
  405. if got != tt.want {
  406. t.Errorf("GetOffsetTimeV2() got = %v, want %v", got, tt.want)
  407. }
  408. if got1 != tt.want1 {
  409. t.Errorf("GetOffsetTimeV2() got1 = %v, want %v", got1, tt.want1)
  410. }
  411. if got2 != tt.want2 {
  412. t.Errorf("GetOffsetTimeV2() got2 = %v, want %v", got2, tt.want2)
  413. }
  414. })
  415. }
  416. }