goat
command
ytstalk
Fetch YouTube channel info including subscribers, views, join date, description, thumbnail.
0
views
0
likes
0
installs
Aliases: ytinfo
raw source
const axios = require("axios");
const fs = require("fs");
const path = require("path");
module.exports = {
config: {
name: "ytstalk",
aliases: ["ytinfo"],
author: "Saimx69x",
version: "1.0",
role: 0,
countDown: 5,
description: "Fetch YouTube channel info including subscribers, views, join date, description, thumbnail.",
category: "information",
guide: "{p}ytstalk <channelName>"
},
onStart: async function ({ api, event, args }) {
const channelName = args.join(" ").trim();
const FONT_URL = "https://raw.githubusercontent.com/Saim-x69x/sakura/main/xfont.json";
const fontRes = await axios.get(FONT_URL);
const fontMap = fontRes.data;
const applyFont = (text) => text.split("").map(c => {
if ((c >= "A" && c <= "Z") || (c >= "a" && c <= "z") || (c >= "0" && c <= "9")) return fontMap[c] || c;
return c;
}).join("");
if (!channelName) {
return api.sendMessage(
applyFont("⚠️ Please provide a YouTube channel name.\nUsage: /ytstalk MrBeast"),
event.threadID,
event.messageID
);
}
try {
const GITHUB_RAW_API = "https://raw.githubusercontent.com/Saim-x69x/sakura/main/ApiUrl.json";
const rawApiRes = await axios.get(GITHUB_RAW_API);
const apiBase = rawApiRes.data.apiv1;
const apiUrl = `${apiBase}/api/ytinfo?channel=${encodeURIComponent(channelName)}`;
const response = await axios.get(apiUrl);
const data = response.data;
if (!data.status) {
return api.sendMessage(
applyFont(`❌ Failed to fetch info for channel: ${channelName}`),
event.threadID,
event.messageID
);
}
const info = data.channelInfo;
const message =
`${applyFont("📺 YouTube Channel Info")}\n━━━━━━━━━━━━━━\n` +
`${applyFont("🏷️ Channel:")} ${applyFont(info.title)}\n` +
`${applyFont("🆔 ID:")} ${applyFont(data.channelId || info.channelId)}\n` +
`${applyFont("🌍 Country:")} ${info.country}\n` +
`${applyFont("📅 Joined:")} ${info.publishedAt}\n` +
`${applyFont("👥 Subscribers:")} ${applyFont(info.subscribers)}\n` +
`${applyFont("👁️ Views:")} ${applyFont(info.views)}\n` +
`${applyFont("🎬 Videos:")} ${applyFont(info.videos)}\n\n` +
`${applyFont("📝 Description:")}\n${applyFont(info.description.substring(0, 600))}${info.description.length > 600 ? "..." : ""}`;
if (info.thumbnail) {
const imgPath = path.join(__dirname, `yt_${data.channelId}.jpg`);
const writer = fs.createWriteStream(imgPath);
const imgRes = await axios.get(info.thumbnail, { responseType: "stream" });
imgRes.data.pipe(writer);
writer.on("finish", () => {
api.sendMessage(
{ body: message, attachment: fs.createReadStream(imgPath) },
event.threadID,
() => { try { fs.unlinkSync(imgPath); } catch {} },
event.messageID
);
});
writer.on("error", (e) => {
console.error(e);
api.sendMessage(message, event.threadID, event.messageID);
});
} else {
api.sendMessage(message, event.threadID, event.messageID);
}
} catch (err) {
console.error(err);
api.sendMessage(
applyFont("❌ Error occurred while fetching channel info. Please check the channel name or try again later."),
event.threadID,
event.messageID
);
}
}
};