diff --git a/README.md b/README.md deleted file mode 100644 index 8f6aaa3..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# telebot-reverser - -Reverse GIF/Video \ No newline at end of file diff --git a/config.js b/config.js new file mode 100644 index 0000000..06be2f2 --- /dev/null +++ b/config.js @@ -0,0 +1,113 @@ +const fs = require('fs'); + +const Markup = require('telegraf/markup'); +const Extra = require('telegraf/extra'); + +const request = require('request'); +const rev = require("./reverser.js"); + + +//=== TOOL FUNCTIONS + +const ratio = 90.0/100.0; + +var download = function(uri, filename, callback){ + request(uri).on('error', function(err) { + throw err; + }).pipe(fs.createWriteStream(filename)).on('close', callback); +}; + +//=== MAIN MODULE CONFIG + +module.exports = function(){ + return { + name : "Reverser", + key : 'revrs', + version : 0.1, + requirements : { + gps: false, + }, + text : [ + { + trigger : ["/reverse"], + public : true, + desc : { + 0: "Breaks a video/photo/...", + 1: "Detruit une video/photo/...", + }, + requirements : (bot,event,message)=>{ + return new Promise((resolve, reject)=>{ + if(message.reply_to_message){ + return resolve(200); + } + return reject(430); + }); + }, + action : (bot,event,message)=>{ + var id; + var vid = false; + if(message.reply_to_message.document){ + id = message.reply_to_message.document.file_id; + if(message.reply_to_message.document.mime_type.indexOf('image')==0){ + return; + }else if(message.reply_to_message.document.mime_type.indexOf('video')==0){ + + console.log(message.reply_to_message.document); + vid = true; + if(message.reply_to_message.document.mime_type.indexOf('mp4')>0){ + vid = "mp4"; + }else if(message.reply_to_message.document.mime_type.indexOf('avi')>0){ + vid = "avi"; + }else if(message.reply_to_message.document.mime_type.indexOf('mkv')>0){ + vid = "mkv"; + }else{ + return; + } + }else{ + return; + } + }else if(message.reply_to_message.sticker){ + id = message.reply_to_message.sticker.file_id; + return; + }else if(message.reply_to_message.video){ + console.log(message.reply_to_message.video); + if(message.reply_to_message.video.mime_type.indexOf('mp4')>0){ + id = message.reply_to_message.video.file_id; + vid = "mp4"; + }else if(message.reply_to_message.video.mime_type.indexOf('avi')>0){ + id = message.reply_to_message.video.file_id; + vid = "avi"; + }else if(message.reply_to_message.video.mime_type.indexOf('mkv')>0){ + id = message.reply_to_message.video.file_id; + vid = "mkv"; + }else{ + return; + } + }else { + return; + } + if(!vid) + return; + + return bot.telegram.getFileLink(id).then(link=>{ + const file = "/tmp/"+id+"."+vid; + download((link,file),function(){ + rev.reverse(file).then(res=>{ + return event.replyWithVideo({source: res.path}); + }).catch(err=>{bot.error(err)}); + }); + }).catch(err=>{bot.error(err)}); + } + }, + ], + reply : [], + regex : [], + media : [], + callback : [], + inline : [], + new_member : (bot,event)=>{}, + weburl : [], + cron : [], +} + +} \ No newline at end of file diff --git a/reverser.js b/reverser.js new file mode 100644 index 0000000..ce16113 --- /dev/null +++ b/reverser.js @@ -0,0 +1,25 @@ +const path = require('path'); +const down = require('download'); +const hasha = require('hasha'); +const ffmpeg = require('fluent-ffmpeg'); + +const {path: ffPath} = require('@ffmpeg-installer/ffmpeg'); +ffmpeg.setFfmpegPath(ffPath); + +const reverse = file => { + return new Promise((resolve, reject) => { + const basename = path.basename(file); + const savepath = path.join(__dirname, '../outputs', 're-' + basename); + ffmpeg(file) + .videoFilter('reverse') + .on('error', error => reject(error)) + .on('end', async () => resolve({ + path: savepath + })) + .save(savepath); + }); +}; + +module.exports = { + reverse +}; \ No newline at end of file