playurl.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/admin/main/tv/model"
  7. "go-common/library/log"
  8. )
  9. const _type = "mp4"
  10. const _maxBackup = 0
  11. const _otype = "json"
  12. const _qn = "16"
  13. // Playurl Def.
  14. func (d *Dao) Playurl(ctx context.Context, cid int) (playurl string, err error) {
  15. var (
  16. result = model.PlayurlResp{}
  17. params = url.Values{}
  18. api = d.c.Cfg.PlayurlAPI
  19. )
  20. params.Set("cid", fmt.Sprintf("%d", cid))
  21. params.Set("type", _type) // to get one piece
  22. params.Set("max_backup", fmt.Sprintf("%d", _maxBackup)) // no backup url needed
  23. params.Set("otype", _otype) // json format response
  24. params.Set("qn", _qn) // json format response
  25. if err = d.client.Get(ctx, api, "", params, &result); err != nil {
  26. log.Error("ClientGet error[%v]", err)
  27. return
  28. }
  29. if result.Code != 0 { // logic error
  30. err = fmt.Errorf("Resp Code:[%v], Message:[%v]", result.Code, result.Message)
  31. return
  32. }
  33. if len(result.Durl) < 1 { // result empty
  34. err = fmt.Errorf("Playurl Result is Empty! Resp (%v)", result)
  35. return
  36. }
  37. playurl = result.Durl[0].URL
  38. return
  39. }
  40. //UPlayurl ugc play url
  41. func (d *Dao) UPlayurl(ctx context.Context, cid int) (playurl string, err error) {
  42. var (
  43. result = model.UPlayURLR{}
  44. params = url.Values{}
  45. api = d.c.Cfg.UPlayurlAPI
  46. )
  47. params.Set("cid", fmt.Sprintf("%d", cid))
  48. params.Set("type", "mp4")
  49. params.Set("max_backup", fmt.Sprintf("%d", 0))
  50. params.Set("otype", "json")
  51. params.Set("qn", "16")
  52. params.Set("platform", "tvproj")
  53. if err = d.client.Get(ctx, api, "", params, &result); err != nil {
  54. log.Error("UPlayurl ClientGet error[%v]", err)
  55. return
  56. }
  57. if result.Code != 0 { // logic error
  58. err = fmt.Errorf("UPlayurl Resp Code:[%v], Message:[%v], Result:[%v]", result.Code, result.Message, result.Result)
  59. return
  60. }
  61. if len(result.Durl) < 1 { // result empty
  62. err = fmt.Errorf("UPlayurl Result is Empty! Resp (%v)", result)
  63. return
  64. }
  65. playurl = result.Durl[0].URL
  66. return
  67. }