decode_test.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package decode
  2. import (
  3. "path/filepath"
  4. "reflect"
  5. "testing"
  6. "github.com/allanpk716/ChineseSubFinder/pkg/types"
  7. "github.com/allanpk716/ChineseSubFinder/pkg/unit_test_helper"
  8. )
  9. func TestGetImdbAndYearMovieXml(t *testing.T) {
  10. rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"movies", "Army of the Dead (2021)"}, 4, false)
  11. wantid := "tt0993840"
  12. wantyear := "2021"
  13. dirPth := filepath.Join(rootDir, "movie.xml")
  14. imdbInfo, err := getVideoNfoInfoFromMovieXml(dirPth)
  15. if err != nil {
  16. t.Error(err)
  17. }
  18. if imdbInfo.ImdbId != wantid {
  19. t.Errorf("got = %v, want %v", imdbInfo.ImdbId, wantid)
  20. }
  21. if imdbInfo.Year != wantyear {
  22. t.Errorf("got = %v, want %v", imdbInfo.Year, wantyear)
  23. }
  24. }
  25. func Test_getImdbAndYearNfo(t *testing.T) {
  26. type args struct {
  27. nfoFilePath string
  28. rootKey string
  29. }
  30. tests := []struct {
  31. name string
  32. args args
  33. want types.VideoNfoInfo
  34. wantErr bool
  35. }{
  36. {
  37. name: "Army of the Dead (2021) WEBDL-1080p.nfo", args: args{
  38. nfoFilePath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"movies", "Army of the Dead (2021)"}, 4, false), "Army of the Dead (2021) WEBDL-1080p.nfo"),
  39. rootKey: "movie",
  40. },
  41. want: types.VideoNfoInfo{
  42. ImdbId: "tt0993840",
  43. Title: "活死人军团",
  44. Year: "2021",
  45. ReleaseDate: "2021-05-13",
  46. },
  47. wantErr: false,
  48. },
  49. {
  50. name: "tvshow_00 (2).nfo", args: args{
  51. nfoFilePath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"nfo_files", "tvshow"}, 4, false), "tvshow_00 (2).nfo"),
  52. rootKey: "tvshow",
  53. },
  54. want: types.VideoNfoInfo{
  55. ImdbId: "tt0346314",
  56. Title: "Ghost in the Shell: Stand Alone Complex",
  57. ReleaseDate: "2002-10-01",
  58. },
  59. wantErr: false,
  60. },
  61. {
  62. name: "tvshow_00 (3).nfo", args: args{
  63. nfoFilePath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"nfo_files", "tvshow"}, 4, false), "tvshow_00 (3).nfo"),
  64. rootKey: "tvshow",
  65. },
  66. want: types.VideoNfoInfo{
  67. ImdbId: "tt1856010",
  68. Title: "House of Cards (US)",
  69. ReleaseDate: "2013-02-01",
  70. },
  71. wantErr: false,
  72. },
  73. }
  74. for _, tt := range tests {
  75. t.Run(tt.name, func(t *testing.T) {
  76. got, err := getVideoNfoInfo(tt.args.nfoFilePath, tt.args.rootKey)
  77. if (err != nil) != tt.wantErr {
  78. t.Errorf("getVideoNfoInfo() error = %v, wantErr %v", err, tt.wantErr)
  79. return
  80. }
  81. if !reflect.DeepEqual(got, tt.want) {
  82. t.Errorf("getVideoNfoInfo() got = %v, want %v", got, tt.want)
  83. }
  84. })
  85. }
  86. }
  87. func TestGetSeasonAndEpisodeFromFileName(t *testing.T) {
  88. str := `杀死伊芙 第二季(-简繁英双语字幕-FIX字幕侠)Killing.Eve.S02.Do.You.Know.How.to.Dispose.of.a.Body.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb.rar`
  89. b, s, e, err := GetSeasonAndEpisodeFromSubFileName(str)
  90. if err != nil {
  91. t.Fatal(err)
  92. }
  93. t.Logf("\n\n%t\t S%dE%d\n", b, s, e)
  94. }
  95. func TestGetNumber2Float(t *testing.T) {
  96. testString := "asd&^%1998.2jh aweo "
  97. outNumber, err := GetNumber2Float(testString)
  98. if err != nil {
  99. t.Error(err)
  100. }
  101. if outNumber != 1998.2 {
  102. t.Error("not the same")
  103. }
  104. }
  105. func TestGetNumber2int(t *testing.T) {
  106. testString := "asd&^%1998jh aweo "
  107. outNumber, err := GetNumber2int(testString)
  108. if err != nil {
  109. t.Error(err)
  110. }
  111. if outNumber != 1998 {
  112. t.Error("not the same")
  113. }
  114. }
  115. func TestGetImdbInfo4SeriesDir(t *testing.T) {
  116. type args struct {
  117. seriesDir string
  118. }
  119. tests := []struct {
  120. name string
  121. args args
  122. want types.VideoNfoInfo
  123. wantErr bool
  124. }{
  125. {
  126. name: "Loki",
  127. args: args{seriesDir: unit_test_helper.GetTestDataResourceRootPath([]string{"series", "Loki"}, 4, false)},
  128. want: types.VideoNfoInfo{
  129. ImdbId: "tt9140554",
  130. Title: "Loki",
  131. ReleaseDate: "2021-06-09",
  132. },
  133. wantErr: false,
  134. },
  135. {
  136. name: "辛普森一家",
  137. args: args{seriesDir: unit_test_helper.GetTestDataResourceRootPath([]string{"series", "辛普森一家"}, 4, false)},
  138. want: types.VideoNfoInfo{
  139. ImdbId: "tt0096697",
  140. Title: "The Simpsons",
  141. ReleaseDate: "1989-12-17",
  142. },
  143. wantErr: false,
  144. },
  145. }
  146. for _, tt := range tests {
  147. t.Run(tt.name, func(t *testing.T) {
  148. got, err := GetVideoNfoInfo4SeriesDir(tt.args.seriesDir)
  149. if (err != nil) != tt.wantErr {
  150. t.Errorf("GetVideoNfoInfo4SeriesDir() error = %v, wantErr %v", err, tt.wantErr)
  151. return
  152. }
  153. if !reflect.DeepEqual(got, tt.want) {
  154. t.Errorf("GetVideoNfoInfo4SeriesDir() got = %v, want %v", got, tt.want)
  155. }
  156. })
  157. }
  158. }
  159. func TestIsFakeBDMVWorked(t *testing.T) {
  160. rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"movies", "失控玩家 (2021)"}, 4, false)
  161. bok, dbmvFPath, _ := IsFakeBDMVWorked(filepath.Join(rootDir, "失控玩家 (2021).mp4"))
  162. if bok == false {
  163. t.Fatal("IsFakeBDMVWorked error")
  164. }
  165. println(dbmvFPath)
  166. }
  167. func TestGetImdbInfo4Movie(t *testing.T) {
  168. //type args struct {
  169. // movieFileFullPath string
  170. //}
  171. //tests := []struct {
  172. // name string
  173. // args args
  174. // want types.VideoNfoInfo
  175. // wantErr bool
  176. //}{
  177. // {name: "00", args: args{
  178. // movieFileFullPath: "X:\\电影\\Death on the Nile (2022)\\Death on the Nile (2022) Bluray-1080p.mkv",
  179. // }},
  180. //}
  181. //for _, tt := range tests {
  182. // t.Run(tt.name, func(t *testing.T) {
  183. // got, err := GetVideoNfoInfo4Movie(tt.args.movieFileFullPath)
  184. // if (err != nil) != tt.wantErr {
  185. // t.Errorf("GetVideoNfoInfo4Movie() error = %v, wantErr %v", err, tt.wantErr)
  186. // return
  187. // }
  188. // if !reflect.DeepEqual(got, tt.want) {
  189. // t.Errorf("GetVideoNfoInfo4Movie() got = %v, want %v", got, tt.want)
  190. // }
  191. // })
  192. //}
  193. }