rec.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package skyhorse
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/xstr"
  10. )
  11. const (
  12. _skyHorseURLAddr = "http://data.bilibili.co/recommand"
  13. _skyHorseCnt = 6
  14. _skyHorseFrom = "29004"
  15. )
  16. type SkyHorseItem struct {
  17. Tid int `json:"tid"`
  18. Id int `json:"id"`
  19. GotoType string `json:"goto_type"`
  20. Source string `json:"source"`
  21. TrackId string `json:"track_id"`
  22. AvFeature string `json:"av_feature"`
  23. RcmdReason string `json:"rcmd_reason"`
  24. }
  25. type skyHorseRecResp struct {
  26. Code int `json:"code"`
  27. Error string `json:"error"`
  28. Data []*SkyHorseItem `json:"data"`
  29. }
  30. func (c *Client) GetSkyHorseRec(ctx context.Context, mid int64, buvid string, build int64, plat string,
  31. duplicateItem []int64, strongLen int, timeout int) (skyHorseRec *skyHorseRecResp, err error) {
  32. cli := bm.NewClient(c.getConf())
  33. param := url.Values{}
  34. requestCnt := _skyHorseCnt - strongLen
  35. if requestCnt <= 0 {
  36. requestCnt = 6
  37. }
  38. param.Set("cmd", "live")
  39. param.Set("from", _skyHorseFrom)
  40. param.Set("request_cnt", strconv.Itoa(requestCnt))
  41. param.Set("mid", strconv.FormatInt(mid, 10))
  42. param.Set("buvid", buvid)
  43. param.Set("build", strconv.FormatInt(build, 10))
  44. param.Set("plat", plat)
  45. param.Set("timeout", strconv.Itoa(timeout))
  46. param.Set("duplicates", xstr.JoinInts(duplicateItem))
  47. skyHorseRec = &skyHorseRecResp{}
  48. err = cli.Get(ctx, _skyHorseURLAddr, "", param, skyHorseRec)
  49. if err != nil {
  50. log.Error("[GetSkyHorseRec]error:%+v=", err)
  51. return
  52. }
  53. if skyHorseRec.Code != ecode.OK.Code() {
  54. err = ecode.Int(skyHorseRec.Code)
  55. log.Error("[getSkyHorseRoomList]getSkyHorseList error:%+v,code:%d,msg:%s", err, skyHorseRec.Code, skyHorseRec.Error)
  56. }
  57. return
  58. }