Advertisement
samiroexpikachu

Video X video finder

Apr 22nd, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require("fs-extra");
  2. const ytdl = require("@distube/ytdl-core");
  3. const yts = require("yt-search");
  4. const axios = require('axios');
  5. const tinyurl = require('tinyurl');
  6.  
  7. module.exports = {
  8.   config: {
  9.     name: "videox",
  10.     aliases: ["video"],
  11.     version: "1.3.9",
  12.     author: "Samir Œ",
  13.     countDown: 5,
  14.     role: 0,
  15.     category: "song",
  16.   },
  17.  
  18.   onStart: async function ({ api, event, message, args }) {
  19.     try {
  20.       let videox;
  21.  
  22.       if (event.type === "message_reply" && ["audio", "video"].includes(event.messageReply.attachments[0].type)) {
  23.         const attachmentUrl = event.messageReply.attachments[0].url;
  24.         const urls = await tinyurl.shorten(attachmentUrl);
  25.         const response = await axios.get(`https://apis-samir.onrender.com/audioRecognize?fileUrl=${urls}`);
  26.  
  27.         if (response.data && response.data.result.title) {
  28.           videox = response.data.result.title;
  29.         }
  30.       } else if (args.length > 0) {
  31.  
  32.         videox = args.join(" ");
  33.       } else {
  34.         return api.sendMessage("Please provide a video title or reply to a video/audio message.", event.threadID, event.messageID);
  35.       }
  36.  
  37.       const originalMessage = await message.reply(`Searching for "${videox}"`);
  38.       const searchResults = await yts(videox);
  39.  
  40.       if (!searchResults.videos.length) {
  41.         return api.sendMessage("No videos found.", event.threadID, event.messageID);
  42.       }
  43.  
  44.       const video = searchResults.videos[0];
  45.       const videoUrl = video.url;
  46.  
  47.       const stream = ytdl(videoUrl, { filter: "audioandvideo" });
  48.  
  49.       const fileName = `${event.senderID}.mp4`;
  50.       const filePath = __dirname + `/cache/${fileName}`;
  51.  
  52.       stream.pipe(fs.createWriteStream(filePath));
  53.  
  54.       stream.on('response', () => {
  55.         console.info('[DOWNLOADER]', 'Starting download now!');
  56.       });
  57.  
  58.       stream.on('info', (info) => {
  59.         console.info('[DOWNLOADER]', `Downloading video: ${info.videoDetails.title}`);
  60.       });
  61.  
  62.       stream.on('end', () => {
  63.         console.info('[DOWNLOADER] Downloaded');
  64.  
  65.         if (fs.statSync(filePath).size > 87380608) {
  66.           fs.unlinkSync(filePath);
  67.           return api.sendMessage('āŒ | The file could not be sent because it is larger than 25MB.', event.threadID);
  68.         }
  69.  
  70.         const replyMessage = {
  71.           body: `šŸ”® | Title: ${video.title}\nā³ | Duration: ${video.duration.timestamp}`,
  72.           attachment: fs.createReadStream(filePath)
  73.         };
  74.  
  75.         api.unsendMessage(originalMessage.messageID);
  76.  
  77.         api.sendMessage(replyMessage, event.threadID, () => {
  78.           fs.unlinkSync(filePath);
  79.         });
  80.       });
  81.     } catch (error) {
  82.       console.error('[ERROR]', error);
  83.       api.sendMessage('Video data not available.', event.threadID);
  84.     }
  85.   }
  86. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement