Skip to content

Instantly share code, notes, and snippets.

@ahmdrz
Last active March 12, 2025 08:11
Show Gist options
  • Save ahmdrz/4e5bdcd3891af25560fbbfae4d74d725 to your computer and use it in GitHub Desktop.
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.
// 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)
}
@mcgdonal
Copy link

mcgdonal commented Mar 9, 2025

Yeah, Telegram works, but if you want a quicker way without sharing it anywhere, try anonyig Just paste the link and download instantly, no login needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment