fast72 commited on
Commit
e3f33e3
·
verified ·
1 Parent(s): 7a598f2

Update lib/yt.js

Browse files
Files changed (1) hide show
  1. lib/yt.js +38 -11
lib/yt.js CHANGED
@@ -108,19 +108,46 @@ async function threads(url) {
108
  }
109
 
110
  async function twitter(url) {
111
- const regex = /https?:\/\/?(?:mobile\.)?(?:www\.)?(?:twitter\.com|x\.com)\/(?:\w+\/status\/)?(\d+)/;
112
- if(!regex.test(url)) return { status: false, r: 'cant find video id' };
113
- const match = url.match(regex);
114
- const id = match ? match[1] : null;
115
- const res = (await axios.get(`https://tweeload.com/download/${id}`)).data
116
- const $ = cheerio.load(res);
117
- const section = $('section.content__section.download_result_section');
118
- const link = section.find('a.btn').attr('href');
119
- const name = section.find('.download__item__profile_pic span').first().text();
120
- const username = section.find('.download__item__profile_pic span').last().text();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  return {
122
- url: link
 
123
  };
 
 
 
124
  }
125
 
126
  module.exports = { yt, tiktok, instagram, threads, twitter };
 
108
  }
109
 
110
  async function twitter(url) {
111
+ try {
112
+ const formData = new URLSearchParams();
113
+ formData.append("q", url);
114
+ formData.append("lang", "id");
115
+ formData.append("cftoken", "JWT.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpcCI6IjE4Mi4xLjEzNS4yMzgiLCJ1cmwiOiJodHRwczovL3guY29tL2dhbGFzYW5zL3N0YXR1cy8xOTAxMTI5MDYyOTU1MDE2Mzk3P3Q9VTgzM0JmSExpUmRYM0NSUDVGOUhrZyZzPTE5IiwibmJmIjoxNzQyMzA0MzI2LCJleHAiOjE3NDIzMDQ2MjYsImlhdCI6MTc0MjMwNDMyNn0.h0GMNpNikiYqJgdhEEA2NN023_5fq5m7Scn31aMqYOo");
116
+ const headers = {
117
+ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
118
+ "Accept": "*/*",
119
+ "X-Requested-With": "XMLHttpRequest",
120
+ "User-Agent":
121
+ "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Mobile Safari/537.36",
122
+ "Referer": "https://x2twitter.com/id",
123
+ };
124
+ const response = await axios.post(
125
+ "https://x2twitter.com/api/ajaxSearch",
126
+ formData,
127
+ { headers }
128
+ );
129
+ if (response.data.status !== "ok") {
130
+ throw new Error("Gagal mengambil data dari server.");
131
+ }
132
+
133
+ const html = response.data.data;
134
+ const $ = cheerio.load(html);
135
+ let results = [];
136
+ $(".dl-action a").each((_, el) => {
137
+ const type = $(el).text().trim();
138
+ const downloadUrl = $(el).attr("href");
139
+ if (downloadUrl && downloadUrl !== "#") {
140
+ results.push({ type, download_url: downloadUrl });
141
+ }
142
+ });
143
+
144
  return {
145
+ success: results.length > 0,
146
+ url: results
147
  };
148
+ } catch (error) {
149
+ return { success: false, r: error.message };
150
+ }
151
  }
152
 
153
  module.exports = { yt, tiktok, instagram, threads, twitter };