1
0

SubTimelineFixerHelperEx_test.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package sub_timeline_fixer
  2. import (
  3. "testing"
  4. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/log_helper"
  5. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/settings"
  6. )
  7. // TODO 暂不方便在其他环境进行单元测试
  8. func TestSubTimelineFixerHelperEx_Check(t *testing.T) {
  9. //if NewSubTimelineFixerHelperEx(config.GetConfig().SubTimelineFixerConfig).Check() == false {
  10. // t.Fatal("Need Install FFMPEG")
  11. //}
  12. }
  13. // TODO 暂不方便在其他环境进行单元测试
  14. func TestSubTimelineFixerHelperEx_Process(t *testing.T) {
  15. //rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_timeline_fixer"}, 4, true)
  16. type args struct {
  17. videoFileFullPath string
  18. srcSubFPath string
  19. }
  20. tests := []struct {
  21. name string
  22. args args
  23. wantErr bool
  24. }{
  25. {
  26. name: "Foundation (2021) - S01E09", args: args{
  27. //videoFileFullPath: "C:\\temp\\video\\瑞克和莫蒂 - S04E05 - Rick and Morty.mp4",
  28. videoFileFullPath: "C:\\temp\\video\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv",
  29. srcSubFPath: "C:\\temp\\video\\瑞克和莫蒂 - S04E05 - Rick and Morty.chinese(简英,zimuku).org.ass"}, // Score,48281
  30. //srcSubFPath: "C:\\temp\\video\\The Boys - S03E01 - Payback WEBRip-1080p.chinese(简英,subhd).ass"}, // Score,19796
  31. //srcSubFPath: "C:\\temp\\video\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.chinese(简英,fix).srt"}, // Score,2
  32. //srcSubFPath: "C:\\temp\\video\\Quo Vadis, Aida! (2021) Bluray-1080p.chinese(简,csf).default.srt"}, // Score,2
  33. wantErr: false,
  34. },
  35. }
  36. s := NewSubTimelineFixerHelperEx(log_helper.GetLogger4Tester(), *settings.NewTimelineFixerSettings())
  37. s.Check()
  38. for _, tt := range tests {
  39. t.Run(tt.name, func(t *testing.T) {
  40. if err := s.Process(tt.args.videoFileFullPath, tt.args.srcSubFPath); (err != nil) != tt.wantErr {
  41. t.Errorf("Process() error = %v, wantErr %v", err, tt.wantErr)
  42. }
  43. })
  44. }
  45. }
  46. func TestSubTimelineFixerHelperEx_IsMatchBySubFile(t *testing.T) {
  47. videoFPath := "C:\\temp\\video\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv"
  48. NowTargetSubFPath := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.chinese(简,subhd).ass"
  49. logger := log_helper.GetLogger4Tester()
  50. s := NewSubTimelineFixerHelperEx(logger, *settings.NewTimelineFixerSettings())
  51. bok, ffmpegInfo, audioVADInfos, infoBase, err := s.IsVideoCanExportSubtitleAndAudio(videoFPath)
  52. if err != nil {
  53. logger.Errorln("IsVideoCanExportSubtitleAndAudio", err)
  54. return
  55. }
  56. if bok == false {
  57. logger.Errorln("IsVideoCanExportSubtitleAndAudio", "bok == false")
  58. return
  59. }
  60. bok, matchResult, err := s.IsMatchBySubFile(
  61. ffmpegInfo,
  62. audioVADInfos,
  63. infoBase,
  64. NowTargetSubFPath,
  65. CompareConfig{
  66. MinScore: 40000,
  67. OffsetRange: 2,
  68. DialoguesDifferencePercentage: 0.25,
  69. })
  70. if err != nil {
  71. logger.Errorln("IsMatchBySubFile", err)
  72. return
  73. }
  74. if bok == false && matchResult == nil {
  75. return
  76. }
  77. }