Compare commits
4 commits
1e18e5100d
...
9a7bfdb22b
Author | SHA1 | Date | |
---|---|---|---|
Cat /dev/Nulo | 9a7bfdb22b | ||
Cat /dev/Nulo | 6d33ce97df | ||
Cat /dev/Nulo | 2e02b5a7a1 | ||
Cat /dev/Nulo | e11c967c29 |
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -10,7 +11,8 @@ import (
|
|||
|
||||
type QueryResponse struct {
|
||||
Data struct {
|
||||
ShortcodeMedia struct {
|
||||
ShortcodeMedia *struct {
|
||||
Type string `json:"__typename"`
|
||||
VideoUrl string `json:"video_url"`
|
||||
Owner struct {
|
||||
Username string `json:"username"`
|
||||
|
@ -19,7 +21,7 @@ type QueryResponse struct {
|
|||
EdgeMediaToCaption struct {
|
||||
Edges []struct {
|
||||
Node struct {
|
||||
Text string `json:"text`
|
||||
Text string `json:"text"`
|
||||
} `json:"node"`
|
||||
} `json:"edges"`
|
||||
} `json:"edge_media_to_caption"`
|
||||
|
@ -34,10 +36,14 @@ type Response struct {
|
|||
}
|
||||
|
||||
func Lookup(urlSrc string) (Response, error) {
|
||||
urlSrcParsed, err := url.Parse(urlSrc)
|
||||
if err != nil {
|
||||
return Response{}, err
|
||||
}
|
||||
|
||||
url, _ := url.Parse("https://www.instagram.com/graphql/query/?query_hash=b3055c01b4b222b8a47dc12b090e4e64")
|
||||
query := url.Query()
|
||||
query.Add("variables", "{\"shortcode\":\""+path.Base(urlSrc)+"\",\"child_comment_count\":3,\"fetch_comment_count\":40,\"parent_comment_count\":24,\"has_threaded_comments\":true}")
|
||||
query.Add("variables", "{\"shortcode\":\""+path.Base(urlSrcParsed.Path)+"\",\"child_comment_count\":3,\"fetch_comment_count\":40,\"parent_comment_count\":24,\"has_threaded_comments\":true}")
|
||||
url.RawQuery = query.Encode()
|
||||
|
||||
resp, err := http.Get(url.String())
|
||||
|
@ -52,6 +58,12 @@ func Lookup(urlSrc string) (Response, error) {
|
|||
if err != nil {
|
||||
return Response{}, err
|
||||
}
|
||||
if response.Data.ShortcodeMedia == nil {
|
||||
return Response{}, errors.New("No encontré el video.")
|
||||
}
|
||||
if response.Data.ShortcodeMedia.Type != "GraphVideo" {
|
||||
return Response{}, errors.New("Esto no es un video.")
|
||||
}
|
||||
return Response{
|
||||
VideoUrl: response.Data.ShortcodeMedia.VideoUrl,
|
||||
Author: response.Data.ShortcodeMedia.Owner.Username,
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"log"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"nulo.in/dlbot/common"
|
||||
|
||||
|
@ -13,10 +14,14 @@ func respond(bot *tgbotapi.BotAPI, update tgbotapi.Update, url *url.URL) common.
|
|||
if url.Hostname() != "instagram.com" && url.Hostname() != "www.instagram.com" {
|
||||
return common.NotValid
|
||||
}
|
||||
if strings.Index(url.Path, "/reel/") != 0 {
|
||||
return common.NotValid
|
||||
}
|
||||
|
||||
log.Printf("Downloading %s", url.String())
|
||||
lookup, err := Lookup(url.String())
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return common.HadError
|
||||
}
|
||||
log.Println(lookup)
|
||||
|
|
Reference in a new issue