Skip to content

Instantly share code, notes, and snippets.

@ZTRdiamond
Last active January 31, 2025 17:59
Show Gist options
  • Select an option

  • Save ZTRdiamond/b4250b5808416ec3ebfb90bb0b6874c3 to your computer and use it in GitHub Desktop.

Select an option

Save ZTRdiamond/b4250b5808416ec3ebfb90bb0b6874c3 to your computer and use it in GitHub Desktop.
Instagram downloader scrape!
import axios from "axios";
/*
Created by https://github.com/ztrdiamond !
Source: https://whatsapp.com/channel/0029VagFeoY9cDDa9ulpwM0T
"Aku janji jika hapus watermark ini maka aku rela miskin hingga 7 turunan"
*/
async function igdl(url) {
try {
return await new Promise(async(resolve, reject) => {
if(!/^https?:\/\/(?:www\.)?instagram\.com\/(?:p|reel|tv)\/[a-zA-Z0-9_-]+\/?.*/.test(url)) reject("invalid url input!");
const headers = { headers: { contentType: "application/json", origin: "https://publer.io", referer: "https://publer.io/" }};
axios.post("https://app.publer.io/hooks/media", {
iphone: false,
url
}, headers).then(async res => {
const task_id = res.data.job_id;
const task = async() => (await axios.get("https://app.publer.io/api/v1/job_status/" + task_id, headers)).data;
async function process() {
const { status, payload } = await task()
if(status === "complete") {
if(payload[0].error) return reject(payload[0].error)
const media = payload.map(d => ({
type: d.type,
url: d.path,
thumb: d.thumbnail
}))
return resolve({
success: true,
media
})
}
setTimeout(process, 1000);
}
await process()
}).catch(e => reject(e))
})
} catch (e) {
return {
success: false,
errors: [e]
}
}
}
export default igdl;
@ZTRdiamond
Copy link
Author

Usage:

igdl("https://www.instagram.com/p/C9y1bHDS6mg")
  .then(console.log)
  .catch(console.log)

Output:

{
  success: true,
  media: [
    {
      type: 'photo',
      url: 'https://app.publer.io/uploads/tmp/1725872643-497431628809507-2434-4601/mini_magick20240909-29274-alwcp7.jpg',
      thumb: 'https://app.publer.io/uploads/tmp/1725872643-497431628809507-2434-4601/mini_magick20240909-29274-alwcp7.jpg'
    },
    {
      type: 'photo',
      url: 'https://app.publer.io/uploads/tmp/1725872644-941434809886158-2435-0041/mini_magick20240909-29274-5e3x7j.jpg',
      thumb: 'https://app.publer.io/uploads/tmp/1725872644-941434809886158-2435-0041/mini_magick20240909-29274-5e3x7j.jpg'
    }
  ]
}

Error:

{
  success: Boolean,
  errors: [String]
}

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