This repository has been archived on 2024-01-17. You can view files and clone it, but cannot push or open issues or pull requests.
dlbot4/tiktok/tikmate.go

47 lines
1.1 KiB
Go
Raw Normal View History

2023-01-04 16:21:00 +00:00
package tiktok
2022-08-10 18:41:51 +00:00
import (
"encoding/json"
"errors"
2022-08-10 18:41:51 +00:00
"io"
"net/url"
)
2023-05-17 02:51:49 +00:00
// alternativa: https://github.com/Evil0ctal/Douyin_TikTok_Download_API
2023-01-04 16:21:00 +00:00
type lookupResponse struct {
2022-08-10 18:41:51 +00:00
AuthorAvatar string `json:"author_avatar"`
AuthorID string `json:"author_id"`
AuthorName string `json:"author_name"`
CommentCount int `json:"comment_count"`
CreateTime string `json:"create_time"`
ID string `json:"id"`
LikeCount int `json:"like_count"`
ShareCount int `json:"share_count"`
Success bool `json:"success"`
Message string `json:"message"`
2022-08-10 18:41:51 +00:00
Token string `json:"token"`
}
2023-01-04 16:36:25 +00:00
func (r *TikTok) lookup(urlS string) (string, error) {
resp, err := r.Client.PostForm(
2022-08-10 18:41:51 +00:00
"https://api.tikmate.app/api/lookup",
url.Values{"url": {urlS}},
)
if err != nil {
return "", err
2022-08-10 18:41:51 +00:00
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
2023-01-04 16:21:00 +00:00
var lookup lookupResponse
err = json.Unmarshal(body, &lookup)
2022-08-10 18:41:51 +00:00
if err != nil {
return "", err
}
if !lookup.Success {
return "", errors.New(lookup.Message)
2022-08-10 18:41:51 +00:00
}
return "https://tikmate.app/download/" + lookup.Token + "/" + lookup.ID + ".mp4", nil
2022-08-10 18:41:51 +00:00
}