talent_getVideo.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package youngee_talent_service
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/lin-jim-leon/kuaishou/util"
  6. )
  7. const (
  8. VideoCountUrl = "https://open.kuaishou.com/openapi/photo/count?app_id=%s&access_token=%s"
  9. VideoListUrl = "https://open.kuaishou.com/openapi/photo/count?app_id=%s&access_token=%s?count=200"
  10. )
  11. type Videoresponse struct {
  12. Result int `json:"result"`
  13. PublicCount int `json:"public_count"`
  14. FriendCount int `json:"friend_count"`
  15. PrivateCount int `json:"private_count"`
  16. AllCount int `json:"all_count"`
  17. }
  18. type VideoListResponse struct {
  19. Result int `json:"result"`
  20. VideoList []VideoInfo `json:"video_list"`
  21. }
  22. type VideoInfo struct {
  23. PhotoID int `json:"photo_id"`
  24. Caption int `json:"caption"`
  25. Cover int `json:"cover"`
  26. PlayURL int `json:"play_url"`
  27. CreateTime int `json:"create_time"`
  28. LikeCount int `json:"like_count"`
  29. CommentCount int `json:"comment_count"`
  30. ViewCount int `json:"view_count"`
  31. Pending int `json:"pending"`
  32. }
  33. // 获取总作品数
  34. func GetVideoCount(appid string, accesstoken string) (info Videoresponse, err error) {
  35. uri := fmt.Sprintf(VideoCountUrl, appid, accesstoken)
  36. var response []byte
  37. response, err = util.HTTPGet(uri)
  38. if err != nil {
  39. return Videoresponse{}, err
  40. }
  41. var result Videoresponse
  42. err = json.Unmarshal(response, &result)
  43. if err != nil {
  44. return Videoresponse{}, err
  45. }
  46. return result, nil
  47. }
  48. // 获取总点赞数(暂时最多统计200个视频)
  49. func GetVideoList(appid string, accesstoken string) (info VideoListResponse, err error) {
  50. uri := fmt.Sprintf(VideoListUrl, appid, accesstoken)
  51. var response []byte
  52. response, err = util.HTTPGet(uri)
  53. if err != nil {
  54. return VideoListResponse{}, err
  55. }
  56. var result VideoListResponse
  57. err = json.Unmarshal(response, &result)
  58. if err != nil {
  59. return VideoListResponse{}, err
  60. }
  61. return result, nil
  62. }
  63. func GetLikeCount(appid string, accesstoken string) (int, error) {
  64. videoListResponse, err := GetVideoList(appid, accesstoken)
  65. if err != nil {
  66. return 0, err
  67. }
  68. totalLikes := 0
  69. for _, video := range videoListResponse.VideoList {
  70. totalLikes += video.LikeCount
  71. }
  72. return totalLikes, nil
  73. }