Update index.js
Browse files
index.js
CHANGED
|
@@ -319,44 +319,50 @@ const youtubedl = async (url) => {
|
|
| 319 |
};
|
| 320 |
|
| 321 |
//TWITTER API
|
| 322 |
-
async function
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
| 339 |
});
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
found: true,
|
| 344 |
-
type: result.media_extended[0].type,
|
| 345 |
-
url: result.media_extended[0].url
|
| 346 |
};
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
}
|
| 358 |
-
else
|
| 359 |
-
return { found: false, error: `Invalid URL: ${input.url}` };
|
| 360 |
}
|
| 361 |
|
| 362 |
const app = express();
|
|
@@ -547,7 +553,7 @@ app.all('/', (req, res) => {
|
|
| 547 |
if (!/https?:\/\/(www\.)?(twitter|x)\.com\/.*\/status/.test(url)) {
|
| 548 |
return res.json({ message: 'Invalid URL' });
|
| 549 |
}
|
| 550 |
-
let data = await
|
| 551 |
return res.json(data);
|
| 552 |
} catch (e) {
|
| 553 |
console.log(e);
|
|
|
|
| 319 |
};
|
| 320 |
|
| 321 |
//TWITTER API
|
| 322 |
+
async function twitterDL(url) {
|
| 323 |
+
try {
|
| 324 |
+
let form = new FormData();
|
| 325 |
+
form.append('q', url);
|
| 326 |
+
form.append('lang', 'en');
|
| 327 |
+
|
| 328 |
+
let response = await fetch('https://x2twitter.com/api/ajaxSearch', {
|
| 329 |
+
method: 'POST',
|
| 330 |
+
body: form,
|
| 331 |
+
headers: form.getHeaders()
|
| 332 |
+
});
|
| 333 |
+
|
| 334 |
+
let data = await response.json();
|
| 335 |
+
|
| 336 |
+
const $ = cheerio.load(data?.data);
|
| 337 |
+
const downloads = [];
|
| 338 |
+
$('.dl-action a').each((index, element) => {
|
| 339 |
+
const format = $(element).text().trim();
|
| 340 |
+
const url = $(element).attr('href');
|
| 341 |
+
downloads.push({ format, url });
|
| 342 |
});
|
| 343 |
+
|
| 344 |
+
const convertToMP3 = {
|
| 345 |
+
url: $('.tw-middle a').attr('href')
|
|
|
|
|
|
|
|
|
|
| 346 |
};
|
| 347 |
+
|
| 348 |
+
const result = {
|
| 349 |
+
downloads,
|
| 350 |
+
convert_to_mp3: convertToMP3
|
| 351 |
+
};
|
| 352 |
+
|
| 353 |
+
const hrefArray = [];
|
| 354 |
+
|
| 355 |
+
$('a').each((index, element) => {
|
| 356 |
+
const href = $(element).attr('href');
|
| 357 |
+
if (href && href !== '/' && href !== '#') {
|
| 358 |
+
hrefArray.push(href);
|
| 359 |
+
}
|
| 360 |
+
});
|
| 361 |
+
|
| 362 |
+
return { result, hrefArray };
|
| 363 |
+
} catch (error) {
|
| 364 |
+
return error;
|
| 365 |
}
|
|
|
|
|
|
|
| 366 |
}
|
| 367 |
|
| 368 |
const app = express();
|
|
|
|
| 553 |
if (!/https?:\/\/(www\.)?(twitter|x)\.com\/.*\/status/.test(url)) {
|
| 554 |
return res.json({ message: 'Invalid URL' });
|
| 555 |
}
|
| 556 |
+
let data = await twitterDL(url);
|
| 557 |
return res.json(data);
|
| 558 |
} catch (e) {
|
| 559 |
console.log(e);
|