ilhamdev commited on
Commit
b12ee53
·
verified ·
1 Parent(s): ac64ba5

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +16 -15
index.js CHANGED
@@ -195,25 +195,26 @@ async function fby2mate(url) {
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,
@@ -221,7 +222,7 @@ async function ytAPI(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
 
 
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