33 lines
984 B
Rust
33 lines
984 B
Rust
|
#![feature(proc_macro_hygiene, decl_macro)]
|
||
|
|
||
|
#[macro_use] extern crate rocket;
|
||
|
|
||
|
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 {
|
||
|
// let mpv_script_path = "/home/hans/mpv_send.sh";
|
||
|
if video.link.starts_with("https://"){
|
||
|
// Command::new(mpv_script_path).arg(&video.link).output().expect("Failed to execute command");
|
||
|
// Command::new(mpv_script_path).arg(&video.link).output().expect("Failed to execute command");
|
||
|
Command::new("/bin/env").args(&["bash", "-c", &format!("mpv {link}", link=&video.link).to_string()]).output().expect("Failed to execute command");
|
||
|
}
|
||
|
Redirect::to("/")
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
rocket::ignite()
|
||
|
.mount("/", routes![new])
|
||
|
.mount("/", StaticFiles::from("static"))
|
||
|
.launch();
|
||
|
}
|
||
|
|