denethdev-ytmp3
v1.0.3
Published
A simple Node.js package to download audio and video from the internet
Readme
YouTube MP3 Downloader
📥 What is YouTube MP3 Downloader NPM?
YouTube MP3 Downloader is an NPM package designed to allow users to easily download YouTube videos and convert them into high-quality MP3 files. With this tool, you can effortlessly grab MP3 audio from YouTube videos using a simple CLI or integrate it into WhatsApp and Telegram bots for automation.
🔧 Easy Integration: Use it with bots (WhatsApp, Telegram)
⚡ Fast Processing: Download MP3s at blazing speeds without losing quality
🖥️ Cross-Platform: Available for macOS, Windows, and Linux.
🛠 Features
- ✅ Fast MP3 Downloading: Convert YouTube videos to MP3 in seconds.
- 🤖 Bot Integration: Easily connect to WhatsApp and Telegram bots to automate MP3 downloads.
- ⚡ Efficient and Fast: Optimized for quick processing without quality loss.
- 🎧 Multiple Bitrates: Save in various bitrates to fit your needs 320kbps.
- 🖥️ Cross-Platform Support: Works on all major operating systems (Windows, macOS, Linux).
🖼️ Preview
Check out how the YouTube MP3 Downloader looks in action:
🧑💻 Owner
- Name: DenethDevᵀᴹ
- Email: [email protected]
🤖 Example WhatsApp Bot Plugin
const { cmd, commands } = require('../command');
const yts = require('yt-search');
const ddownr = require('denethdev-ytmp3'); // Importing the denethdev-ytmp3 package for downloading
cmd({
pattern: "song",
desc: "Download songs.",
category: "download",
react: '🎧',
filename: __filename
}, async (messageHandler, context, quotedMessage, { from, reply, q }) => {
try {
if (!q) return reply("*Please Provide A Song Name or Url 🙄*");
// Search for the song using yt-search
const searchResults = await yts(q);
if (!searchResults || searchResults.videos.length === 0) {
return reply("*No Song Found Matching Your Query 🧐*");
}
const songData = searchResults.videos[0];
const songUrl = songData.url;
// Using denethdev-ytmp3 to fetch the download link
const result = await ddownr.download(songUrl, 'mp3'); // Download in mp3 format
const downloadLink = result.downloadUrl; // Get the download URL
let songDetailsMessage = `*YOUTUBE AUDIO DL*\n\n`;
songDetailsMessage += `*⚜ Title:* ${songData.title}\n`;
songDetailsMessage += `*👀 Views:* ${songData.views}\n`;
songDetailsMessage += `*⏰ Duration:* ${songData.timestamp}\n`;
songDetailsMessage += `*📆 Uploaded:* ${songData.ago}\n`;
songDetailsMessage += `*📽 Channel:* ${songData.author.name}\n`;
songDetailsMessage += `*🖇 URL:* ${songData.url}\n\n`;
songDetailsMessage += `*Choose Your Download Format:*\n\n`;
songDetailsMessage += `1 || Audio File 🎶\n`;
songDetailsMessage += `2 || Document File 📂\n\n`;
songDetailsMessage += `> ᴅᴇɴᴇᴛʜ-ᴍᴅ ʙʏ ᴋɪɴɢ X ᴅᴇɴᴇᴛʜᴅᴇᴠ®`;
// Send the video thumbnail with song details
const sentMessage = await messageHandler.sendMessage(from, {
image: { url: songData.thumbnail },
caption: songDetailsMessage,
}, { quoted: quotedMessage });
// Listen for the user's reply to select the download format
messageHandler.ev.on("messages.upsert", async (update) => {
const message = update.messages[0];
if (!message.message || !message.message.extendedTextMessage) return;
const userReply = message.message.extendedTextMessage.text.trim();
// Handle the download format choice
if (message.message.extendedTextMessage.contextInfo.stanzaId === sentMessage.key.id) {
switch (userReply) {
case '1': // Audio File
await messageHandler.sendMessage(from, {
audio: { url: downloadLink },
mimetype: "audio/mpeg"
}, { quoted: quotedMessage });
break;
case '2': // Document File
await messageHandler.sendMessage(from, {
document: { url: downloadLink },
mimetype: 'audio/mpeg',
fileName: `${songData.title}.mp3`,
caption: `${songData.title}\n\n> ᴅᴇɴᴇᴛʜ-ᴍᴅ ʙʏ ᴋɪɴɢ X ᴅᴇɴᴇᴛʜᴅᴇᴠ®`
}, { quoted: quotedMessage });
break;
default:
reply("*Invalid Option. Please Select A Valid Option 🙄*");
break;
}
}
});
} catch (error) {
console.error(error);
reply("*An Error Occurred While Processing Your Request 😔*");
}
});CREATED BY DENETHDEVᵀᴹ