File size: 3,136 Bytes
046b271 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
const axios = require("axios");
const { cmd } = require("../command");
cmd({
pattern: "tiktok",
alias: ["ttdl", "tiktokdl","tt"],
react: 'β°',
desc: "Download TikTok videos.",
category: "download",
use: ".tiktok <TikTok video URL>",
filename: __filename
}, async (conn, mek, m, { from, reply, args }) => {
try {
// Check if the user provided a TikTok video URL
const tiktokUrl = args[0];
if (!tiktokUrl || !tiktokUrl.includes("tiktok.com")) {
return reply('Please provide a valid TikTok video URL. Example: `.tiktok https://tiktok.com/...`');
}
// Add a reaction to indicate processing
await conn.sendMessage(from, { react: { text: 'β³', key: m.key } });
// Prepare the API URL
const apiUrl = `https://api.nexoracle.com/downloader/tiktok-nowm?apikey=free_key@maher_apis&url=${encodeURIComponent(tiktokUrl)}`;
// Call the API using GET
const response = await axios.get(apiUrl);
// Check if the API response is valid
if (!response.data || response.data.status !== 200 || !response.data.result) {
return reply('β Unable to fetch the video. Please check the URL and try again.');
}
// Extract the video details
const { title, thumbnail, author, metrics, url } = response.data.result;
// Inform the user that the video is being downloaded
// await reply(`π₯ *Downloading TikTok video by @${author.username}... Please wait.*`);
// Download the video
const videoResponse = await axios.get(url, { responseType: 'arraybuffer' });
if (!videoResponse.data) {
return reply('β Failed to download the video. Please try again later.');
}
// Prepare the video buffer
const videoBuffer = Buffer.from(videoResponse.data, 'binary');
// Send the video with details
await conn.sendMessage(from, {
video: videoBuffer,
caption: `*π«πΙΔ«Δ« πΖ ππππππππππ*\n\n` +
`π *α΄Ιͺα΄Κα΄*: ${title || "No title"}\n` +
`π€ *α΄α΄α΄Κα΄Κ*: ${author.nickname}\n` +
`β₯οΈ *ΚΙͺα΄α΄s*: ${metrics.digg_count}\n` +
`π¬ *α΄α΄α΄α΄α΄Ι΄α΄s*: ${metrics.comment_count}\n` +
`β»οΈ *sΚα΄Κα΄s*: ${metrics.share_count}\n` +
`π₯ *α΄
α΄α΄‘Ι΄Κα΄α΄α΄
s*: ${metrics.download_count}\n\n` +
`> *Β© α΄α΄α΄‘α΄Κα΄α΄
ΚΚ α΄ΚΙͺ*`,
contextInfo: {
mentionedJid: [m.sender],
forwardingScore: 999,
isForwarded: true,
forwardedNewsletterMessageInfo: {
newsletterJid: '120363318387454868@newsletter',
newsletterName: 'γ πΙΔ«Δ« πΖ πΚΜππΰΉαΦΙΌΚ γ',
serverMessageId: 143
}
}
}, { quoted: mek });
// Add a reaction to indicate success
await conn.sendMessage(from, { react: { text: 'β
', key: m.key } });
} catch (error) {
console.error('Error downloading TikTok video:', error);
reply('β Unable to download the video. Please try again later.');
// Add a reaction to indicate failure
await conn.sendMessage(from, { react: { text: 'β', key: m.key } });
}
});
|