Update index.js
Browse files
index.js
CHANGED
|
@@ -195,46 +195,52 @@ async function fby2mate(url) {
|
|
| 195 |
}
|
| 196 |
}
|
| 197 |
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
noCheckCertificates: true,
|
| 206 |
-
noWarnings: true,
|
| 207 |
-
preferFreeFormats: true,
|
| 208 |
-
addHeader: ['referer:youtube.com', 'user-agent:googlebot']
|
| 209 |
});
|
|
|
|
|
|
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
resolution: format.resolution,
|
| 219 |
-
url: format.url
|
| 220 |
-
}))
|
| 221 |
-
};
|
| 222 |
-
|
| 223 |
-
// Filter MP4 and MP3 formats
|
| 224 |
-
const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4');
|
| 225 |
-
const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
|
| 226 |
|
| 227 |
-
|
| 228 |
-
title: videoDetails.title,
|
| 229 |
-
url: videoDetails.url,
|
| 230 |
-
mp4Url: mp4Format ? mp4Format.url : null,
|
| 231 |
-
mp3Url: mp3Format ? mp3Format.url : null
|
| 232 |
-
};
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
}
|
| 239 |
}
|
| 240 |
|
|
|
|
| 195 |
}
|
| 196 |
}
|
| 197 |
|
| 198 |
+
async function streamToBuffer(stream) {
|
| 199 |
+
const chunks = [];
|
| 200 |
+
const captureChunks = new Writable({
|
| 201 |
+
write(chunk, encoding, callback) {
|
| 202 |
+
chunks.push(chunk);
|
| 203 |
+
callback();
|
| 204 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
});
|
| 206 |
+
|
| 207 |
+
await util.promisify(pipeline)(stream, captureChunks);
|
| 208 |
|
| 209 |
+
return Buffer.concat(chunks);
|
| 210 |
+
}
|
| 211 |
+
const fileDitch : async (media) => {
|
| 212 |
+
return new Promise(async (resolve, reject) => {
|
| 213 |
+
let {fileTypeFromBuffer} = await (await import('file-type'))
|
| 214 |
+
let mime = await fileTypeFromBuffer(media)
|
| 215 |
+
let form = new FormData()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
+
form.append("files[]", media, `file-${new Date().getTime()}.${mime.ext}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
|
| 219 |
+
axios.post("https://up1.fileditch.com/upload.php", form, {
|
| 220 |
+
headers: {
|
| 221 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0",
|
| 222 |
+
...form.getHeaders()
|
| 223 |
+
}
|
| 224 |
+
}).then(({ data }) => resolve(data?.files[0]?.url)).catch(reject)
|
| 225 |
+
})
|
| 226 |
+
//https://up1.fileditch.com/upload.php
|
| 227 |
+
}
|
| 228 |
+
async function ytAPI(url) {
|
| 229 |
+
try {
|
| 230 |
+
const ID = ytdl.getVideoID(url),
|
| 231 |
+
const videoStream = await ytdl(ID, { filter: 'audioandvideo', quality: 'highestvideo' });
|
| 232 |
+
const audioStream = await ytdl(ID, {filter: "audioonly", quality:"lowestaudio"})
|
| 233 |
+
let buffermp4 = await streamToBuffer(videoStream)
|
| 234 |
+
let buffermp3 = await streamToBuffer(audioStream)
|
| 235 |
+
buffermp4 = await fileDitch(buffermp4)
|
| 236 |
+
buffermp3 = await fileDitch(buffermp3)
|
| 237 |
+
return {
|
| 238 |
+
mp4_url: buffermp4,
|
| 239 |
+
mp3_url: buffermp3,
|
| 240 |
+
}
|
| 241 |
+
} catch (err) {
|
| 242 |
+
console.error('Error occurred:', err);
|
| 243 |
+
return null;
|
| 244 |
}
|
| 245 |
}
|
| 246 |
|