12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package youngee_talent_service
- import (
- "encoding/json"
- "fmt"
- "github.com/lin-jim-leon/kuaishou/util"
- )
- const (
- VideoCountUrl = "https://open.kuaishou.com/openapi/photo/count?app_id=%s&access_token=%s"
- VideoListUrl = "https://open.kuaishou.com/openapi/photo/count?app_id=%s&access_token=%s?count=200"
- )
- type Videoresponse struct {
- Result int `json:"result"`
- PublicCount int `json:"public_count"`
- FriendCount int `json:"friend_count"`
- PrivateCount int `json:"private_count"`
- AllCount int `json:"all_count"`
- }
- type VideoListResponse struct {
- Result int `json:"result"`
- VideoList []VideoInfo `json:"video_list"`
- }
- type VideoInfo struct {
- PhotoID int `json:"photo_id"`
- Caption int `json:"caption"`
- Cover int `json:"cover"`
- PlayURL int `json:"play_url"`
- CreateTime int `json:"create_time"`
- LikeCount int `json:"like_count"`
- CommentCount int `json:"comment_count"`
- ViewCount int `json:"view_count"`
- Pending int `json:"pending"`
- }
- // 获取总作品数
- func GetVideoCount(appid string, accesstoken string) (info Videoresponse, err error) {
- uri := fmt.Sprintf(VideoCountUrl, appid, accesstoken)
- var response []byte
- response, err = util.HTTPGet(uri)
- if err != nil {
- return Videoresponse{}, err
- }
- var result Videoresponse
- err = json.Unmarshal(response, &result)
- if err != nil {
- return Videoresponse{}, err
- }
- return result, nil
- }
- // 获取总点赞数(暂时最多统计200个视频)
- func GetVideoList(appid string, accesstoken string) (info VideoListResponse, err error) {
- uri := fmt.Sprintf(VideoListUrl, appid, accesstoken)
- var response []byte
- response, err = util.HTTPGet(uri)
- if err != nil {
- return VideoListResponse{}, err
- }
- var result VideoListResponse
- err = json.Unmarshal(response, &result)
- if err != nil {
- return VideoListResponse{}, err
- }
- return result, nil
- }
- func GetLikeCount(appid string, accesstoken string) (int, error) {
- videoListResponse, err := GetVideoList(appid, accesstoken)
- if err != nil {
- return 0, err
- }
- totalLikes := 0
- for _, video := range videoListResponse.VideoList {
- totalLikes += video.LikeCount
- }
- return totalLikes, nil
- }
|