Last active
January 6, 2023 22:39
-
-
Save paulwongx/dfcd511db3beb22c6e67914944fd3f28 to your computer and use it in GitHub Desktop.
Download Youtube mp3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ytdl from "ytdl-core"; | |
import fs from "fs"; | |
import ffmpeg from "fluent-ffmpeg"; | |
import readline from "readline"; | |
// https://github.com/fent/node-ytdl-core/blob/master/example/convert_to_mp3.js | |
const id = 'nMfPqeZjc2c'; | |
let stream = ytdl(id, { | |
quality: 'highestaudio', | |
}); | |
let start = Date.now(); | |
ffmpeg(stream) | |
.audioBitrate(128) | |
.save(`${__dirname}/${id}.mp3`) | |
.on('progress', (p:any) => { | |
readline.cursorTo(process.stdout, 0); | |
process.stdout.write(`${p.targetSize}kb downloaded`); | |
}) | |
.on('end', () => { | |
console.log(`\ndone, thanks - ${(Date.now() - start) / 1000}s`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment