talentVideoInfo.go 2.5 KB

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