Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-05-09 03:54:25 +05:30
parent d170ae0e1a
commit 0113466c87
12 changed files with 2845 additions and 329 deletions

View File

@@ -1,4 +1,4 @@
use crate::lib::ffmpeg::FfmpegTranscode;
use crate::lib::{ffmpeg::FfmpegTranscode, messages::ExtractInfo};
use serenity::{
framework::standard::{macros::command, Args, CommandResult},
http::AttachmentType,
@@ -13,11 +13,11 @@ pub const IMAGE_EXTS: [&'static str; 6] = ["png", "gif", "bmp", "webp", "jpg", "
#[command]
#[aliases("mux")]
pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let q: Vec<&str> = args.raw().collect::<Vec<&str>>();
if q.len() < 2 || q.len() > 4 {
let q = msg.extract_urls().urls;
if q.len() < 2 {
msg.reply(
ctx,
"Please use the proper syntax: `xxremux <audio> <video> [audio_codec] [video_codec]`",
"Please use the proper syntax: `xxremux <audio> <video> [audio_codec] [video_codec]`"
)
.await?;
return Ok(());
@@ -25,13 +25,13 @@ pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let mut trans = FfmpegTranscode::default();
trans.add_input(q[0]);
trans.add_input(&q[0]);
trans.set_acodec("copy");
let mut ext = Path::new(&q[1]).extension().unwrap().to_str().unwrap();
if IMAGE_EXTS.contains(&ext) {
let resp = reqwest::get(q[1]).await?;
let resp = reqwest::get(&q[1]).await?;
let p = format!("/tmp/{}{}-image.{}", "singh4-", msg.id, ext);
let mut f = File::create(&p).await?;
tokio::io::copy(&mut resp.bytes().await?.as_ref(), &mut f).await?;
@@ -44,19 +44,20 @@ pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
.add_input(&p)
.set_vcodec("h264")
.add_arg("vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2") //to correct the dimensions
.add_arg("tune", "stillimage");
.add_arg("tune", "stillimage")
.add_arg("pix_fmt", "yuv420p");
ext = "mp4";
} else {
trans.add_input(q[1]).set_vcodec("copy");
trans.add_input(&q[1]).set_vcodec("copy");
}
if q.len() > 2 {
/* if q.len() > 2 {
trans.set_acodec(q[2]);
}
if q.len() > 3 {
trans.set_vcodec(q[3]);
}
}*/
let output = format!("/tmp/{}{}.{}", "singh4-", msg.id, ext);

View File

@@ -3,11 +3,11 @@ use serenity::model::channel::Message;
#[derive(Default)]
pub struct URLExtractInfo {
urls: Vec<String>,
n_attachments: u8,
n_links: u16,
rn_attachments: Option<u8>,
rn_links: Option<u16>,
pub urls: Vec<String>,
pub n_attachments: u8,
pub n_links: u16,
pub rn_attachments: Option<u8>,
pub rn_links: Option<u16>,
}
pub trait ExtractInfo {

View File

@@ -1 +1,2 @@
pub mod ffmpeg;
pub mod messages;