mirror of
https://github.com/Divam-dev/aynt.git
synced 2025-02-20 11:23:20 +08:00
Minor fixes
Fixed twitter downloader and add pinging
This commit is contained in:
parent
a009b0618a
commit
8c93ef6eba
1542
package-lock.json
generated
1542
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,9 @@
|
||||
"ffmpeg-static": "^5.1.0",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"fs": "^0.0.1-security",
|
||||
"get-twitter-media": "^2.0.6",
|
||||
"instagram-url-dl": "^5.1.3",
|
||||
"node-cron": "^3.0.2",
|
||||
"nodemon": "^2.0.22",
|
||||
"telegraf": "^4.12.2",
|
||||
"telegraf-session-local": "^2.1.1",
|
||||
|
@ -27,7 +27,6 @@ module.exports = function(bot) {
|
||||
|
||||
return async function downloadTikTokVideo(ctx, videoUrl) {
|
||||
try {
|
||||
// Always use the full URL with https scheme
|
||||
const fullVideoUrl = `https://${videoUrl}`;
|
||||
const data = await getVideo(fullVideoUrl);
|
||||
|
||||
@ -35,16 +34,16 @@ module.exports = function(bot) {
|
||||
const isAudio = mediaUrl.endsWith('.mp3');
|
||||
|
||||
if (isAudio) {
|
||||
// Construct a gallery-like message with multiple images
|
||||
// Construct message with multiple images
|
||||
const mediaArray = data.result.data.images.map(image => ({
|
||||
type: 'photo',
|
||||
media: { url: image }
|
||||
}));
|
||||
|
||||
// Reply with the media group (gallery-like message)
|
||||
// Reply with the media group
|
||||
await ctx.replyWithMediaGroup(mediaArray);
|
||||
|
||||
// Send the audio without a button
|
||||
// Send the audio
|
||||
ctx.replyWithAudio(data.result.data.music);
|
||||
} else {
|
||||
// Reply with video
|
||||
|
@ -1,43 +1,50 @@
|
||||
const axios = require('axios');
|
||||
const fs = require('fs');
|
||||
const getTwitterMedia = require('get-twitter-media');
|
||||
|
||||
async function downloadTwitterVideo(ctx, url) {
|
||||
async function downloadTwitterMedia(ctx, url) {
|
||||
try {
|
||||
const response = await axios.get(`https://aemt.me/download/twtdl?url=${encodeURIComponent(url)}`);
|
||||
let media = await getTwitterMedia(url, {buffer: true});
|
||||
|
||||
if (response.data.status && response.data.result.length > 0) {
|
||||
const videoUrl = response.data.result[0].url;
|
||||
|
||||
// Download the video
|
||||
if (media.found) {
|
||||
if (media.type === 'video' && media.url) {
|
||||
// Download and send the video
|
||||
const videoResponse = await axios({
|
||||
method: 'get',
|
||||
url: videoUrl,
|
||||
url: media.url,
|
||||
responseType: 'stream',
|
||||
});
|
||||
|
||||
// Save the video to a local file
|
||||
const videoFilePath = 'downloaded_video.mp4';
|
||||
const videoStream = fs.createWriteStream(videoFilePath);
|
||||
videoResponse.data.pipe(videoStream);
|
||||
|
||||
videoStream.on('finish', async () => {
|
||||
// Sending the downloaded video to the user
|
||||
// Sending video to the user
|
||||
await ctx.replyWithVideo({ source: videoFilePath });
|
||||
|
||||
// Clean up: remove the downloaded file
|
||||
// Remove the downloaded file
|
||||
fs.unlink(videoFilePath, (err) => {
|
||||
if (err) {
|
||||
console.error('Error deleting video file:', err);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else if (media.type === 'image' && media.url) {
|
||||
// Send the image
|
||||
await ctx.replyWithPhoto({ url: media.url });
|
||||
} else {
|
||||
await ctx.reply('Error: Unable to download the Twitter video.');
|
||||
console.error('Error: Unsupported media type.');
|
||||
await ctx.reply('Unsupported media type.');
|
||||
}
|
||||
} else {
|
||||
console.error('Error: Twitter media not found.');
|
||||
await ctx.reply('Unable to download Twitter media.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error downloading Twitter video:', error);
|
||||
await ctx.reply('Error: Unable to download the Twitter video.');
|
||||
console.error('Error downloading Twitter media:', error);
|
||||
await ctx.reply('Unable to download Twitter media.');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = downloadTwitterVideo;
|
||||
module.exports = downloadTwitterMedia;
|
@ -25,14 +25,14 @@ async function downloadYoutubeVideo(ctx, url) {
|
||||
maxVideoSize = 50 * 1024 * 1024;
|
||||
}
|
||||
|
||||
// Calculate the size of the video in bytes
|
||||
// Max video size
|
||||
const videoSize = parseInt(format.contentLength);
|
||||
if (videoSize > maxVideoSize) {
|
||||
await ctx.reply(`⛔ The video is too large to download (max ${maxVideoSize / (1024 * 1024)}MB).`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get video information for the preview message
|
||||
// Get video information for preview message
|
||||
const videoName = info.videoDetails.title;
|
||||
const views = info.videoDetails.viewCount;
|
||||
const uploadDate = new Date(info.videoDetails.uploadDate).toLocaleDateString();
|
||||
@ -41,7 +41,7 @@ async function downloadYoutubeVideo(ctx, url) {
|
||||
duration.setSeconds(info.videoDetails.lengthSeconds);
|
||||
const durationStr = duration.toISOString().substr(11, 8);
|
||||
|
||||
// Construct the video thumbnail URL
|
||||
// Video thumbnail URL
|
||||
const thumbnailUrl = `https://i.ytimg.com/vi/${videoId}/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAVrdfOFtJegCDgOPWIT2WTNA3XwQ`;
|
||||
|
||||
// Send video preview message with photo
|
||||
@ -50,7 +50,6 @@ async function downloadYoutubeVideo(ctx, url) {
|
||||
parse_mode: 'HTML'
|
||||
});
|
||||
|
||||
// Start downloading
|
||||
await ctx.reply('✅ Start downloading...');
|
||||
|
||||
if (format && audioFormat) {
|
||||
@ -63,7 +62,7 @@ async function downloadYoutubeVideo(ctx, url) {
|
||||
const videoWriteStream = fs.createWriteStream(videoPath);
|
||||
const audioWriteStream = fs.createWriteStream(audioPath);
|
||||
|
||||
// Use `pipeline` to merge the video and audio streams into their respective files
|
||||
// Use pipeline to merge the video and audio streams
|
||||
const { pipeline } = require('stream');
|
||||
await Promise.all([
|
||||
new Promise((resolve, reject) => {
|
||||
@ -80,7 +79,7 @@ async function downloadYoutubeVideo(ctx, url) {
|
||||
}),
|
||||
]);
|
||||
|
||||
// Now that the video and audio streams are saved as separate files, merge them using ffmpeg
|
||||
// Merge video and audio streams using ffmpeg
|
||||
await new Promise((resolve, reject) => {
|
||||
ffmpeg()
|
||||
.input(videoPath)
|
||||
@ -92,14 +91,13 @@ async function downloadYoutubeVideo(ctx, url) {
|
||||
.save(path.join(__dirname, `${videoId}_merged.mp4`));
|
||||
});
|
||||
|
||||
// Send "Uploading" message after merging is complete
|
||||
await ctx.reply('✅ Uploading...');
|
||||
|
||||
// Send the merged video to the user
|
||||
const mergedFilePath = path.join(__dirname, `${videoId}_merged.mp4`);
|
||||
await ctx.replyWithVideo({ source: fs.createReadStream(mergedFilePath) });
|
||||
|
||||
// Clean up the temporary files
|
||||
// Clean up temporary files
|
||||
fs.unlinkSync(videoPath);
|
||||
fs.unlinkSync(audioPath);
|
||||
fs.unlinkSync(mergedFilePath);
|
||||
|
@ -12,7 +12,7 @@
|
||||
" - Youtube(in developing)",
|
||||
" - Tiktok",
|
||||
" - Instagram",
|
||||
" - Twitter(videos)(temporarily not working)",
|
||||
" - Twitter",
|
||||
"",
|
||||
"Feedback - @DivamYT"
|
||||
]
|
||||
|
@ -1,5 +1,12 @@
|
||||
const { Telegraf } = require('telegraf');
|
||||
require('dotenv').config();
|
||||
const cron = require('node-cron');
|
||||
|
||||
// Pinging my site
|
||||
cron.schedule('*/10 * * * *', () => {
|
||||
console.log('Pinging server');
|
||||
fetch('https://aynt.onrender.com/');
|
||||
});
|
||||
|
||||
let bot;
|
||||
if (process.env.LOCAL_SERVER) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user