almtools 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tools/tools.js DELETED
@@ -1,426 +0,0 @@
1
- const axios = require("axios")
2
- const FormData = require("form-data");
3
- const cheerio = require("cheerio");
4
-
5
- async function tiktok(url) {
6
- return new Promise(async (resolve, reject) => {
7
- try {
8
- function formatNumber(integer) {
9
- let numb = parseInt(integer);
10
- return Number(numb).toLocaleString().replace(/,/g, '.');
11
- }
12
-
13
- let domain = 'https://www.tikwm.com/api/';
14
- let res = await (await axios.post(domain, {}, {
15
- headers: {
16
- 'Accept': 'application/json, text/javascript, */*; q=0.01',
17
- 'Accept-Language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
18
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
19
- 'Origin': 'https://www.tikwm.com',
20
- 'Referer': 'https://www.tikwm.com/',
21
- 'Sec-Ch-Ua': '"Not)A;Brand" ;v="24" , "Chromium" ;v="116"',
22
- 'Sec-Ch-Ua-Mobile': '?1',
23
- 'Sec-Ch-Ua-Platform': 'Android',
24
- 'Sec-Fetch-Dest': 'empty',
25
- 'Sec-Fetch-Mode': 'cors',
26
- 'Sec-Fetch-Site': 'same-origin',
27
- 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36',
28
- 'X-Requested-With': 'XMLHttpRequest'
29
- },
30
- params: {
31
- url: url,
32
- count: 12,
33
- cursor: 0,
34
- web: 1,
35
- hd: 1
36
- }
37
- })).data.data;
38
-
39
- let result = {
40
- status: true,
41
- result: {}
42
- };
43
- if (!res.size) {
44
- result.result = {
45
- mediatype: "image",
46
- media: res.images,
47
- title: res.title,
48
- audio: 'https://www.tikwm.com' + (res.music || res.music_info.play),
49
- author: {
50
- id: res.author.id,
51
- fullname: res.author.unique_id,
52
- nickname: res.author.nickname,
53
- avatar: 'https://www.tikwm.com' + res.author.avatar
54
- }
55
- };
56
- } else {
57
- result.result = {
58
- mediatype: "video",
59
- media: 'https://www.tikwm.com' + res.hdplay,
60
- title: res.title,
61
- audio: 'https://www.tikwm.com' + (res.music || res.music_info.play),
62
- author: {
63
- id: res.author.id,
64
- fullname: res.author.unique_id,
65
- nickname: res.author.nickname,
66
- avatar: 'https://www.tikwm.com' + res.author.avatar
67
- }
68
- };
69
- }
70
-
71
- resolve(result);
72
- } catch (e) {
73
- reject(e);
74
- }
75
- });
76
- }
77
-
78
- async function instagram(url) {
79
-
80
- try {
81
- if (!url.match(/https?:\/\/(www\.)?(instagram\.com|facebook\.com)/i)) {
82
- throw 'URL yang Anda masukkan tidak valid!';
83
- }
84
-
85
- const { data } = await axios.post(
86
- 'https://yt1s.io/api/ajaxSearch',
87
- new URLSearchParams({ p: 'home', q: url, w: '', lang: 'en' }),
88
- {
89
- headers: {
90
- 'User-Agent':
91
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
92
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
93
- }
94
- }
95
- );
96
-
97
- if (data.status !== 'ok') throw 'Gagal mendapatkan data dari server!';
98
-
99
- const $ = cheerio.load(data.data);
100
- const downloads = $('a.abutton.is-success.is-fullwidth.btn-premium')
101
- .map((_, el) => ({
102
- title: $(el).attr('title'),
103
- url: $(el).attr('href'),
104
- }))
105
- .get();
106
-
107
- if (!downloads || downloads.length === 0) {
108
- throw 'Tidak dapat menemukan media untuk diunduh!';
109
- }
110
-
111
- const media = [];
112
-
113
- for (const dl of downloads) {
114
- try {
115
- const head = await axios.head(dl.url);
116
- const mimeType = head.headers['content-type'];
117
- if (dl.title == "Download Thumbnail") continue
118
- if (mimeType.includes('image')) {
119
- media.push({
120
- mediatype: 'image',
121
- url: dl.url
122
- });
123
- } else if (mimeType.includes('video')) {
124
- media.push({
125
- mediatype: 'video',
126
- url: dl.url
127
- });
128
- } else {
129
- continue;
130
- }
131
- } catch (err) {
132
- console.error('Failed to get content type:', err.message);
133
- }
134
- }
135
-
136
- const result = { status: true, media };
137
-
138
- if (media.length === 0) {
139
- throw 'No valid media found.';
140
- }
141
-
142
- return result
143
- } catch (error) {
144
- console.error(error);
145
- return {
146
- status: false,
147
- error: error
148
- }
149
- }
150
- };
151
-
152
- async function douyin(url) {
153
- try {
154
- const { data } = await axios.get(
155
- "https://dlpanda.com/id?token=G7eRpMaa&url=" + encodeURIComponent(url)
156
- );
157
- const $ = cheerio.load(data);
158
-
159
- const imageUrls = [];
160
-
161
- $('.single-popular-domain .card-body img').each((_, el) => {
162
- const src = $(el).attr('src');
163
- if (src) imageUrls.push(src);
164
- });
165
-
166
- const video = $('video source').attr('src');
167
-
168
- if (imageUrls.length > 0) {
169
- return {
170
- status: true,
171
- result: {
172
- mediatype: "image",
173
- media: imageUrls
174
- }
175
- };
176
- } else {
177
- return {
178
- status: true,
179
- result: {
180
- mediatype: "video",
181
- media: video.startsWith("//") ? "https:" + video : video
182
- }
183
- };
184
- }
185
- } catch (error) {
186
- return {
187
- status: false,
188
- error
189
- };
190
- }
191
- }
192
-
193
- const fb = {
194
- tokens: async () => {
195
- const {
196
- data: a
197
- } = await axios.get("https://fbdown.me/");
198
- const $ = cheerio.load(a);
199
- return $('#token')
200
- .val();
201
- },
202
-
203
- dl: async (urls) => {
204
- const tokens = await fb.tokens();
205
- const d = new FormData();
206
- d.append("url", urls);
207
- d.append("token", tokens);
208
-
209
- const headers = {
210
- headers: {
211
- ...d.getHeaders()
212
- }
213
- };
214
-
215
- const {
216
- data: s
217
- } = await axios.post(
218
- "https://fbdown.me/wp-json/aio-dl/video-data", d,
219
- headers);
220
- return { status: true, result: s }
221
- }
222
- };
223
-
224
- class SpotMate {
225
- constructor() {
226
- this._cookie = null;
227
- this._token = null;
228
- }
229
-
230
- async _visit() {
231
- try {
232
- const response = await axios.get('https://spotmate.online/en', {
233
- headers: {
234
- 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36',
235
- },
236
- });
237
-
238
- const setCookieHeader = response.headers['set-cookie'];
239
- if (setCookieHeader) {
240
- this._cookie = setCookieHeader
241
- .map((cookie) => cookie.split(';')[0])
242
- .join('; ');
243
- }
244
-
245
- const $ = cheerio.load(response.data);
246
- this._token = $('meta[name="csrf-token"]').attr('content');
247
-
248
- if (!this._token) {
249
- throw new Error('Token CSRF tidak ditemukan.');
250
- }
251
-
252
- console.log('Berhasil mendapatkan cookie dan token.');
253
- } catch (error) {
254
- throw new Error(`Gagal mengunjungi halaman: ${error.message}`);
255
- }
256
- }
257
-
258
- async info(spotifyUrl) {
259
- if (!this._cookie || !this._token) {
260
- await this._visit();
261
- }
262
-
263
- try {
264
- const response = await axios.post(
265
- 'https://spotmate.online/getTrackData',
266
- { spotify_url: spotifyUrl },
267
- {
268
- headers: this._getHeaders(),
269
- }
270
- );
271
-
272
- return response.data;
273
- } catch (error) {
274
- throw new Error(`Gagal mendapatkan info track: ${error.message}`);
275
- }
276
- }
277
-
278
- async convert(spotifyUrl) {
279
- if (!this._cookie || !this._token) {
280
- await this._visit();
281
- }
282
-
283
- try {
284
- const response = await axios.post(
285
- 'https://spotmate.online/convert',
286
- { urls: spotifyUrl },
287
- {
288
- headers: this._getHeaders(),
289
- }
290
- );
291
-
292
- return response.data;
293
- } catch (error) {
294
- throw new Error(`Gagal mengonversi track: ${error.message}`);
295
- }
296
- }
297
-
298
- clear() {
299
- this._cookie = null;
300
- this._token = null;
301
- console.log('Cookie dan token telah dihapus.');
302
- }
303
-
304
- _getHeaders() {
305
- return {
306
- 'authority': 'spotmate.online',
307
- 'accept': '*/*',
308
- 'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
309
- 'content-type': 'application/json',
310
- 'cookie': this._cookie,
311
- 'origin': 'https://spotmate.online',
312
- 'referer': 'https://spotmate.online/en',
313
- 'sec-ch-ua': '"Not A(Brand";v="8", "Chromium";v="132"',
314
- 'sec-ch-ua-mobile': '?1',
315
- 'sec-ch-ua-platform': '"Android"',
316
- 'sec-fetch-dest': 'empty',
317
- 'sec-fetch-mode': 'cors',
318
- 'sec-fetch-site': 'same-origin',
319
- 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36',
320
- 'x-csrf-token': this._token,
321
- };
322
- }
323
- }
324
-
325
- async function contol(url) {
326
- try {
327
- let spotMate = new SpotMate();
328
- let info = await spotMate.info(url);
329
- let track = await spotMate.convert(url);
330
- if (track.error) throw "Error While Downloading Audio";
331
- let artists = []
332
- let artist = info?.artists.forEach((i) => artists.push(i.name)) || null;
333
- let data = {
334
- title: info?.name || null,
335
- album: info?.album.name || null,
336
- thumbnail: info?.album.images || null,
337
- artists: artists.filter(_ => _),
338
- duration: info.duration_ms || null,
339
- url: track.url
340
- }
341
- return { status: true, result: data }
342
- } catch (e) {
343
- throw e
344
- }
345
- }
346
-
347
- async function snack(url) {
348
- const res = await fetch(url);
349
- const body = await res.text();
350
- const $ = cheerio.load(body);
351
- const video = $("div.video-box").find("a-video-player");
352
- const author = $("div.author-info");
353
- const attr = $("div.action");
354
-
355
- const data = {
356
- title: $(author).find("div.author-desc > span").children("span").eq(0).text().trim(),
357
- thumbnail: $(video).parent().siblings("div.background-mask").children("img").attr("src"),
358
- media: $(video).attr("src"),
359
- author: $("div.author-name").text().trim(),
360
- authorImage: $(attr).find("div.avatar > img").attr("src"),
361
- like: $(attr).find("div.common").eq(0).text().trim(),
362
- comment: $(attr).find("div.common").eq(1).text().trim(),
363
- share: $(attr).find("div.common").eq(2).text().trim(),
364
- };
365
- return { status: true, result: data }
366
- }
367
-
368
- async function twitter(link) {
369
- try {
370
- const apiUrl = "https://www.twitterdown.com/api/parse";
371
- const headers = {
372
- "Content-Type": "application/json",
373
- "User-Agent":
374
- "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, seperti Gecko) Chrome/134.0.0.0 Mobile Safari/537.36",
375
- "Referer": `https://www.twitterdown.com/${link.split("/").slice(-2).join("/")}`,
376
- };
377
- const postData = { url: link };
378
- const response = await axios.post(apiUrl, postData, { headers });
379
- if (!response.data || !response.data.resolutions) {
380
- throw new Error("Gagal mengambil data dari TwitterDown.");
381
- }
382
- const thumbnail = response.data.thumbnail || null;
383
- const text = response.data.text || null;
384
- const username = response.data.username || null;
385
- const statusId = response.data.statusId || null;
386
- const downloadLinks = response.data.resolutions.reduce((acc, media) => {
387
- acc[media.resolution] = media.url;
388
- return acc;
389
- }, {});
390
-
391
- let sta = {
392
- username,
393
- statusId,
394
- title: text,
395
- thumbnail,
396
- url: downloadLinks,
397
- }
398
- return { status: true, result: sta }
399
- } catch (error) {
400
- throw error
401
- }
402
- }
403
-
404
- async function capcut(url) {
405
- if (!url) throw new Error('URL cannot be empty');
406
-
407
- const response = await axios.get(url);
408
- const data = response.data;
409
- const $ = cheerio.load(data);
410
-
411
- return {
412
- url: $("video").attr("src") || null,
413
- description: $('meta[name="keywords"]').attr("content") || null
414
- };
415
- }
416
-
417
- module.exports = {
418
- facebook: fb.dl,
419
- instagram,
420
- tiktok,
421
- douyin,
422
- spotify: contol,
423
- snackvideo: snack,
424
- twitter,
425
- capcut
426
- }