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

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +37 -34
index.js CHANGED
@@ -195,48 +195,51 @@ async function fby2mate(url) {
195
  }
196
  }
197
 
198
- const { exec } = require('@distube/yt-dlp');
 
199
 
 
 
 
 
 
 
200
  async function ytAPI(url) {
201
- try {
202
- // Eksekusi yt-dlp untuk mendapatkan informasi video
203
- const { stdout, stderr } = await exec(url, ['--dump-json']);
204
-
205
- // Handle output
206
- const info = JSON.parse(stdout);
207
-
208
- // Extract necessary information
209
- const videoDetails = {
210
- title: info.title,
211
- url: url,
212
- formats: info.formats.map(format => ({
213
- format_id: format.format_id,
214
- ext: format.ext,
215
- resolution: format.resolution,
216
- url: format.url
217
- }))
218
- };
219
 
220
- // Filter MP4 and MP3 formats
221
- const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4');
222
- const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
223
 
224
- const result = {
225
- title: videoDetails.title,
226
- url: videoDetails.url,
227
- mp4Url: mp4Format ? mp4Format.url : null,
228
- mp3Url: mp3Format ? mp3Format.url : null
229
- };
230
 
231
- return result;
232
- } catch (error) {
233
- console.error('Error fetching video info:', error);
234
- throw error;
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 = {