mirror of
https://github.com/Divam-dev/aynt.git
synced 2025-02-20 11:23:20 +08:00
Fix twitter downloader
This commit is contained in:
parent
bf561f12e6
commit
6f743baee0
@ -2,9 +2,20 @@ const axios = require('axios');
|
||||
const fs = require('fs');
|
||||
const getTwitterMedia = require('get-twitter-media');
|
||||
|
||||
async function convertXToTwitterURL(url) {
|
||||
// Check if the URL is from x.com, and if so, convert it to twitter.com
|
||||
if (url.includes('x.com')) {
|
||||
url = url.replace('x.com', 'twitter.com');
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
async function downloadTwitterMedia(ctx, url) {
|
||||
try {
|
||||
let media = await getTwitterMedia(url, {buffer: true});
|
||||
// Convert x.com URL to twitter.com if needed
|
||||
url = await convertXToTwitterURL(url);
|
||||
|
||||
let media = await getTwitterMedia(url, { buffer: true });
|
||||
|
||||
if (media.found) {
|
||||
if (media.type === 'video' && media.url) {
|
||||
|
@ -51,7 +51,7 @@ bot.on('text', async (ctx) => {
|
||||
const youtubeUrlRegex = /(https?:\/\/(?:www\.)?youtube\.com\/watch\?v=|https?:\/\/youtu\.be\/|https?:\/\/(?:www\.)?youtube\.com\/shorts\/)([\w-]{11})/gi;
|
||||
const tiktokUrlRegex = /(https?:\/\/(?:www\.)?tiktok\.com\/(?:@[\w.-]+\/video\/[\w-]+|@[\w.-]+)|vm\.tiktok\.com\/[\w.-]+|vt\.tiktok\.com\/[\w.-]+)/gi;
|
||||
const instagramUrlRegex = /(https?:\/\/(?:www\.)?instagram\.com\/(p|tv|reels|stories)\/[\w.-]+)/gi;
|
||||
const twitterUrlRegex = /(https?:\/\/(?:www\.)?twitter\.com\/(?:[\w.-]+)\/status\/[\d]+|https?:\/\/t\.co\/[\w.-]+)/gi;
|
||||
const twitterUrlRegex = /(https?:\/\/(?:www\.)?(?:twitter|x)\.com\/(?:[\w.-]+)\/status\/[\d]+|https?:\/\/t\.co\/[\w.-]+)/gi;
|
||||
|
||||
const youtubeUrls = text.match(youtubeUrlRegex);
|
||||
const tiktokUrls = text.match(tiktokUrlRegex);
|
||||
|
Loading…
x
Reference in New Issue
Block a user