Home > Software design >  Download an instagram video from URL
Download an instagram video from URL

Time:10-11

I have a bot which ive been wanting to add a feature where a user inputs an instagram link and it returns the downloaded media from the post. The issue is i have no idea how to get the video link to download it.

I've tried using the Instagram download packages from npm however they usually end up not returning anything. I've also tried fetching the web page however the page isn't static so requesting the HTML doesn't give me any useful data. Another option I've tried is to look through inspect element on the website to find anything useful that could help but after a while, I ended up not finding anything useful that i could access from code.

Any help or idea would be good as ive tried about anything i can think of.

CodePudding user response:

Maybe this could work? https://developers.facebook.com/docs/instagram-api/reference/ig-media

You would have to use the Instagram Graph API for this.

CodePudding user response:

Maybe you could try one of the products on rapidapi under the search for an 'instagram media downloader' and go from there?

I found this one that might be able to help you: https://rapidapi.com/arraybobo/api/instagram-media-downloader/

CodePudding user response:

Short answer:

  1. Have an instagram account without 2FA.

  2. Install gallery-dl:

sudo apt update && sudo snap install gallery-dl
  1. Download the resource:
gallery-dl -g -u "<username>" -p "<password>" "https://www.instagram.com/p/CUU9-FFFaE5/"

Write some Node.js code which will execute that command asyncronously like this or in other way:

const command = `gallery-dl -g -u "${user}" -p "${pass}" "${url}"`;
exec(command, async (err, stdout, stderr) => {
    if (err) {
        // getting the err.message
    } else {
        // use the downloaded file name/path to do your stuff
    }
});

Personal thoughts:

At first I will not recommend to do that in non official way, but apart from that, theoretically you can do it in 2 ways: getting the media with tool like gallery-dl or some other alternative tool that you want to work with, or just parsing it for your own (I've worked on parsing it via Node.js snippet about 3 years ago, and in that moment Instagram have been changing their API policy or something like that, so i don't actually remember the way i did that).

Actually in some point both ways are the same, they're just grabbing the data, but anyway.. you can have some account on instagram only for doing that parsing without any multi-factor authentication, and use gallery-dl.

  • Related