randydev commited on
Commit
499c35a
·
verified ·
1 Parent(s): 972da13

Create @randydev /capcut.js

Browse files
Files changed (1) hide show
  1. lib/@randydev/capcut.js +86 -0
lib/@randydev/capcut.js ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import axios = from "axios";
2
+ import cheerio from "cheerio";
3
+ import qs from "qs";
4
+
5
+ const domain = "https://ssscapcut.com/";
6
+
7
+ function getCookies() {
8
+ return new Promise((resolve, reject) => {
9
+ axios
10
+ .get("https://ssscapcut.com/")
11
+ .then((response) => {
12
+ const cookiesArray = response.headers["set-cookie"];
13
+ const cookies = cookiesArray.map((cookie) => cookie.split(";")[0]); // Ambil hanya bagian yang diperlukan
14
+ resolve(cookies);
15
+ })
16
+ .catch((error) => {
17
+ console.error(error);
18
+ reject(error);
19
+ });
20
+ });
21
+ }
22
+
23
+ const getOriginalUrl = async (shortUrl) => {
24
+ try {
25
+ const response = await axios.get(shortUrl, {
26
+ maxRedirects: 0,
27
+ validateStatus: null,
28
+ });
29
+ const originalUrl = response.headers.location;
30
+ return originalUrl;
31
+ } catch (error) {
32
+ return shortUrl;
33
+ }
34
+ };
35
+
36
+ function capcutdl(Url) {
37
+ return new Promise(async (resolve, reject) => {
38
+ try {
39
+ if (!global.isUrlFSPR(Url) || !/capcut\.com/i.test(Url))
40
+ return global.rejectFSPR("Invalid URL: " + Url);
41
+
42
+ const cookies = await getCookies();
43
+ Url = await getOriginalUrl(Url);
44
+ const token = Url.match(/\d+/)[0];
45
+
46
+ await axios
47
+ .get(`https://ssscap.net/api/download/${token}`, {
48
+ headers: {
49
+ authority: "ssscap.net",
50
+ accept: "application/json, text/plain, */*",
51
+ "accept-language": "ms-MY,ms;q=0.9,en-US;q=0.8,en;q=0.7,id;q=0.6",
52
+ cookie: cookies.join("; "),
53
+ referer: "https://ssscap.net/",
54
+ "sec-ch-ua": '"Not)A;Brand";v="24", "Chromium";v="116"',
55
+ "sec-ch-ua-mobile": "?1",
56
+ "sec-ch-ua-platform": '"Android"',
57
+ "sec-fetch-dest": "empty",
58
+ "sec-fetch-mode": "cors",
59
+ "sec-fetch-site": "same-origin",
60
+ "user-agent":
61
+ "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36",
62
+ },
63
+ })
64
+ .then(({ data }) => {
65
+ resolve(global.resolveFSPR(updateUrls(data)));
66
+ })
67
+ .catch((error) => {
68
+ resolve(global.rejectFSPR(error));
69
+ });
70
+ } catch (error) {
71
+ resolve(global.rejectFSPR(error));
72
+ }
73
+ });
74
+ }
75
+
76
+ function updateUrls(obj) {
77
+ const regex =
78
+ /("originalVideoUrl": "| "authorUrl": "|"coverUrl": ")(\/[^"]+)/g;
79
+ const updatedData = JSON.stringify(obj, null, 2).replace(
80
+ regex,
81
+ (match, p1, p2) => p1 + domain + p2,
82
+ );
83
+ return JSON.parse(updatedData);
84
+ }
85
+
86
+ export { capcutdl };