bangumi.go 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package notice
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/library/log"
  8. )
  9. type bangumi struct {
  10. EpisodeID int64 `json:"episode_id,string"`
  11. SeasonID int64 `json:"season_id"`
  12. Title string `json:"title"`
  13. IndexTitle string `json:"index_title"`
  14. }
  15. // Bangumi return link.
  16. func (d *Dao) Bangumi(c context.Context, oid int64) (title, link string, epid int64, err error) {
  17. params := url.Values{}
  18. params.Set("aids", strconv.FormatInt(oid, 10))
  19. params.Set("platform", "reply")
  20. params.Set("build", "0")
  21. var res struct {
  22. Code int `json:"code"`
  23. Result map[int64]*bangumi `json:"result"`
  24. }
  25. if err = d.httpClient.Get(c, d.urlBangumi, "", params, &res); err != nil {
  26. log.Error("d.httpClient.Get(%s?%s) error(%v)", d.urlBangumi, params.Encode(), err)
  27. return
  28. }
  29. if res.Code != 0 || res.Result == nil {
  30. err = fmt.Errorf("url:%s?%s code:%d", d.urlBangumi, params.Encode(), res.Code)
  31. return
  32. }
  33. if r := res.Result[oid]; r != nil {
  34. epid = r.EpisodeID
  35. }
  36. return
  37. }