Skip to content

rozelrosel-dotcom/bug-free-meta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📥 Instagram-Downloader

A simple Node.js project to download Instagram media (images and videos) using Axios and Cheerio. This tool fetches metadata from Instagram posts/reels and downloads the media files locally.


🗂 Project Structure

Instagram-Downloader/
├─ index.js              # Entry point: example usage of the downloader
├─ test.js               # Main module handling Instagram media download
├─ LICENSE               # BSD 3-Clause License
├─ README.md             # Project readme and contact info
├─ package.json          # Node.js project metadata & dependencies

⚡ Features

  • ✅ Download Instagram images and videos using the post URL
  • ✅ Automatically fetch metadata: title, description, thumbnail, and media type
  • ✅ Save files locally with proper file paths
  • ✅ Simple and reusable functions for integration in other projects
  • ✅ Supports Instagram reels and standard posts

📦 Dependencies

  • axios → For HTTP requests
  • cheerio → For parsing HTML
  • fs → For file system operations
  • path → For handling file paths

Install dependencies with:

npm install axios cheerio

📝 Usage Example

const instagram_download = require("./test");

(async () => {
  const value = await instagram_download.downloadMedia(
    "https://www.instagram.com/reel/DADNc8DimE8/?igsh=MXFwZzN2MmJwODV2cw==",
    "./"
  );
  console.log(value);
})();

Sample Output:

{
  "file": "/Users/user/Downloads/DADNc8DimE8.mp4",
  "type": "Video",
  "thumbnail": "/Users/user/Downloads/DADNc8DimE8-thumb.jpg"
}

📚 Detailed Functions

1️⃣ createNewUrl(oriUrl)

  • Description: Appends ?__a=1 to the Instagram URL to get JSON metadata.

  • Parameters:

    • oriUrl (string): Original Instagram URL
  • Returns: New URL string

Example:

const newUrl = createNewUrl("https://www.instagram.com/p/abc123/");
console.log(newUrl); // https://www.instagram.com/p/abc123/?__a=1

2️⃣ getMediaType(mediaData)

  • Description: Determines if the media is an image or video.

  • Parameters:

    • mediaData (object): Metadata object from Instagram
  • Returns: "image" | "video"


3️⃣ downloadMetaData(url)

  • Description: Fetches Instagram post metadata using Axios and Cheerio.

  • Parameters:

    • url (string): Instagram post URL
  • Returns: Object containing metadata

Metadata Fields:

Field Type Description
description string Instagram post description
url string Direct media URL
thumbnail string Thumbnail image URL
title string Title of the post
is_video boolean True if media is video, false if image

4️⃣ download(url, filename, savePath)

  • Description: Downloads media file from the given URL and saves it to disk.

  • Parameters:

    • url (string): Media file URL
    • filename (string): Name for the saved file
    • savePath (string): Directory to save the file
  • Returns: Promise resolving on successful download


5️⃣ downloadMedia(url, savePath)

  • Description: Main function to download Instagram media (image/video) with metadata.

  • Parameters:

    • url (string): Instagram post URL
    • savePath (string): Directory to save the media
  • Returns: DownlodResult object

DownlodResult Fields:

Field Type Description
file string Absolute path to downloaded file
type string "Image" or "Video"
thumbnail string Path to thumbnail (only for video)

Example:

const result = await downloadMedia("https://www.instagram.com/p/abc123/", "./media");
console.log(result);
/*
{
  file: '/media/abc123.mp4',
  type: 'Video',
  thumbnail: '/media/abc123-thumb.jpg'
}
*/

🛠 How It Works

  1. Transform URL: createNewUrl() adds ?__a=1 to get JSON from Instagram.
  2. Fetch Metadata: downloadMetaData() scrapes description, media URL, and thumbnail.
  3. Determine Media Type: getMediaType() checks if it's video or image.
  4. Download Media: download() streams the media content to local disk.
  5. Return Paths: downloadMedia() returns file paths and type for further use.

💾 Database / Storage

This project does not use a database. Media files are saved directly to the local filesystem.

File Example Structure on Disk:

./media/
├─ abc123.jpg             # Image post
├─ xyz456.mp4             # Video post
├─ xyz456-thumb.jpg       # Video thumbnail

🔧 License

This project is released under BSD 3-Clause License. See the LICENSE file for details.


📞 Contact / Social Links


⚡ Notes

  • This downloader works on public Instagram posts only.
  • Video posts download both the video and thumbnail automatically.
  • All paths returned by downloadMedia are absolute paths for easy integration.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors