Update index.js
Browse files
index.js
CHANGED
|
@@ -197,38 +197,41 @@ async function fby2mate(url) {
|
|
| 197 |
}
|
| 198 |
|
| 199 |
async function ytAPI(url) {
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 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 |
|