playurl.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package goblin
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/interface/main/tv/model"
  6. arcwar "go-common/app/service/main/archive/api"
  7. tvapi "go-common/app/service/main/tv/api"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _tvVipOk = 1
  13. )
  14. // UgcPlayurl returns the result of ugc play url
  15. func (s *Service) UgcPlayurl(c context.Context, p *model.PlayURLReq, mid int64) (result map[string]interface{}, err error) {
  16. var (
  17. arc *arcwar.Arc
  18. firstRes map[string]interface{}
  19. firstResp *model.PlayURLResp
  20. tvRes *tvapi.UserInfoReply
  21. )
  22. result = make(map[string]interface{})
  23. if firstRes, firstResp, err = s.dao.UgcPlayurl(c, p); err != nil {
  24. return
  25. }
  26. if _, ok := s.VipQns[p.Qn]; !ok { // if it doesn't request vip quality, let it go
  27. return firstRes, nil
  28. }
  29. if mid != 0 {
  30. if tvRes, err = s.tvCilent.UserInfo(c, &tvapi.UserInfoReq{Mid: mid}); err != nil && !ecode.EqualError(ecode.NothingFound, err) {
  31. log.Error("[playurl.UgcPlayurl] mid(%d) error(%s)", mid, err)
  32. return
  33. }
  34. if tvRes != nil && tvRes.Status == _tvVipOk {
  35. return firstRes, nil // if it's tv vip, let it go !
  36. }
  37. if arc, err = s.arcDao.Archive3(c, p.Avid); err != nil || arc == nil { // try author himself
  38. log.Warn("s.arcDao.Archive3 failed can not view Aid %d, Mid %", p.Avid, mid)
  39. return
  40. }
  41. if arc.Author.Mid == mid {
  42. return firstRes, nil // if it's upper himself, let it go
  43. }
  44. }
  45. // downgrade logic
  46. for _, qn := range firstResp.AcceptQuality {
  47. qnStr := fmt.Sprintf("%d", qn)
  48. if _, ok := s.VipQns[qnStr]; ok { // if vip
  49. continue
  50. }
  51. p.Qn = qnStr
  52. result, _, err = s.dao.UgcPlayurl(c, p)
  53. return
  54. }
  55. err = ecode.NothingFound // it doesn't have any other quality to allow downgrade
  56. log.Error("Allow Quality %v, Err %v", firstResp.AcceptQuality, err)
  57. return
  58. }