subhd_test.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package subhd
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. "testing"
  6. "time"
  7. commonValue "github.com/allanpk716/ChineseSubFinder/pkg/types/common"
  8. "github.com/allanpk716/ChineseSubFinder/pkg/logic/file_downloader"
  9. "github.com/allanpk716/ChineseSubFinder/pkg/logic/series_helper"
  10. "github.com/allanpk716/ChineseSubFinder/pkg/cache_center"
  11. "github.com/allanpk716/ChineseSubFinder/pkg/global_value"
  12. "github.com/allanpk716/ChineseSubFinder/pkg/log_helper"
  13. "github.com/allanpk716/ChineseSubFinder/pkg/my_util"
  14. "github.com/allanpk716/ChineseSubFinder/pkg/random_auth_key"
  15. "github.com/allanpk716/ChineseSubFinder/pkg/settings"
  16. "github.com/allanpk716/ChineseSubFinder/pkg/something_static"
  17. "github.com/allanpk716/ChineseSubFinder/pkg/unit_test_helper"
  18. )
  19. var authKey random_auth_key.AuthKey
  20. func defInstance() {
  21. my_util.ReadCustomAuthFile(log_helper.GetLogger4Tester())
  22. authKey = random_auth_key.AuthKey{
  23. BaseKey: global_value.BaseKey(),
  24. AESKey16: global_value.AESKey16(),
  25. AESIv16: global_value.AESIv16(),
  26. }
  27. }
  28. // 无需关注这个测试用例,这个方案暂时弃用
  29. func TestSupplier_GetSubListFromFile(t *testing.T) {
  30. //movie1 := "X:\\电影\\The Devil All the Time (2020)\\The Devil All the Time (2020) WEBDL-1080p.mkv"
  31. //movie1 := "X:\\电影\\Luca (2021)\\Luca (2021) WEBDL-1080p.mkv"
  32. //movie1 := "X:\\电影\\The Boss Baby Family Business (2021)\\The Boss Baby Family Business (2021) WEBDL-1080p.mkv"
  33. //movie1 := "X:\\电影\\Oslo (2021)\\Oslo (2021) WEBDL-1080p.mkv"
  34. //movie1 := "X:\\电影\\Spiral From the Book of Saw (2021)\\Spiral From the Book of Saw (2021) WEBDL-1080p.mkv"
  35. //movie1 := "X:\\电影\\消失爱人 (2016)\\消失爱人 (2016) 720p AAC.rmvb"
  36. //movie1 := "X:\\电影\\机动战士Z高达:星之继承者 (2005)\\机动战士Z高达:星之继承者 (2005) 1080p TrueHD.mkv"
  37. getCode()
  38. defInstance()
  39. rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_spplier"}, 5, true)
  40. movie1 := filepath.Join(rootDir, "zimuku", "movies", "消失爱人 (2016)", "消失爱人 (2016) 720p AAC.rmvb")
  41. subhd := NewSupplier(file_downloader.NewFileDownloader(cache_center.NewCacheCenter("test", settings.NewSettings(), log_helper.GetLogger4Tester()), authKey))
  42. outList, err := subhd.getSubListFromFile4Movie(movie1)
  43. if err != nil {
  44. t.Error(err)
  45. }
  46. println(outList)
  47. if len(outList) == 0 {
  48. println("now sub found")
  49. }
  50. for i, sublist := range outList {
  51. println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, sublist.FileUrl, len(sublist.Data))
  52. }
  53. alive, _ := subhd.CheckAlive()
  54. if alive == false {
  55. t.Fatal("CheckAlive == false")
  56. }
  57. }
  58. // 无需关注这个测试用例,这个方案暂时弃用
  59. func TestSupplier_GetSubListFromFile4Series(t *testing.T) {
  60. //ser := "X:\\连续剧\\The Bad Batch" // tt12708542
  61. //ser := "X:\\连续剧\\瑞克和莫蒂 (2013)" //
  62. //ser := "X:\\连续剧\\杀死伊芙 (2018)" // tt7016936
  63. //ser := "X:\\连续剧\\Money.Heist"
  64. //ser := "X:\\连续剧\\黑钱胜地 (2017)"
  65. getCode()
  66. defInstance()
  67. // 可以指定几集去调试
  68. epsMap := make(map[int][]int, 0)
  69. epsMap[4] = []int{1}
  70. //epsMap[1] = []int{1, 2, 3}
  71. rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_spplier"}, 5, true)
  72. ser := filepath.Join(rootDir, "zimuku", "series", "黄石 (2018)")
  73. // 读取本地的视频和字幕信息
  74. seriesInfo, err := series_helper.ReadSeriesInfoFromDir(log_helper.GetLogger4Tester(), ser, 90, false, false, epsMap)
  75. if err != nil {
  76. t.Fatal(err)
  77. }
  78. s := NewSupplier(file_downloader.NewFileDownloader(cache_center.NewCacheCenter("test", settings.NewSettings(), log_helper.GetLogger4Tester()), authKey))
  79. outList, err := s.GetSubListFromFile4Series(seriesInfo)
  80. if err != nil {
  81. t.Fatal(err)
  82. }
  83. for i, sublist := range outList {
  84. println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
  85. }
  86. }
  87. // 无需关注这个测试用例,这个方案暂时弃用
  88. func TestSupplier_getSubListFromKeyword4Movie(t *testing.T) {
  89. //imdbID := "tt12708542" // 星球大战:残次品
  90. //imdbID := "tt7016936" // 杀死伊芙
  91. imdbID := "tt2990738" // 恐怖直播
  92. //imdbID := "tt3032476" // 风骚律师
  93. //imdbID := "tt6468322" // 纸钞屋
  94. //imdbID := "tt15299712" // 云南虫谷
  95. //imdbID := "tt3626476" // Vacation Friends (2021)
  96. getCode()
  97. defInstance()
  98. subhd := NewSupplier(file_downloader.NewFileDownloader(cache_center.NewCacheCenter("test", settings.NewSettings(), log_helper.GetLogger4Tester()), authKey))
  99. subInfos, err := subhd.getSubListFromKeyword4Movie(imdbID)
  100. if err != nil {
  101. t.Fatal(err)
  102. }
  103. for i, sublist := range subInfos {
  104. println(i, sublist.Name, sublist.Ext, sublist.Language.String(), sublist.Score, len(sublist.Data))
  105. }
  106. }
  107. func getCode() {
  108. if my_util.ReadCustomAuthFile(log_helper.GetLogger4Tester()) == false {
  109. println("read auth file failed")
  110. return
  111. }
  112. fileDownloader := file_downloader.NewFileDownloader(
  113. cache_center.NewCacheCenter("local_task_queue", settings.GetSettings(), log_helper.GetLogger4Tester()),
  114. random_auth_key.AuthKey{
  115. BaseKey: global_value.BaseKey(),
  116. AESKey16: global_value.AESKey16(),
  117. AESIv16: global_value.AESIv16(),
  118. })
  119. nowTT := time.Now()
  120. nowTimeFileNamePrix := fmt.Sprintf("%d%d%d", nowTT.Year(), nowTT.Month(), nowTT.Day())
  121. updateTimeString, code, err := something_static.GetCodeFromWeb(log_helper.GetLogger4Tester(), nowTimeFileNamePrix, fileDownloader)
  122. if err != nil {
  123. commonValue.SubhdCode = ""
  124. } else {
  125. commonValue.SubhdCode = code
  126. }
  127. fmt.Println("UpdateTime", updateTimeString)
  128. }