descargas-fb.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import fetch from 'node-fetch';
  2. const handler = async (m, {conn, args, command, usedPrefix}) => {
  3. // Verificar que se proporcionó una URL
  4. if (!args[0]) {
  5. throw `⚠️ Ingrese un enlace de Facebook para descargar el video
  6. • *Ejemplo:* ${usedPrefix + command} https://www.facebook.com/watch?v=636541475139`;
  7. }
  8. // Verificar que la URL sea de Facebook
  9. if (!args[0].match(/www.facebook.com|fb.watch/g)) {
  10. throw `⚠️ Ingrese un enlace válido de Facebook para descargar el video
  11. • *Ejemplo:* ${usedPrefix + command} https://www.facebook.com/watch?v=636541475139`;
  12. }
  13. // Indicar que se está procesando
  14. m.react(`⌛`);
  15. try {
  16. // Usar la API de siputzx para obtener los enlaces de descarga
  17. const apiUrl = `https://api.siputzx.my.id/api/d/facebook?url=${encodeURIComponent(args[0])}`;
  18. const response = await fetch(apiUrl);
  19. const data = await response.json();
  20. // Verificar si la respuesta fue exitosa
  21. if (!data.status) {
  22. throw new Error('No se pudo obtener el video de Facebook');
  23. }
  24. // Obtener la URL del video en la mejor calidad disponible
  25. const videoOptions = data.data;
  26. if (!videoOptions || videoOptions.length === 0) {
  27. throw new Error('No se encontraron enlaces de descarga');
  28. }
  29. // Prefiere la resolución HD si está disponible, sino usa SD
  30. const hdVideo = videoOptions.find(v => v.resolution.includes('HD'));
  31. const sdVideo = videoOptions.find(v => v.resolution.includes('SD'));
  32. const videoUrl = hdVideo ? hdVideo.url : (sdVideo ? sdVideo.url : videoOptions[0].url);
  33. // Enviar el video al chat
  34. await conn.sendFile(
  35. m.chat,
  36. videoUrl,
  37. 'facebook_video.mp4',
  38. `✅ *Video descargado exitosamente*\n📱 *Resolución:* ${hdVideo ? 'HD' : 'SD'}`,
  39. m
  40. );
  41. // Reacción de éxito
  42. m.react(`✅`);
  43. } catch (error) {
  44. // Manejar errores
  45. console.error('Error al descargar el video:', error);
  46. m.react(`❌`);
  47. m.reply(`⚠️ *Ocurrió un error al descargar el video*\n\nPor favor, intente con otro enlace o reporte este problema con el comando: #report`);
  48. }
  49. };
  50. // Configuración del comando
  51. handler.help = ['fb', 'facebook', 'fbdl'];
  52. handler.tags = ['downloader'];
  53. handler.command = /^(facebook|fb|facebookdl|fbdl)$/i;
  54. handler.limit = 2; // Reducido de 3 a 2 por mayor eficiencia
  55. handler.register = true;
  56. export default handler;