Skip to content

Commit

Permalink
Update yt-search.js
Browse files Browse the repository at this point in the history
  • Loading branch information
HyHamza authored Jul 14, 2024
1 parent d4485d7 commit 9677041
Showing 1 changed file with 4 additions and 63 deletions.
67 changes: 4 additions & 63 deletions commandes/yt-search.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
const { Hamza } = require("../TalkDrove/Hamza");
const { getytlink, ytdwn } = require("../TalkDrove/ytdl-core");
const yts = require("yt-search");
const ytdl = require('ytdl-core');
const fs = require('fs');

Hamza({ nomCom: "yts", categorie: "Search", reaction: "✋" }, async (dest, zk, commandeOptions) => {
const { ms, repondre, arg } = commandeOptions;
const query = arg.join(" ");

if (!query[0]) {
repondre("Please specify what you want to search for.");
return;
}

try {
const info = await yts(query);
const results = info.videos;

let captions = "";
for (let i = 0; i < 10; i++) {
captions += `----------------\nTitle: ${results[i].title}\nTime : ${results[i].timestamp}\nUrl: ${results[i].url}\n`;
}
captions += "\n======\n*Powered by BYTE-MD*";

zk.sendMessage(dest, { image: { url: results[0].thumbnail }, caption: captions }, { quoted: ms });
} catch (error) {
repondre("Error during the process: " + error);
}
});
// Assuming Hamza function structure is used for command registration

Hamza({
nomCom: "ytmp4",
Expand All @@ -41,7 +16,8 @@ Hamza({
return;
}

const url = arg.join(" ");
const url = arg[0]; // Only take the first argument as the URL

try {
const videoInfo = await ytdl.getInfo(url);
const format = ytdl.chooseFormat(videoInfo.formats, { quality: '18' });
Expand All @@ -53,49 +29,14 @@ Hamza({

fileStream.on('finish', () => {
zk.sendMessage(origineMessage, { video: { url: `./${filename}` }, caption: "Powered by *BYTE-MD*", gifPlayback: false }, { quoted: ms });
console.log("Video file sent successfully!");
});

fileStream.on('error', (error) => {
console.error('Error writing video file:', error);
repondre('An error occurred while writing the video file.');
});

} catch (error) {
console.error('Error searching or downloading video:', error);
repondre('An error occurred during the search or download of the video.' + error);
}
});

Hamza({
nomCom: "ytmp3",
categorie: "Download",
reaction: "💿"
}, async (origineMessage, zk, commandeOptions) => {
const { ms, repondre, arg } = commandeOptions;

if (!arg[0]) {
repondre("Please insert a YouTube link.");
return;
}

try {
const url = arg.join(" ");
const audioStream = ytdl(url, { filter: 'audioonly', quality: 'highestaudio' });
const filename = 'audio.mp3';

const fileStream = fs.createWriteStream(filename);
audioStream.pipe(fileStream);

fileStream.on('finish', () => {
zk.sendMessage(origineMessage, { audio: { url: `./${filename}` }, mimetype: 'audio/mp4' }, { quoted: ms, ptt: false });
console.log("Audio file sent successfully!");
});

fileStream.on('error', (error) => {
console.error('Error writing audio file:', error);
repondre('An error occurred while writing the audio file.');
});

} catch (error) {
console.error('Error searching or downloading video:', error);
repondre('An error occurred during the search or download of the video.');
Expand Down

0 comments on commit 9677041

Please sign in to comment.