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

42 lines
908 B
Go
Raw Normal View History

2023-01-04 16:21:00 +00:00
package instagram
2023-01-03 02:30:01 +00:00
import (
"log"
2023-01-04 16:36:25 +00:00
"net/http"
2023-01-03 02:30:01 +00:00
"net/url"
"strings"
2023-01-03 02:30:01 +00:00
"nulo.in/dlbot/common"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
2023-01-04 16:36:25 +00:00
type Instagram struct {
http.Client
}
var Responder *Instagram = &Instagram{}
func (r *Instagram) Respond(bot *tgbotapi.BotAPI, update tgbotapi.Update, url *url.URL) common.Result {
2023-01-03 02:30:01 +00:00
if url.Hostname() != "instagram.com" && url.Hostname() != "www.instagram.com" {
return common.NotValid
}
if strings.Index(url.Path, "/reel/") != 0 {
return common.NotValid
}
2023-01-03 02:30:01 +00:00
log.Printf("Downloading %s", url.String())
2023-01-04 16:36:25 +00:00
lookup, err := r.lookup(url.String())
2023-01-03 02:30:01 +00:00
if err != nil {
2023-01-03 02:45:46 +00:00
log.Println(err)
2023-01-03 02:30:01 +00:00
return common.HadError
}
log.Println(lookup)
res := tgbotapi.NewVideo(update.Message.Chat.ID, tgbotapi.FileURL(lookup.VideoUrl))
res.ReplyToMessageID = update.Message.MessageID
res.Caption = "@" + lookup.Author
2023-01-03 02:30:01 +00:00
bot.Send(res)
return common.Uploaded
}