videoup.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/job/main/dm2/model"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _archiveURL = "/videoup/view"
  11. )
  12. func (d *Dao) archiveURI() string {
  13. return d.conf.Host.Videoup + _archiveURL
  14. }
  15. // Videos 根据aid获取分批信息,包含未开放浏览分批.
  16. func (d *Dao) Videos(c context.Context, aid int64) (videos []*model.Video, err error) {
  17. var (
  18. uri = d.archiveURI()
  19. params = url.Values{}
  20. res struct {
  21. Code int64 `json:"code"`
  22. Message string `json:"message"`
  23. Data *struct {
  24. Archive *model.Archive `json:"archive"`
  25. Videos []*model.Video `json:"videos"`
  26. } `json:"data"`
  27. }
  28. )
  29. params.Set("aid", fmt.Sprint(aid))
  30. if err = d.httpCli.Get(c, uri, "", params, &res); err != nil {
  31. return
  32. }
  33. if res.Code != 0 {
  34. err = fmt.Errorf("aid:%d,res.Code:%d", aid, res.Code)
  35. log.Error("url(%s) aid(%d) res(%v)", uri+"?"+params.Encode(), aid, res)
  36. return
  37. }
  38. if res.Data == nil || res.Data.Archive == nil {
  39. log.Error("url(%s) aid(%d) res(%v)", uri+"?"+params.Encode(), aid, res)
  40. return
  41. }
  42. if len(res.Data.Videos) == 0 {
  43. log.Error("url(%s) aid(%d) videos is empty", uri+"?"+params.Encode(), aid)
  44. return
  45. }
  46. for _, v := range res.Data.Videos {
  47. v.Mid = res.Data.Archive.Mid
  48. videos = append(videos, v)
  49. }
  50. return
  51. }