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/main.go

44 lines
932 B
Go
Raw Normal View History

2023-01-04 16:21:00 +00:00
package tiktok
2022-08-10 18:41:51 +00:00
import (
"log"
2023-01-04 16:36:25 +00:00
"net/http"
2022-08-10 18:41:51 +00:00
"net/url"
2023-01-03 02:02:17 +00:00
"nulo.in/dlbot/common"
2022-08-10 18:41:51 +00:00
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
// Gracias a https://github.com/Xenzi-XN1/Tiktok-Download
// por enseñarme tikmate.app
2023-01-04 16:36:25 +00:00
type TikTok struct {
http.Client
}
var Responder *TikTok = &TikTok{}
func (r *TikTok) Respond(bot *tgbotapi.BotAPI, update tgbotapi.Update, url *url.URL) common.Result {
2023-01-03 02:02:17 +00:00
if url.Hostname() != "vm.tiktok.com" && url.Hostname() != "tiktok.com" {
return common.NotValid
2022-08-10 18:41:51 +00:00
}
2023-01-03 02:02:17 +00:00
urlString := url.String()
2022-08-10 18:41:51 +00:00
2023-01-03 02:02:17 +00:00
// tikmate no entiende tiktok.com
url.Host = "vm.tiktok.com"
2022-08-10 18:41:51 +00:00
2023-01-03 02:02:17 +00:00
log.Printf("Downloading %s", urlString)
2023-01-04 16:36:25 +00:00
lookup, err := r.lookup(urlString)
2023-01-03 02:02:17 +00:00
if err != nil {
log.Println(err)
2023-01-03 02:02:17 +00:00
return common.HadError
2022-08-10 18:41:51 +00:00
}
2023-01-03 02:02:17 +00:00
log.Println(lookup)
2022-08-10 18:41:51 +00:00
res := tgbotapi.NewVideo(update.Message.Chat.ID, tgbotapi.FileURL(lookup))
2023-01-03 02:02:17 +00:00
res.ReplyToMessageID = update.Message.MessageID
bot.Send(res)
return common.Uploaded
2022-08-10 18:41:51 +00:00
}