zimuku_test.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package zimuku
  2. import (
  3. "path/filepath"
  4. "testing"
  5. "github.com/allanpk716/ChineseSubFinder/pkg"
  6. "github.com/allanpk716/ChineseSubFinder/pkg/rod_helper"
  7. "github.com/allanpk716/ChineseSubFinder/pkg/cache_center"
  8. "github.com/allanpk716/ChineseSubFinder/pkg/log_helper"
  9. "github.com/allanpk716/ChineseSubFinder/pkg/logic/file_downloader"
  10. "github.com/allanpk716/ChineseSubFinder/pkg/logic/series_helper"
  11. "github.com/allanpk716/ChineseSubFinder/pkg/random_auth_key"
  12. "github.com/allanpk716/ChineseSubFinder/pkg/settings"
  13. "github.com/allanpk716/ChineseSubFinder/pkg/sub_helper"
  14. "github.com/allanpk716/ChineseSubFinder/pkg/unit_test_helper"
  15. )
  16. func TestSupplier_GetSubListFromKeyword(t *testing.T) {
  17. defInstance()
  18. browser, err := rod_helper.NewBrowserBase(log_helper.GetLogger4Tester(), "", "", true, settings.NewSettings(pkg.ConfigRootDirFPath()).AdvancedSettings.SuppliersSettings.Zimuku.RootUrl)
  19. if err != nil {
  20. t.Fatal(err)
  21. }
  22. defer func() {
  23. _ = browser.Close()
  24. }()
  25. //imdbId1 := "tt3228774"
  26. videoName := "黑白魔女库伊拉"
  27. outList, err := zimukuInstance.getSubListFromKeyword(browser, videoName)
  28. if err != nil {
  29. t.Error(err)
  30. }
  31. println(outList)
  32. for i, sublist := range outList {
  33. println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
  34. }
  35. }
  36. func TestSupplier_GetSubListFromFile(t *testing.T) {
  37. opt := rod_helper.NewBrowserOptions(log_helper.GetLogger4Tester(), true, settings.NewSettings(pkg.ConfigRootDirFPath()))
  38. opt.SetPreLoadUrl(settings.NewSettings(pkg.ConfigRootDirFPath()).AdvancedSettings.SuppliersSettings.Zimuku.RootUrl)
  39. browser, err := rod_helper.NewBrowserEx(opt)
  40. if err != nil {
  41. t.Fatal(err)
  42. }
  43. defer func() {
  44. _ = browser.Close()
  45. }()
  46. //movie1 := "X:\\电影\\The Devil All the Time (2020)\\The Devil All the Time (2020) WEBDL-1080p.mkv"
  47. //movie1 := "X:\\电影\\龙猫 (1988)\\龙猫 (1988) 1080p DTS.mkv"
  48. //movie1 := "X:\\电影\\消失爱人 (2016)\\消失爱人 (2016) 720p AAC.rmvb"
  49. //movie1 := "X:\\电影\\Spiral From the Book of Saw (2021)\\Spiral From the Book of Saw (2021) WEBDL-1080p.mkv"
  50. //movie1 := "X:\\电影\\机动战士Z高达:星之继承者 (2005)\\机动战士Z高达:星之继承者 (2005) 1080p TrueHD.mkv"
  51. //movie1 := "X:\\连续剧\\The Bad Batch\\Season 1\\The Bad Batch - S01E01 - Aftermath WEBDL-1080p.mkv"
  52. defInstance()
  53. rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_spplier"}, 5, true)
  54. movie1 := filepath.Join(rootDir, "zimuku", "movies", "The Devil All the Time (2020)", "The Devil All the Time (2020) WEBDL-1080p.mkv")
  55. outList, err := zimukuInstance.getSubListFromMovie(browser, movie1)
  56. if err != nil {
  57. t.Error(err)
  58. }
  59. println(outList)
  60. for i, sublist := range outList {
  61. println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
  62. }
  63. }
  64. func TestSupplier_GetSubListFromFile4Series(t *testing.T) {
  65. //ser := "X:\\连续剧\\The Bad Batch" // tt12708542
  66. //ser := "X:\\连续剧\\杀死伊芙 (2018)" // tt12708542
  67. //ser := "X:\\连续剧\\Money.Heist"
  68. //ser := "X:\\连续剧\\黄石 (2018)"
  69. // 可以指定几集去调试
  70. epsMap := make(map[int][]int, 0)
  71. epsMap[4] = []int{1}
  72. //epsMap[1] = []int{1, 2, 3}
  73. rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_spplier"}, 5, true)
  74. ser := filepath.Join(rootDir, "zimuku", "series", "黄石 (2018)")
  75. // 读取本地的视频和字幕信息
  76. seriesInfo, err := series_helper.ReadSeriesInfoFromDir(log_helper.GetLogger4Tester(),
  77. ser,
  78. 90,
  79. false,
  80. false,
  81. settings.Get().AdvancedSettings.ProxySettings,
  82. epsMap)
  83. if err != nil {
  84. t.Fatal(err)
  85. }
  86. defInstance()
  87. outList, err := zimukuInstance.GetSubListFromFile4Series(seriesInfo)
  88. if err != nil {
  89. t.Fatal(err)
  90. }
  91. println(outList)
  92. for i, sublist := range outList {
  93. println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
  94. }
  95. organizeSubFiles, err := sub_helper.OrganizeDlSubFiles(log_helper.GetLogger4Tester(), filepath.Base(seriesInfo.DirPath), outList, false)
  96. if err != nil {
  97. t.Fatal(err)
  98. }
  99. for s2, strings := range organizeSubFiles {
  100. println(s2, strings)
  101. }
  102. }
  103. func TestSupplier_getSubListFromKeyword(t *testing.T) {
  104. opt := rod_helper.NewBrowserOptions(log_helper.GetLogger4Tester(), true, settings.NewSettings(pkg.ConfigRootDirFPath()))
  105. opt.SetPreLoadUrl(settings.NewSettings(pkg.ConfigRootDirFPath()).AdvancedSettings.SuppliersSettings.Zimuku.RootUrl)
  106. browser, err := rod_helper.NewBrowserEx(opt)
  107. if err != nil {
  108. t.Fatal(err)
  109. }
  110. defer func() {
  111. _ = browser.Close()
  112. }()
  113. //imdbID := "tt12708542" // 星球大战:残次品
  114. //imdbID := "tt7016936" // 杀死伊芙
  115. //imdbID := "tt2990738" // 恐怖直播
  116. //imdbID := "tt3032476" // 风骚律师
  117. //imdbID := "tt6468322" // 纸钞屋
  118. //imdbID := "tt15299712" // 云南虫谷
  119. //imdbID := "tt3626476" // Vacation Friends (2021)
  120. imdbID := "tt11192306" // Superman.and.Lois
  121. defInstance()
  122. subInfos, err := zimukuInstance.getSubListFromKeyword(browser, imdbID)
  123. if err != nil {
  124. t.Fatal(err)
  125. }
  126. for i, sublist := range subInfos {
  127. println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
  128. }
  129. }
  130. func TestSupplier_step3(t *testing.T) {
  131. // 调试用,不作为单元测试的一个考核,因为可能不可控
  132. //dlUrl := "https://zmk.pw/dld/162150.html"
  133. //s := Supplier{}
  134. //fileName, datas, err := s.DownFile(dlUrl)
  135. //if err != nil {
  136. // t.Fatal(err)
  137. //}
  138. //
  139. //println(fileName)
  140. //println(len(datas))
  141. }
  142. func TestSupplier_CheckAlive(t *testing.T) {
  143. defInstance()
  144. alive, _ := zimukuInstance.CheckAlive()
  145. if alive == false {
  146. t.Fatal("CheckAlive == false")
  147. }
  148. }
  149. var zimukuInstance *Supplier
  150. func defInstance() {
  151. pkg.ReadCustomAuthFile(log_helper.GetLogger4Tester())
  152. authKey := random_auth_key.AuthKey{
  153. BaseKey: pkg.BaseKey(),
  154. AESKey16: pkg.AESKey16(),
  155. AESIv16: pkg.AESIv16(),
  156. }
  157. zimukuInstance = NewSupplier(file_downloader.NewFileDownloader(
  158. cache_center.NewCacheCenter("test", log_helper.GetLogger4Tester()), authKey))
  159. }