media-downloader-ez
v2.1.9
Published
download videos from URLs and autocrop (Instagram, YouTube, TikTok, X, etc.) to send directly to Discord or other!
Maintainers
Readme
media-downloader-ez
A simple npm package to download videos from various platforms, including Instagram, YouTube, TikTok, X/Twitter, and more.
Features
- AutoCompress: Automatically compress videos with a size limit.
- AutoCrop: Automatically crop videos to remove black bars.
- Rotate: Rotate the video left or right.
Supported Platforms
- TikTok
- Twitter (X)
- YouTube
- Google Drive
- CapCut
- Likee
- Threads
- Mediafire
Note: Some Instagram posts/reels/stories can fail with the default extractor. This package includes an alternate Instagram method called "option3" (uses instagramcustom.js) that you can force when needed.
Basic Example
const MediaDownloader = require('media-downloader-ez');
let url = "http://";
MediaDownloader(url, {
autocrop: true, // Automatically crop black bars (useful for TikTok, Instagram videos)
limitSizeMB: "10", // Maximum size limit in MB
rotation: null, // Rotate video: "right", "left", or null
useInstaOption3: false // Set to true to force the custom Instagram downloader
});Example for Discord.js
const MediaDownloader = require('media-downloader-ez');
const Discord = require('discord.js-v11-stable');
const client = new Discord.Client({
disableEveryone: true
});
client.on('message', async (message) => {
try {
if (message.content.startsWith('!download') && message.content.includes('http')) {
let attachment = await MediaDownloader(message.content, {
autocrop: true,
limitSizeMB: "10"
});
message.channel.send({ content: `Downloaded by: \`${message.author.username}\``, files: [attachment] });
}
} catch (error) {
console.error('Error downloading video:', error);
message.reply('An error occurred while downloading the video.').then((m) => { m.delete(); });
}
});
client.login("your token").catch((err) => {
console.log('INCORRECT TOKEN LOGIN!');
});Note: Keep your Discord bot token private and secure.
YouTube Download and Get Cookie
To download YouTube videos requiring authentication, follow these steps:
- Open youtube.com in your browser.
- Press
CTRL + SHIFT + I(or right-click → Inspect). - Open the Console tab.
- In the console, type:
and press Enter. (This allows pasting commands into the console.)allow pasting - Then, type:
copy(document.cookie) - Your cookie will now be copied to your clipboard. Paste it into your script where required.
Example with YouTube Cookie
const MediaDownloader = require('media-downloader-ez');
let url = "http://";
let cookie = "your_cookie_here";
MediaDownloader(url, {
YTBcookie: cookie, // YouTube cookie
YTBmaxduration: 80, // Maximum duration in seconds
autocrop: true, // Automatically crop black bars
limitSizeMB: "10", // Maximum size limit in MB
rotation: null // Rotate video: "right", "left", or null
});Only Safe Links Example
if (MediaDownloader.isVideoLink(url)) {
let attachment = await MediaDownloader(url, {
autocrop: true,
limitSizeMB: "10",
rotation: "left" // or "right" or null
});
}