Giter Site home page Giter Site logo

Comments (2)

siyosu avatar siyosu commented on May 25, 2024 1

To get media info you need to pass the media id not the media code.
You can get media id using oembed https://i.instagram.com/api/v1/oembed/?url=<the post / reel url>

from instagram-private-api.

yemreak avatar yemreak commented on May 25, 2024

Thank you so much @siyosu!

Here is the my necessary code scripts for who are planning to do similar actions

import fs from "fs"
import path from "path"

async function getIGMediaIdFromURL(url: string): Promise<string> {
	const response = await fetch(`https://i.instagram.com/api/v1/oembed/?url=${url}`)
	const data = await response.json()
	return data.media_id
}

export async function downloadFile(url: string, outputPath: string): Promise<void> {
	const response = await fetch(url)
	if (!response.ok) throw new Error(`Failed to download: ${response.statusText}`)

	const buffer = await response.arrayBuffer()
	fs.writeFileSync(outputPath, Buffer.from(buffer))
}

const mediaId = await getIGMediaIdFromURL(postUrl)
const mediaInfo: any = await ig.media.info(mediaId) // ig comes from "instagram-private-api"
const videoUrl: string = mediaInfo.items[0].video_versions[0].url

const output = path.join("data", `${mediaId}.mp4`)
await downloadFile(videoUrl, output)

from instagram-private-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.