Update index.js
Browse files196 unmodified lines197198199200201202200201202203204205206207208209210211212213214203204205206207208209210211212213214215216217218216217218219220221222220221222223224225223224225226227228229227228229230231230231232233234235236237196 unmodified lines}
async function ytAPI(url) { try { // Fetch the video info const info = await ytdlp.exec(url, ['--dump-json']); try { // Fetch the video info const info = await ytdlp.getInfo(url);
// Extract necessary information const videoDetails = { title: info.title, url: url, formats: info.formats.map(format => ({ format_id: format.format_id, ext: format.ext, resolution: format.resolution, url: format.url })) };
// Parse the JSON data const videoData = JSON.parse(info);
// Extract necessary information const videoDetails = { title: videoData.title, url: url, formats: videoData.formats.map(format => ({ format_id: format.format_id, ext: format.ext, resolution: format.resolution, url: format.url })) };
// Filter MP4 and MP3 formats const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4'); const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3'); // Filter MP4 and MP3 formats const mp4Format = videoDetails.formats.find(format => format.ext === 'mp4'); const mp3Format = videoDetails.formats.find(format => format.ext === 'mp3');
const result = { title: videoDetails.title, url: videoDetails.url, mp4Url: mp4Format ? mp4Format.url : null, mp3Url: mp3Format ? mp3Format.url : null }; const result = { title: videoDetails.title, url: videoDetails.url, mp4Url: mp4Format ? mp4Format.url : null, mp3Url: mp3Format ? mp3Format.url : null };
return result; } catch (error) { console.error('Error fetching video info:', error); throw error; } return result; } catch (error) { console.error('Error fetching video info:', error); throw error; }}
index.js+32-29