Skip to content

Instantly share code, notes, and snippets.

@INR-L
Last active February 25, 2023 17:02
Show Gist options
  • Save INR-L/aa6bcb5132167cb3d0525a37cb33b6b9 to your computer and use it in GitHub Desktop.
Save INR-L/aa6bcb5132167cb3d0525a37cb33b6b9 to your computer and use it in GitHub Desktop.
const { inrl, isUrl, googleIt, wikiMedia, ringTone, getYtV, getYtA, weather, movie, getBuffer } = require('../lib');
let {yts} = require("whatsapp-bot-pack");
const {getVar} = require('../lib/database/variable');
const {ytdl} = require('whatsapp-bot-pack');
const fs = require('fs-extra')
var videotime = 60000 // 1000 min
var dlsize = 1000 // 1000mb
inrl(
{
pattern: ['play'],
desc: 'do get goole serch result',
sucReact: "πŸ™ƒ",
category: ["system", "all"],
type : "search"
},
async(m, conn, text) => {
let {PREFIX,FOOTER} = await getVar();
let prefix = PREFIX == 'false' ? '':PREFIX;
if (!text) return citel.reply(`Use ${play} Back in Black`);
let search = await yts(text);
let anu = search.videos[0];
let buttons = [{
buttonId: `${prefix}ytmp4 ${anu.url}`,
buttonText: {
displayText: "β–Ί Video",
},
type: 1,
},
{
buttonId: `${prefix}ytmp3 ${anu.url}`,
buttonText: {
displayText: "β™« Audio",
},
type: 1,
},
{
buttonId: `${prefix}ytdoc ${anu.url}`,
buttonText: {
displayText: "β™« Document",
},
type: 1,
},
];
let buttonMessage = {
image: {
url: anu.thumbnail,
},
caption: `
╭───────────────◆
β”‚βΏ» *Youtube Player* ✨
β”‚βΏ» *Title:* ${anu.title}
β”‚βΏ» *Duration:* ${anu.timestamp}
β”‚βΏ» *Viewers:* ${anu.views}
β”‚βΏ» *Uploaded:* ${anu.ago}
β”‚βΏ» *Author:* ${anu.author.name}
╰────────────────◆
β¦Ώ *Url* : ${anu.url}
`,
footer: FOOTER,
buttons: buttons,
headerType: 4,
};
return conn.sendMessage(m.from, buttonMessage, {
quoted: m,
});
}
)
inrl(
{
pattern: ['ytdoc'],
desc: 'do get goole serch result',
sucReact: "πŸ™ƒ",
category: ["system", "all"],
type : "search"
},
async(m, conn, text) => {
const getRandom = (ext) => {
return `${Math.floor(Math.random() * 10000)}${ext}`;
};
if (text.length === 0) {
reply(`❌ URL is empty! \nSend ${prefix}ytmp3 url`);
return;
}
try {
let urlYt = text;
if (!urlYt.startsWith("http")) {
m.reply(`❌ Give youtube link!`);
return;
}
let infoYt = await ytdl.getInfo(urlYt);
//30 MIN
if (infoYt.videoDetails.lengthSeconds >= videotime) {
reply(`❌ I can't download that long video!`);
return;
}
let titleYt = infoYt.videoDetails.title;
let randomName = getRandom(".mp3");
const stream = ytdl(urlYt, {
filter: (info) => info.audioBitrate == 160 || info.audioBitrate == 128,
})
.pipe(fs.createWriteStream(`./${randomName}`));
await new Promise((resolve, reject) => {
stream.on("error", reject);
stream.on("finish", resolve);
});
let stats = fs.statSync(`./${randomName}`);
let fileSizeInBytes = stats.size;
let fileSizeInMegabytes = fileSizeInBytes / (1024 * 1024);
if (fileSizeInMegabytes <= dlsize) {
let search = await yts(text);
let buttonMessage = {
document: fs.readFileSync(`./${randomName}`),
mimetype: 'audio/mpeg',
fileName: titleYt + ".mp3",
headerType: 4,
contextInfo: {
externalAdReply: {
title: titleYt,
body: m.pushName,
renderLargerThumbnail: true,
thumbnailUrl: search.all[0].thumbnail,
mediaUrl: text,
mediaType: 1,
thumbnail: await getBuffer(search.all[0].thumbnail),
sourceUrl: text,
},
},
}
await conn.sendMessage(m.from, buttonMessage, { quoted: m })
return fs.unlinkSync(`./${randomName}`);
} else {
m.reply(`❌ File size bigger than 100mb.`);
}
fs.unlinkSync(`./${randomName}`);
} catch (e) {
console.log(e)
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment