Last active
August 22, 2022 12:31
-
-
Save ahmdrz/4e5bdcd3891af25560fbbfae4d74d725 to your computer and use it in GitHub Desktop.
Want to download instagram videos ? Why not using telegram ? Share it to a user and receive it on telegram.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test project main.go | |
package main | |
import ( | |
"fmt" | |
"net/http" | |
"strconv" | |
"time" | |
"net/url" | |
"github.com/ahmdrz/goinsta" | |
) | |
const AcceptedThread = "---" //which one of your direct threads ? enter the title of the thread here | |
const GroupID = 12345678 //which chat in telegram ? enter the chat id in this field | |
const Token = "token" //what is your robot token in telegram ? | |
const InstaUsername = "username" //instagram username | |
const InstaPassword = "password" //instagram password | |
const ScanTime = 60 //time in second for scanning instagram direct | |
type Scanner struct { | |
*goinsta.Instagram | |
} | |
func (insta Scanner) Scan() { | |
result, _ := insta.GetRankedRecipients() | |
for _, threadItem := range result.RankedRecipients { | |
item := threadItem.Thread | |
if item.ThreadTitle == AcceptedThread { | |
thread, err := insta.GetDirectThread(item.ThreadID) | |
if err != nil { | |
fmt.Println(item.ThreadID, "errored") | |
} else { | |
for _, item := range thread.Thread.Items { | |
if len(item.MediaShare.VideoVersions) == 0 { | |
continue | |
} | |
itemtime := item.Timestamp / 1000000 | |
if time.Now().Unix()-itemtime > ScanTime { | |
continue | |
} | |
if len(item.MediaShare.VideoVersions) > 0 { | |
video := item.MediaShare.VideoVersions[len(item.MediaShare.VideoVersions)-1] | |
caption := AcceptedThread + " - " + item.MediaShare.Caption.Text | |
if len(caption) > 200 { | |
caption = caption[:200] | |
} | |
SendVideo(video.URL, caption) | |
} | |
} | |
} | |
} | |
} | |
} | |
func main() { | |
insta := goinsta.New(InstaUsername, InstaPassword) | |
err := insta.Login() | |
if err != nil { | |
panic(err) | |
} | |
defer insta.Logout() | |
scanner := Scanner{insta} | |
for { | |
scanner.Scan() | |
time.Sleep(ScanTime * time.Second) | |
} | |
} | |
func SendVideo(link string, caption string) { | |
val := url.Values{} | |
val.Set("chat_id", strconv.FormatInt(GroupID, 10)) | |
val.Set("video", link) | |
val.Set("caption", caption) | |
api := "https://api.telegram.org/bot" + Token + "/sendVideo?" + val.Encode() | |
fmt.Println(api) | |
r, err := http.NewRequest("POST", api, nil) | |
if err != nil { | |
return | |
} | |
client := http.Client{} | |
client.Do(r) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment