Update index.js
Browse files
index.js
CHANGED
|
@@ -195,25 +195,26 @@ async function fby2mate(url) {
|
|
| 195 |
}
|
| 196 |
}
|
| 197 |
|
| 198 |
-
const
|
| 199 |
-
const { YtDlpPlugin } = require("@distube/yt-dlp");
|
| 200 |
|
| 201 |
-
// Inisialisasi DisTube dengan plugin YtDlpPlugin
|
| 202 |
-
const distube = new DisTube(client, {
|
| 203 |
-
plugins: [new YtDlpPlugin({ update: true })],
|
| 204 |
-
});
|
| 205 |
-
|
| 206 |
-
// Fungsi untuk mendapatkan informasi video dari URL
|
| 207 |
async function ytAPI(url) {
|
| 208 |
try {
|
| 209 |
-
//
|
| 210 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
-
//
|
| 213 |
const videoDetails = {
|
| 214 |
-
title:
|
| 215 |
-
url:
|
| 216 |
-
formats:
|
| 217 |
format_id: format.format_id,
|
| 218 |
ext: format.ext,
|
| 219 |
resolution: format.resolution,
|
|
@@ -221,7 +222,7 @@ async function ytAPI(url) {
|
|
| 221 |
}))
|
| 222 |
};
|
| 223 |
|
| 224 |
-
// Filter
|
| 225 |
const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4');
|
| 226 |
const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
|
| 227 |
|
|
|
|
| 195 |
}
|
| 196 |
}
|
| 197 |
|
| 198 |
+
const youtubedl = require('youtube-dl-exec');
|
|
|
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
async function ytAPI(url) {
|
| 201 |
try {
|
| 202 |
+
// Execute youtube-dl to get video information
|
| 203 |
+
const output = await youtubedl(url, {
|
| 204 |
+
dumpSingleJson: true,
|
| 205 |
+
noCheckCertificates: true,
|
| 206 |
+
noWarnings: true,
|
| 207 |
+
preferFreeFormats: true,
|
| 208 |
+
addHeader: ['referer:youtube.com', 'user-agent:googlebot']
|
| 209 |
+
});
|
| 210 |
+
|
| 211 |
+
const info = JSON.parse(output);
|
| 212 |
|
| 213 |
+
// Extract necessary information
|
| 214 |
const videoDetails = {
|
| 215 |
+
title: info.title,
|
| 216 |
+
url: url,
|
| 217 |
+
formats: info.formats.map(format => ({
|
| 218 |
format_id: format.format_id,
|
| 219 |
ext: format.ext,
|
| 220 |
resolution: format.resolution,
|
|
|
|
| 222 |
}))
|
| 223 |
};
|
| 224 |
|
| 225 |
+
// Filter MP4 and MP3 formats
|
| 226 |
const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4');
|
| 227 |
const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
|
| 228 |
|