const YoutubeMp3Downloader = require("youtube-mp3-downloader"); // Configure the downloader const downloader = new YoutubeMp3Downloader({ outputPath: "./downloads", // Where the MP3s will go youtubeVideoQuality: "highest", // Video quality to fetch audio from queueParallelism: 2, // How many downloads at once progressTimeout: 2000, // How often to emit 'progress' allowWebm: false // Prefer mp4 audio streams }); Here is how you download a file. You will need the YouTube Video ID (the string after ?v= in the URL).
node index.js Check your ./downloads folder—you should see your new MP3 file ready to play. 1. Extracting the Video ID from a URL Don't ask users to type the ID manually. Add this helper: youtube-mp3-downloader npm
// Event: When download starts downloader.on("start", (data) => { console.log( Starting download: ${data.videoId} ); }); If you are downloading hundreds of files, set
const downloader = new YoutubeMp3Downloader({ outputPath: "./mp3s", youtubeVideoQuality: "highestaudio", }); If you need metadata
function getVideoId(url) { const urlParams = new URLSearchParams(new URL(url).search); return urlParams.get('v'); } const userUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"; const id = getVideoId(userUrl); The queueParallelism option is vital. If you are downloading hundreds of files, set this to 1 or 2 to avoid being rate-limited or banned by YouTube. 3. Custom MP3 Metadata The base package does not add ID3 tags (Artist, Album Art). If you need metadata, consider combining this with the node-id3 package after the finished event fires. ⚠️ Legal Disclaimer (Important!) Please read this before using the tool commercially or publicly.
// Example: Video URL: https://www.youtube.com/watch?v=abc123DEF const videoId = "abc123DEF"; const fileName = "My_Song_Name.mp3"; downloader.download(videoId, fileName);
Clone the repo and convert your first video today. README.md snippet for GitHub (Short version) If you are writing documentation for your repository that uses this package: