Update index.js
Browse files
index.js
CHANGED
|
@@ -195,48 +195,51 @@ async function fby2mate(url) {
|
|
| 195 |
}
|
| 196 |
}
|
| 197 |
|
| 198 |
-
const {
|
|
|
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
async function ytAPI(url) {
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
url: format.url
|
| 217 |
-
}))
|
| 218 |
-
};
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
}
|
| 237 |
|
| 238 |
|
| 239 |
-
|
| 240 |
// Fungsi untuk mengkonversi video dari YouTube
|
| 241 |
const convert = async (url, v_id, ftype, fquality, fname, token, timeExpire) => {
|
| 242 |
let params = {
|
|
|
|
| 195 |
}
|
| 196 |
}
|
| 197 |
|
| 198 |
+
const { DisTube } = require("distube");
|
| 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 |
+
// Gunakan DisTube untuk mencari lagu dari URL
|
| 210 |
+
const songInfo = await distube.search(url);
|
| 211 |
+
|
| 212 |
+
// Dapatkan detail video
|
| 213 |
+
const videoDetails = {
|
| 214 |
+
title: songInfo.title,
|
| 215 |
+
url: songInfo.url,
|
| 216 |
+
formats: songInfo.formats.map(format => ({
|
| 217 |
+
format_id: format.format_id,
|
| 218 |
+
ext: format.ext,
|
| 219 |
+
resolution: format.resolution,
|
| 220 |
+
url: format.url
|
| 221 |
+
}))
|
| 222 |
+
};
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
+
// Filter format MP4 dan MP3
|
| 225 |
+
const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4');
|
| 226 |
+
const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
|
| 227 |
|
| 228 |
+
const result = {
|
| 229 |
+
title: videoDetails.title,
|
| 230 |
+
url: videoDetails.url,
|
| 231 |
+
mp4Url: mp4Format ? mp4Format.url : null,
|
| 232 |
+
mp3Url: mp3Format ? mp3Format.url : null
|
| 233 |
+
};
|
| 234 |
|
| 235 |
+
return result;
|
| 236 |
+
} catch (error) {
|
| 237 |
+
console.error('Error fetching video info:', error);
|
| 238 |
+
throw error;
|
| 239 |
+
}
|
| 240 |
}
|
| 241 |
|
| 242 |
|
|
|
|
| 243 |
// Fungsi untuk mengkonversi video dari YouTube
|
| 244 |
const convert = async (url, v_id, ftype, fquality, fname, token, timeExpire) => {
|
| 245 |
let params = {
|