mango_recom.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package thirdp
  2. import (
  3. "fmt"
  4. "go-common/library/time"
  5. )
  6. // MangoRecom is mango recom table structure
  7. type MangoRecom struct {
  8. ID int64 `json:"id"`
  9. RID int64 `json:"rid"`
  10. Rtype int `json:"rtype"`
  11. Title string `json:"title"`
  12. Cover string `json:"cover"`
  13. Category int `json:"category"`
  14. Playcount int64 `json:"playcount"`
  15. JID int64 `json:"jid"`
  16. Content string `json:"content"`
  17. Staff string `json:"staff"`
  18. Rorder int `json:"rorder"`
  19. Mtime time.Time `json:"-"`
  20. }
  21. // MangoParams is the output structure for mango recom api
  22. type MangoParams struct {
  23. JumpParam string `json:"jump_param"` // combine
  24. Title string `json:"title"`
  25. Cover string `json:"cover"`
  26. Playcount int64 `json:"play_count"`
  27. Category string `json:"category"` // transform to CN
  28. Desc string `json:"desc"`
  29. Staff string `json:"staff"`
  30. Role string `json:"role"` // from DB
  31. PlayTime string `json:"play_time"` // from DB
  32. }
  33. // MangoOrder struct
  34. type MangoOrder struct {
  35. RIDs []int64
  36. }
  37. const (
  38. _fixStr = "&progress=0&from=mango&resource=rec"
  39. _pgcJump = "yst://com.xiaodianshi.tv.yst?type=3&isBangumi=1&seasonId=%d&epId=%d" + _fixStr
  40. _ugcJump = "yst://com.xiaodianshi.tv.yst?type=3&isBangumi=0&avId=%d&cId=%d" + _fixStr
  41. _rtypePGC = 1
  42. _rtypeUGC = 2
  43. )
  44. // ToParam transforms an MangoRecom from DB to MangoParam for mango OS
  45. func (m *MangoRecom) ToParam() *MangoParams {
  46. param := &MangoParams{
  47. Title: m.Title,
  48. Cover: m.Cover,
  49. Playcount: m.Playcount,
  50. Desc: m.Content,
  51. Staff: m.Staff,
  52. }
  53. if m.Rtype == _rtypePGC {
  54. param.JumpParam = fmt.Sprintf(_pgcJump, m.RID, m.JID)
  55. }
  56. if m.Rtype == _rtypeUGC {
  57. param.JumpParam = fmt.Sprintf(_ugcJump, m.RID, m.JID)
  58. }
  59. return param
  60. }