Update index.js
Browse files
index.js
CHANGED
|
@@ -201,28 +201,6 @@ function bufferToStream(buffer) {
|
|
| 201 |
stream.push(null); // Menandakan akhir dari stream
|
| 202 |
return stream;
|
| 203 |
}
|
| 204 |
-
function convertWebmToMp3(webmBuffer) {
|
| 205 |
-
return new Promise((resolve, reject) => {
|
| 206 |
-
const inputStream = bufferToStream(webmBuffer);
|
| 207 |
-
const outputStream = new PassThrough();
|
| 208 |
-
const chunks = [];
|
| 209 |
-
|
| 210 |
-
ffmpeg(inputStream)
|
| 211 |
-
.inputFormat('webm')
|
| 212 |
-
.audioCodec('libmp3lame')
|
| 213 |
-
.format('mp3')
|
| 214 |
-
.on('data', (chunk) => {
|
| 215 |
-
chunks.push(chunk);
|
| 216 |
-
})
|
| 217 |
-
.on('end', () => {
|
| 218 |
-
resolve(Buffer.concat(chunks));
|
| 219 |
-
})
|
| 220 |
-
.on('error', (err) => {
|
| 221 |
-
reject(err);
|
| 222 |
-
})
|
| 223 |
-
.pipe(outputStream, { end: true });
|
| 224 |
-
});
|
| 225 |
-
}
|
| 226 |
async function streamToBuffer(stream) {
|
| 227 |
const chunks = [];
|
| 228 |
const captureChunks = new Writable({
|
|
@@ -261,9 +239,8 @@ async function ytAPI(url) {
|
|
| 261 |
let audioStream = await ytdl(ID, {filter: "audioonly", quality:"lowestaudio"})
|
| 262 |
let buffermp4 = await streamToBuffer(videoStream)
|
| 263 |
let buffermp3 = await streamToBuffer(audioStream)
|
| 264 |
-
let konvert = await convertWebmToMp3(buffermp3)
|
| 265 |
buffermp4 = await fileDitch(buffermp4)
|
| 266 |
-
buffermp3 = await fileDitch(
|
| 267 |
return {
|
| 268 |
mp4_url: buffermp4,
|
| 269 |
mp3_url: buffermp3,
|
|
|
|
| 201 |
stream.push(null); // Menandakan akhir dari stream
|
| 202 |
return stream;
|
| 203 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
async function streamToBuffer(stream) {
|
| 205 |
const chunks = [];
|
| 206 |
const captureChunks = new Writable({
|
|
|
|
| 239 |
let audioStream = await ytdl(ID, {filter: "audioonly", quality:"lowestaudio"})
|
| 240 |
let buffermp4 = await streamToBuffer(videoStream)
|
| 241 |
let buffermp3 = await streamToBuffer(audioStream)
|
|
|
|
| 242 |
buffermp4 = await fileDitch(buffermp4)
|
| 243 |
+
buffermp3 = await fileDitch(buffermp3)
|
| 244 |
return {
|
| 245 |
mp4_url: buffermp4,
|
| 246 |
mp3_url: buffermp3,
|