descargas-ig.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import fetch from 'node-fetch';
  2. import axios from 'axios';
  3. import {instagramdl} from '@bochilteam/scraper';
  4. import {fileTypeFromBuffer} from 'file-type';
  5. const handler = async (m, {conn, args, command, usedPrefix}) => {
  6. const datas = global
  7. if (!args[0]) throw `⚠️ Ingresa el enlace del vídeo de Instagram junto al comando.\n\nEjemplo: *${usedPrefix + command}* https://www.instagram.com/p/C60xXk3J-sb/?igsh=YzljYTk1ODg3Zg==`
  8. await m.react('⌛')
  9. try {
  10. const res = await fetch(`https://api.siputzx.my.id/api/d/igdl?url=${args}`);
  11. const data = await res.json();
  12. const fileType = data.data[0].url.includes('.webp') ? 'image' : 'video';
  13. const downloadUrl = data.data[0].url;
  14. if (fileType === 'image') {
  15. await conn.sendFile(m.chat, downloadUrl, 'ig.jpg', '_*Aqui tiene tu imagen de Instagram*', m, null, fake);
  16. m.react('✅');
  17. } else if (fileType === 'video') {
  18. await conn.sendFile(m.chat, downloadUrl, 'ig.mp4', '*Aqui esta el video de Instagram*', m, null, fake);
  19. m.react('✅');
  20. }
  21. } catch {
  22. try {
  23. const res = await fetch(`${APIs.fgmods.url}/downloader/igdl?url=${args}&apikey=${APIs.fgmods.key}`);
  24. const data = await res.json();
  25. if (!data || !data.result || data.result.length === 0) return m.react("❌");
  26. const result = data.result[0];
  27. const thumbnail = result.thumbnail;
  28. const downloadUrl = result.url;
  29. if (!downloadUrl) return m.react("❌");
  30. if (thumbnail && downloadUrl) {
  31. if (downloadUrl.endsWith('.jpg') || downloadUrl.endsWith('.png')) {
  32. await conn.sendFile(m.chat, downloadUrl, 'ig.jpg', '_*Aqui tiene tu imagen de Instagram*', m, null, fake);
  33. m.react('✅');
  34. } else if (downloadUrl.endsWith('.mp4')) {
  35. await conn.sendFile(m.chat, downloadUrl, 'ig.mp4', '**Aqui esta el video de Instagram*', m, null, fake);
  36. m.react('✅');
  37. }} else {
  38. m.react("❌");
  39. }} catch {
  40. try {
  41. const apiUrl = `${apis}/download/instagram?url=${encodeURIComponent(args[0])}`;
  42. const apiResponse = await fetch(apiUrl);
  43. const delius = await apiResponse.json();
  44. if (!delius || !delius.data || delius.data.length === 0) return m.react("❌");
  45. const downloadUrl = delius.data[0].url;
  46. const fileType = delius.data[0].type;
  47. if (!downloadUrl) return m.react("❌");
  48. if (fileType === 'image') {
  49. await conn.sendFile(m.chat, downloadUrl, 'ig.jpg', '_*Aqui tiene tu imagen de Instagram*', m, null, fake);
  50. m.react('✅')
  51. } else if (fileType === 'video') {
  52. await conn.sendFile(m.chat, downloadUrl, 'ig.mp4', '*Aqui esta el video de Instagram*', m, null, fake);
  53. m.react('✅')
  54. } else {
  55. return m.react("❌");
  56. }} catch {
  57. try {
  58. const resultssss = await instagramdl(args[0]);
  59. const shortUrl3 = await (await fetch(`https://tinyurl.com/api-create.php?url=${args[0]}`)).text();
  60. const txt4 = `_${shortUrl3}_`.trim();
  61. for (const {url} of resultssss) await conn.sendFile(m.chat, url, 'error.mp4', txt4, m, null, fake);
  62. await m.react('✅')
  63. } catch (e) {
  64. await m.react('❌')
  65. console.log(e)
  66. handler.limit = 0
  67. }}}}}
  68. handler.help = ['instagram *<link ig>*']
  69. handler.tags = ['downloader']
  70. handler.command = /^(instagramdl|instagram|igdl|ig|instagramdl2|instagram2|igdl2|ig2|instagramdl3|instagram3|igdl3|ig3)$/i
  71. handler.limit = 1
  72. handler.register = true
  73. export default handler;
  74. const getBuffer = async (url, options) => {
  75. options = options || {};
  76. const res = await axios({method: 'get', url, headers: {'DNT': 1, 'Upgrade-Insecure-Request': 1}, ...options, responseType: 'arraybuffer'});
  77. const buffer = Buffer.from(res.data, 'binary');
  78. const detectedType = await fileTypeFromBuffer(buffer);
  79. if (!detectedType || (detectedType.mime !== 'image/jpeg' && detectedType.mime !== 'image/png' && detectedType.mime !== 'video/mp4')) {
  80. return null;
  81. }
  82. return { buffer, detectedType };
  83. };