videoup.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/admin/main/dm/model"
  7. "go-common/library/log"
  8. "go-common/library/xstr"
  9. )
  10. const (
  11. _views = "/videoup/views"
  12. _types = "/videoup/types"
  13. _season = "/pgc/admin/season/dm/aids"
  14. )
  15. // TypeInfo TypeInfo
  16. func (d *Dao) TypeInfo(c context.Context) (types map[int64]*model.ArchiveType, err error) {
  17. var (
  18. res struct {
  19. Code int64 `json:"code"`
  20. Data map[int64]*model.ArchiveType `json:"data"`
  21. Message string `json:"message"`
  22. }
  23. )
  24. v := make(url.Values)
  25. if err = d.httpCli.Get(c, d.typesURI, "", v, &res); err != nil {
  26. log.Error("d.httpCli.Get(%s) error(%v)", d.typesURI, err)
  27. return
  28. }
  29. if res.Code != 0 {
  30. err = fmt.Errorf("%v", res)
  31. log.Error("d.httpClient.Get(%s) code(%d)", d.typesURI, res.Code)
  32. }
  33. types = res.Data
  34. return
  35. }
  36. // ArchiveVideos return archive and video info.
  37. func (d *Dao) ArchiveVideos(c context.Context, aids []int64) (avm map[int64]*model.ArcVideo, err error) {
  38. var (
  39. res struct {
  40. Code int64 `json:"code"`
  41. Data map[int64]*model.ArcVideo `json:"data"`
  42. Message string `json:"message"`
  43. }
  44. v = make(url.Values)
  45. )
  46. v.Set("aids", xstr.JoinInts(aids))
  47. if err = d.httpCli.Get(c, d.viewsURI, "", v, &res); err != nil {
  48. log.Error("d.httpClient.Get(%s) error(%v)", d.viewsURI, err)
  49. return
  50. }
  51. if res.Code != 0 {
  52. err = fmt.Errorf("%v", res)
  53. log.Error("d.httpClient.Get(%s) code(%d)", d.viewsURI, res.Code)
  54. return
  55. }
  56. avm = res.Data
  57. return
  58. }
  59. // SeasonInfos return season infos
  60. func (d *Dao) SeasonInfos(c context.Context, IDType string, id int64) (aids, oids []int64, err error) {
  61. var (
  62. res struct {
  63. Code int64 `json:"code"`
  64. Message string `json:"message"`
  65. Data []*model.SeasonInfo `json:"result"`
  66. }
  67. params = make(url.Values, 1)
  68. )
  69. switch IDType {
  70. case "ep":
  71. params.Set("epid", fmt.Sprint(id))
  72. case "ss":
  73. params.Set("season_id", fmt.Sprint(id))
  74. default:
  75. err = fmt.Errorf("season type(%s) error", IDType)
  76. log.Error("d.SeasonInfos error(%v)", err)
  77. return
  78. }
  79. if err = d.httpSearch.Get(c, d.seasonURI, "", params, &res); err != nil {
  80. log.Error("d.httpSearch.Get(uri:%s,params:%s) error(%v)", d.seasonURI, params.Encode(), err)
  81. return
  82. }
  83. if res.Code != 0 {
  84. err = fmt.Errorf("uri:%s,code:%d", d.seasonURI, res.Code)
  85. log.Error("d.SeasonInfos error(%v)", err)
  86. return
  87. }
  88. for _, v := range res.Data {
  89. aids = append(aids, v.Aid)
  90. oids = append(oids, v.Cid)
  91. }
  92. return
  93. }