I am new to coding and am trying to figure out how to link a javascript function to an HTML button. I am trying to create a YouTube to MP3 converter for personal use. I am using the npm install youtube-mp3-downloader --save library. Below is the code:
var YoutubeMp3Downloader = require("youtube-mp3-downloader");
//Configure YoutubeMp3Downloader with your settings
var YD = new YoutubeMp3Downloader({
"ffmpegPath": "/usr/local/bin/ffmpeg", // FFmpeg binary location
"outputPath": "*output path*", // Output file location (default: the home directory)
"youtubeVideoQuality": "highestaudio", // Desired video quality (default: highestaudio)
"queueParallelism": 2, // Download parallelism (default: 1)
"progressTimeout": 2000, // Interval in ms for the progress reports (default: 1000)
"allowWebm": false // Enable download from WebM sources (default: false)
});
//Download video and save as MP3 file
YD.download("jNQXAC9IVRw");
YD.on("finished", function(err, data) {
console.log(JSON.stringify(data));
});
YD.on("error", function(error) {
console.log(error);
});
YD.on("progress", function(progress) {
console.log(JSON.stringify(progress));
});
<h1 class="heading">YouTube Downloader</h1>
<input class="URL-input" placeholder="Paste the letters between = and & of YouTube URL">
<button class="YD.download(jNQXAC9IVRw)">Convert</button>
I am trying to link the YD.download function to the convert button. Any suggestions would be appreciated. Thank you.