File size: 4,088 Bytes
2821330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const axios = require('axios');
const fs = require('fs');
const getFBInfo = require("@xaviabot/fb-downloader");
const line = "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”";
module.exports.config = {
  name: "adown",
  version: "1.0",
  hasPermssion: 0,
  credits: "Jonell Magallanes",
  description: "Automatically download TikTok, Facebook, and Capcut videos by Jonell Magallanes",
  usePrefix: false,
  hide: true,
  commandCategory: "Media",
  usage: " ",
  cooldowns: 3,
};

module.exports.handleEvent = async function ({ api, event }) {
  if (event.body && event.isGroup) {
    const tiktokLinkRegex = /https:\/\/(www\.|vt\.|vm\.)?tiktok\.com\/.*$/;
    const facebookLinkRegex = /https:\/\/(www\.)?facebook\.com\/.*$/;
    const capcutLinkRegex = /https:\/\/(www\.)?capcut\.com\/t\/.*$/;
    const link = event.body;

    if (tiktokLinkRegex.test(link)) {
      api.setMessageReaction("๐Ÿ“ฅ", event.messageID, () => {}, true);
      downloadAndSendTikTokContent(link, api, event);
    } else if (facebookLinkRegex.test(link)) {
      api.setMessageReaction("๐Ÿ“ฅ", event.messageID, () => {}, true);
      downloadAndSendFBContent(link, api, event);
    } else if (capcutLinkRegex.test(link)) {
      api.setMessageReaction("๐Ÿ“ฅ", event.messageID, () => {}, true);
      downloadAndSendCapcutContent(link, api, event);
    }
  }
};

const downloadAndSendTikTokContent = async (url, api, event) => {
  try {
    const response = await axios.post('https://www.tikwm.com/api/', { url });
    const data = response.data.data;
    const videoStream = await axios({
      method: 'get',
      url: data.play,
      responseType: 'stream'
    }).then(res => res.data);

    const fileName = `TikTok-${Date.now()}.mp4`;
    const filePath = `./${fileName}`;
    const videoFile = fs.createWriteStream(filePath);

    videoStream.pipe(videoFile);

    videoFile.on('finish', () => {
      videoFile.close(() => {
        console.log('Downloaded TikTok video file.');
        api.sendMessage({
          body: `๐—ง๐—ถ๐—ธ๐˜๐—ผ๐—ธ ๐——๐—ผ๐˜„๐—ป๐—น๐—ผ๐—ฎ๐—ฑ๐—ฒ๐—ฟ\n${line}\nContent: ${data.title}\nLikes: ${data.digg_count}\nComments: ${data.comment_count}`,
          attachment: fs.createReadStream(filePath)
        }, event.threadID, () => {
          fs.unlinkSync(filePath);
        });
      });
    });
  } catch (e) {
    console.error(e);
  }
};

const downloadAndSendFBContent = async (url, api, event) => {
  const fbvid = './video.mp4'; 
  try {
    const result = await getFBInfo(url);
    let videoData = await axios.get(encodeURI(result.sd), { responseType: 'arraybuffer' });
    fs.writeFileSync(fbvid, Buffer.from(videoData.data, "utf-8"));

    api.sendMessage({
      body: `๐—™๐—ฎ๐—ฐ๐—ฒ๐—ฏ๐—ผ๐—ผ๐—ธ ๐——๐—ผ๐˜„๐—ป๐—น๐—ผ๐—ฎ๐—ฑ๐—ฒ๐—ฟ\n${line}`,
      attachment: fs.createReadStream(fbvid)
    }, event.threadID, () => {
      fs.unlinkSync(fbvid); 
    });
  } catch (e) {
    console.error(e);
  }
};

const downloadAndSendCapcutContent = async (url, api, event) => {
  try {
    const response = await axios.get(`https://ccexplorerapisjonell.vercel.app/api/capcut?url=${url}`);
    const { result } = response.data;

    const capcutFileName = `Capcut-${Date.now()}.mp4`;
    const capcutFilePath = `./${capcutFileName}`;

    const videoResponse = await axios({
      method: 'get',
      url: result.video_ori,
      responseType: 'arraybuffer'
    });

    fs.writeFileSync(capcutFilePath, Buffer.from(videoResponse.data, 'binary'));

    api.sendMessage({
      body: `๐—–๐—ฎ๐—ฝ๐—ฐ๐˜‚๐˜ ๐——๐—ผ๐˜„๐—ป๐—น๐—ผ๐—ฎ๐—ฑ๐—ฒ๐—ฟ\n${line}\n๐—ง๐—ถ๐˜๐—น๐—ฒ: ${result.title}\n๐——๐—ฒ๐˜€๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜๐—ถ๐—ผ๐—‡: ${result.description}`,
      attachment: fs.createReadStream(capcutFilePath)
    }, event.threadID, () => {
      fs.unlinkSync(capcutFilePath);
    });
  } catch (e) {
    console.error(e);
  }
};

module.exports.run = async function ({ api, event }) {
  api.sendMessage("๐Ÿ“ | This command automatically downloads TikTok, Facebook, and Capcut videos by Jonell Magallanes", event.threadID);
};