mpv_send/src/main.rs

49 lines
1.3 KiB
Rust

#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
use std::env;
use std::path::Path;
use std::process::Command;
use rocket::request::Form;
use rocket_contrib::serve::StaticFiles;
use rocket::response::Redirect;
#[derive(FromForm)]
struct Video {
link: String,
}
#[post("/new", data = "<video>")]
fn new(video: Form<Video>) -> Redirect {
for part in video.link.split(" ") {
if part.starts_with("https://"){
Command::new("/bin/env")
// .args(&[&video.link])
.args(&["DISPLAY=:0", "bash", "-c", &format!("mpv {link}", link=&part).to_string()])
.output()
.expect("Failed to execute command");
}
}
Redirect::to("/")
}
fn main() {
let env_config_path = match env::var("CONFIG_PATH") {
Ok(val) => val,
Err(_e) => panic!("Please provide a config path via the CONFIG_PATH env variable!"),
};
let config_path = Path::new(&env_config_path);
match env::set_current_dir(&config_path).is_ok() {
true => println!("Config path set"),
false => panic!("Config path could not be set!"),
};
rocket::ignite()
.mount("/", routes![new])
.mount("/", StaticFiles::from("static"))
.launch();
}