sub_helper_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package sub_helper
  2. import (
  3. "fmt"
  4. "github.com/allanpk716/ChineseSubFinder/pkg"
  5. "path/filepath"
  6. "testing"
  7. "github.com/allanpk716/ChineseSubFinder/pkg/log_helper"
  8. "github.com/allanpk716/ChineseSubFinder/pkg/logic/sub_parser/ass"
  9. "github.com/allanpk716/ChineseSubFinder/pkg/logic/sub_parser/srt"
  10. "github.com/allanpk716/ChineseSubFinder/pkg/my_util"
  11. "github.com/allanpk716/ChineseSubFinder/pkg/sub_parser_hub"
  12. "github.com/allanpk716/ChineseSubFinder/pkg/unit_test_helper"
  13. )
  14. func TestDeleteOneSeasonSubCacheFolder(t *testing.T) {
  15. const testSerName = "XXX"
  16. const needDelFolderName = "Sub_S1E0"
  17. testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_helper", "org", needDelFolderName}, 4, false)
  18. desSerFullPath, err := pkg.GetDebugFolderByName([]string{testSerName})
  19. if err != nil {
  20. t.Fatal(err)
  21. }
  22. desSeasonFullPath, err := pkg.GetDebugFolderByName([]string{testSerName, filepath.Base(testRootDir)})
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. err = my_util.CopyDir(testRootDir, desSeasonFullPath)
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. err = DeleteOneSeasonSubCacheFolder(desSerFullPath)
  31. if err != nil {
  32. t.Fatal(err)
  33. }
  34. if my_util.IsDir(desSeasonFullPath) == true {
  35. t.Fatal("Sub_S1E0 not delete")
  36. }
  37. }
  38. func TestGetVADInfosFromSub(t *testing.T) {
  39. log := log_helper.GetLogger4Tester()
  40. // 这两个字幕是一样的,只不过是格式不同而已
  41. subParserHub := sub_parser_hub.NewSubParserHub(log, ass.NewParser(log), srt.NewParser(log))
  42. testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_helper", "org", "R&M-S05E10"}, 4, false)
  43. baseSubFile := filepath.Join(testRootDir, "Rick and Morty - S05E10 - Rickmurai Jack WEBRip-1080p.chinese(简,zimuku).default.srt")
  44. srcSubFile := filepath.Join(testRootDir, "Rick and Morty - S05E10 - Rickmurai Jack WEBRip-1080p.chinese(简英,zimuku).ass")
  45. bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(baseSubFile)
  46. if err != nil {
  47. t.Fatal(err)
  48. }
  49. if bFind == false {
  50. t.Fatal("sub not match")
  51. }
  52. bFind, infoSrc, err := subParserHub.DetermineFileTypeFromFile(srcSubFile)
  53. if err != nil {
  54. t.Fatal(err)
  55. }
  56. if bFind == false {
  57. t.Fatal("sub not match")
  58. }
  59. if len(infoBase.Dialogues) != len(infoSrc.Dialogues) {
  60. t.Fatal(fmt.Sprintf("info Base And Src Parse Error, infoBase.DialoguesFilterEx Len = %v, infoSrc.DialoguesFilterEx Len = %v",
  61. len(infoBase.Dialogues), len(infoSrc.Dialogues)))
  62. }
  63. baseSubUnit, err := GetVADInfoFeatureFromSubNew(infoBase, FrontAndEndPerBase)
  64. if err != nil {
  65. t.Fatal(err)
  66. }
  67. srcSubUnit, err := GetVADInfoFeatureFromSubNew(infoSrc, FrontAndEndPerBase)
  68. if err != nil {
  69. t.Fatal(err)
  70. }
  71. if len(baseSubUnit.VADList) != len(srcSubUnit.VADList) {
  72. t.Fatal(fmt.Sprintf("info Base And Src Parse Error, infoBase.VADList Len = %v, infoSrc.VADList Len = %v",
  73. len(baseSubUnit.VADList), len(srcSubUnit.VADList)))
  74. }
  75. for i := 0; i < len(baseSubUnit.VADList); i++ {
  76. if baseSubUnit.VADList[i] != srcSubUnit.VADList[i] {
  77. println(fmt.Sprintf("base src VADList i=%v, not the same", i))
  78. }
  79. }
  80. }
  81. const FrontAndEndPerBase = 0