Launch mpv in an idle process.

master
Tom Alexander 2 years ago
parent 111d9026c5
commit 498612a5c0
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -8,6 +8,6 @@ CREATE TABLE watched (
id INTEGER PRIMARY KEY AUTOINCREMENT,
profile INTEGER NOT NULL,
path TEXT NOT NULL,
recorded_at DATE NOT NULL,
watched_at DATE NOT NULL,
FOREIGN KEY(profile) REFERENCES profile(id)
);

@ -1,12 +1,16 @@
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::sqlite::SqlitePool;
use std::env;
use std::process::Stdio;
use std::str::FromStr;
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::process::Command;
use walkdir::DirEntry;
use walkdir::WalkDir;
mod mpvctl;
#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut args = env::args();
let _program = args.next().expect("argv[0] should be this program?");
let profile = args.next().expect("Must provide a profile");
@ -23,21 +27,35 @@ async fn main() -> Result<(), sqlx::Error> {
}
files.sort_by_key(|file| file.path().to_owned());
for f in files {
println!("{}", f.path().display());
}
let db_path = dirs::home_dir()
.map(|pb| pb.join(".record_watch.sqlite"))
.unwrap();
let url = format!("sqlite://{}", db_path.as_path().display());
println!("{}", &url);
let pool =
SqlitePool::connect_with(SqliteConnectOptions::from_str(&url)?.create_if_missing(true))
.await?;
sqlx::migrate!("./migrations").run(&pool).await?;
for f in files {
println!("Launching {}", f.path().display());
}
launch_mpv().await?;
Ok(())
}
async fn launch_mpv() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::new("mpv");
cmd.arg("--input-ipc-server=/tmp/recordwatchsocket")
.arg("--idle");
cmd.kill_on_drop(true);
let mut child = cmd.spawn().expect("failed to spawn command");
// Launch the child in the runtime so it can run without blocking this thread
tokio::spawn(async move {
let status = child.wait().await.expect("mpv encountered an error");
println!("mpv status was: {}", status);
});
Ok(())
}

@ -0,0 +1,3 @@
mod mpvctl;
pub use mpvctl::MpvCtl;

@ -0,0 +1 @@
pub struct MpvCtl;
Loading…
Cancel
Save