audio_playlist.go 783 B

123456789101112131415161718192021222324252627282930313233343536
  1. package notice
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _urlAudioPlayList = "https://m.bilibili.com/audio/am%d"
  10. )
  11. // AudioPlayList is show AudioPlay list
  12. func (d *Dao) AudioPlayList(c context.Context, oid int64) (title, link string, err error) {
  13. params := url.Values{}
  14. uri := fmt.Sprintf(d.urlAudioPlaylist, oid)
  15. var res struct {
  16. Code int `json:"code"`
  17. Data *struct {
  18. Title string `json:"title"`
  19. } `json:"data"`
  20. }
  21. if err = d.httpClient.Get(c, uri, "", params, &res); err != nil {
  22. log.Error("d.httpClient.Get(%s?%s) error(%v)", uri, params.Encode(), err)
  23. return
  24. }
  25. if res.Data == nil {
  26. err = fmt.Errorf("url:%s code:%d", uri, res.Code)
  27. return
  28. }
  29. title = res.Data.Title
  30. link = fmt.Sprintf(_urlAudioPlayList, oid)
  31. return
  32. }