ilhamdev commited on
Commit
66e4214
·
verified ·
1 Parent(s): dd53a35

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +32 -29
index.js CHANGED
@@ -197,38 +197,41 @@ async function fby2mate(url) {
197
  }
198
 
199
  async function ytAPI(url) {
200
- try {
201
- // Fetch the video info
202
- const info = await ytdlp.getInfo(url);
203
-
204
- // Extract necessary information
205
- const videoDetails = {
206
- title: info.title,
207
- url: url,
208
- formats: info.formats.map(format => ({
209
- format_id: format.format_id,
210
- ext: format.ext,
211
- resolution: format.resolution,
212
- url: format.url
213
- }))
214
- };
 
 
 
215
 
216
- // Filter MP4 and MP3 formats
217
- const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4');
218
- const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
219
 
220
- const result = {
221
- title: videoDetails.title,
222
- url: videoDetails.url,
223
- mp4Url: mp4Format ? mp4Format.url : null,
224
- mp3Url: mp3Format ? mp3Format.url : null
225
- };
226
 
227
- return result;
228
- } catch (error) {
229
- console.error('Error fetching video info:', error);
230
- throw error;
231
- }
232
  }
233
 
234
 
 
197
  }
198
 
199
  async function ytAPI(url) {
200
+ try {
201
+ // Fetch the video info
202
+ const info = await ytdlp.exec(url, ['--dump-json']);
203
+
204
+ // Parse the JSON data
205
+ const videoData = JSON.parse(info);
206
+
207
+ // Extract necessary information
208
+ const videoDetails = {
209
+ title: videoData.title,
210
+ url: url,
211
+ formats: videoData.formats.map(format => ({
212
+ format_id: format.format_id,
213
+ ext: format.ext,
214
+ resolution: format.resolution,
215
+ url: format.url
216
+ }))
217
+ };
218
 
219
+ // Filter MP4 and MP3 formats
220
+ const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4');
221
+ const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
222
 
223
+ const result = {
224
+ title: videoDetails.title,
225
+ url: videoDetails.url,
226
+ mp4Url: mp4Format ? mp4Format.url : null,
227
+ mp3Url: mp3Format ? mp3Format.url : null
228
+ };
229
 
230
+ return result;
231
+ } catch (error) {
232
+ console.error('Error fetching video info:', error);
233
+ throw error;
234
+ }
235
  }
236
 
237