Skip to content

Instantly share code, notes, and snippets.

@dipto-008
Created July 9, 2025 07:26
Show Gist options
  • Save dipto-008/437b54605ae3679f26dda0c67613788e to your computer and use it in GitHub Desktop.
Save dipto-008/437b54605ae3679f26dda0c67613788e to your computer and use it in GitHub Desktop.
Hey noob πŸ‘‹πŸ‘‹
const axios = require("axios");
const fs = require('fs');
const baseApiUrl = async () => {
const base = await axios.get(
`https://raw.githubusercontent.com/Blankid018/D1PT0/main/baseApiUrl.json`
);
return base.data.api;
};
module.exports = {
config: {
name: "ytb",
version: "1.1.4",
aliases: ['youtube'],
author: "dipto",
countDown: 5,
role: 0,
description: {
en: "Download video, audio, and info from YouTube"
},
category: "media",
guide: {
en: " {pn} [video|-v] [<video name>|<video link>]: use to download video from YouTube."
+ "\n {pn} [audio|-a] [<video name>|<video link>]: use to download audio from YouTube"
+ "\n {pn} [info|-i] [<video name>|<video link>]: use to view video information from YouTube"
+ "\n Example:"
+ "\n {pn} -v chipi chipi chapa chapa"
+ "\n {pn} -a chipi chipi chapa chapa"
+ "\n {pn} -i chipi chipi chapa chapa"
}
},
onStart: async ({ api, args, event, commandName }) => {
const action = args[0].toLowerCase();
const checkurl = /^(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=|shorts\/))((\w|-){11})(?:\S+)?$/;
const urlYtb = checkurl.test(args[1]);
let videoID
if(urlYtb){
if (action === '-v' || action === '-a') {
try {
const format = action === '-v' ? 'mp4' : 'mp3';
const path = `ytb_${format}_${videoID}.${format}`;
const match = args[1].match(checkurl);
videoID = match ? match[1] : null;
const { data: { title, downloadLink, quality } } = await axios.get(`${await baseApiUrl()}/ytDl3?link=${videoID}&format=${format}&quality=3`);
await api.sendMessage({
body: `β€’ Title: ${title}\nβ€’ Quality: ${quality}`,
attachment: await dipto(downloadLink, path)
}, event.threadID, () => fs.unlinkSync(path), event.messageID);
} catch (e) {
console.error(e);
return api.sendMessage('❌ Failed to download the video/audio. Please try again later.', event.threadID, event.messageID);
}
} }
args.shift();
let keyWord = args.join(" ");
const maxResults = 6;
let result;
try {
result = (await axios.get(`${await baseApiUrl()}/ytFullSearch?songName=${keyWord}`)).data.slice(0, maxResults);
} catch (err) {
return api.sendMessage("❌ An error occurred: " + err.message, event.threadID, event.messageID);
}
if (result.length === 0) {
return api.sendMessage("β­• No search results match the keyword: " + keyWord, event.threadID, event.messageID);
}
let msg = "";
let i = 1;
const thumbnails = [];
for (const info of result) {
thumbnails.push(diptoSt(info.thumbnail, `thumbnail.jpg`));
msg += `${i++}. ${info.title}\nTime: ${info.time}\nChannel: ${info.channel.name}\n\n`;
}
api.sendMessage({
body: msg + "Reply to this message with a number to choose",
attachment: await Promise.all(thumbnails)
}, event.threadID, (err, info) => { global.GoatBot.onReply.set(info.messageID, {
commandName,
messageID: info.messageID,
author: event.senderID,
result,
action
});
}, event.messageID);
},
onReply: async ({ event, api, Reply }) => {
const { result, action } = Reply;
const choice = parseInt(event.body);
if (isNaN(choice) || choice <= 0 || choice > result.length) {
return api.sendMessage('❌ Invalid choice. Please reply with a valid number.', event.threadID, event.messageID);
}
const selectedVideo = result[choice - 1];
const videoID = selectedVideo.id;
if (action === '-v' || action === 'video' || action === 'mp4' || action === '-a' || action === 'audio' || action === 'mp3' || action === 'music') {
try {
let format = ['-a', 'audio', 'mp3', 'music'].includes(action) ? 'mp3' : 'mp4';
const path = `ytb_${format}_${videoID}.${format}`;
const { data: { title, downloadLink, quality } } = await axios.get(`${await baseApiUrl()}/ytDl3?link=${videoID}&format=${format}&quality=3`);
api.unsendMessage(Reply.messageID);
await api.sendMessage({
body: `β€’ Title: ${title}\nβ€’ Quality: ${quality}`,
attachment: await dipto(downloadLink, path)
}, event.threadID, () => fs.unlinkSync(path), event.messageID);
} catch (e) {
console.error(e);
return api.sendMessage('❌ Failed to download the video/audio. Please try again later.', event.threadID, event.messageID);
}
}
if (action === '-i' || action === 'info') {
try {
const { data } = await axios.get(`${await baseApiUrl()}/ytfullinfo?videoID=${videoID}`);
api.unsendMessage(Reply.messageID);
await api.sendMessage({
body: `✨ | πšƒπš’πšπš•πšŽ: ${data.title}\n⏳ | π™³πšžπš›πšŠπšπš’πš˜πš—: ${data.duration / 60} minutes\nπšπšŽπšœπš˜πš•πšžπšπš’πš˜πš—: ${data.resolution}\nπŸ‘€ | πš…πš’πšŽπš  π™²πš˜πšžπš—πš: ${data.view_count}\nπŸ‘πŸ» | π™»πš’πš”πšŽπšœ: ${data.like_count}\nπŸ“¬ | π™²πš˜πš–πš–πšŽπš—πšπšœ: ${data.comment_count}\n♻️ | π™²πšŠπšπšŽπšπš˜πš›πš’πšŽπšœ: ${data.categories[0]}\n🌐 | π™²πš‘πšŠπš—πš—πšŽπš•: ${data.channel}\nπŸ§πŸ»β€β™‚οΈ | πš„πš™πš•πš˜πšŠπšπšŽπš› π™Έπš: ${data.uploader_id}\nπŸ‘₯ | πš‚πšžπš‹πšœπšŒπš›πš’πš‹πšŽπš›πšœ: ${data.channel_follower_count}\nπŸ”— | π™²πš‘πšŠπš—πš—πšŽπš• πš„πš›πš•: ${data.channel_url}\nπŸ”— | πš…πš’πšπšŽπš˜ πš„πš›πš•: ${data.webpage_url}`,
attachment: await diptoSt(data.thumbnail, 'info_thumb.jpg')
}, event.threadID, event.messageID);
} catch (e) {
console.error(e);
return api.sendMessage('❌ Failed to retrieve video info. Please try again later.', event.threadID, event.messageID);
}
}
}
};
async function dipto(url,pathName) {
try {
const response = (await axios.get(url,{
responseType: "arraybuffer"
})).data;
fs.writeFileSync(pathName, Buffer.from(response));
return fs.createReadStream(pathName);
}
catch (err) {
throw err;
}
}
async function diptoSt(url,pathName) {
try {
const response = await axios.get(url,{
responseType: "stream"
});
response.data.path = pathName;
return response.data;
}
catch (err) {
throw err;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment