Electronode is an Electron App that uses electron-handlebars, Bootstrap v4.3 and Vanilla JS to download songs.
- Download or clone the repo.
- Surf into the directory where Electronode is located.
> npm install
> electron src/index
- Enjoy it!
The main process renders mainWindow
and loads the first HBS file. There we have a two input form that helps us to create the YouTube Query.
let youtubeQuery = "input1 + input2";
then we load this into a Browser Window. And load the whole query like this:
youtubeWin.loadURL(`https://www.youtube.com/results?search_query=${youtubeQuery}`);
I preload a script on that youtubeWin
so it picks the first <a>
HTML tag on which his href attribute contains his YouTube video id.
And why is this important? This is our main piece to consume the Youtube To Mp3 Download API. This is a little example of the request.
const getRequest = (songId) => {
var req = http.request(
{
"method": "GET",
"hostname": "coolguruji-youtube-to-mp3-download-v1.p.rapidapi.com",
"port": null,
"path": `/?id=${songId}`,
"headers": {
"x-rapidapi-host": "coolguruji-youtube-to-mp3-download-v1.p.rapidapi.com",
"x-rapidapi-key": "yourAPIkey"
}
}, (res) => {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
mainWindow.webContents.send('data', JSON.parse(body.toString()));
});
});
req.end();
}
Then you can see that I send this response from our main process to our mainWindow because the response is actually HTML code that I'm trying to append to the code.