Created
July 9, 2025 07:26
-
-
Save dipto-008/437b54605ae3679f26dda0c67613788e to your computer and use it in GitHub Desktop.
Hey noob ππ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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