Launch mpv in an idle process.
This commit is contained in:
parent
111d9026c5
commit
498612a5c0
@ -8,6 +8,6 @@ CREATE TABLE watched (
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
profile INTEGER NOT NULL,
|
profile INTEGER NOT NULL,
|
||||||
path TEXT NOT NULL,
|
path TEXT NOT NULL,
|
||||||
recorded_at DATE NOT NULL,
|
watched_at DATE NOT NULL,
|
||||||
FOREIGN KEY(profile) REFERENCES profile(id)
|
FOREIGN KEY(profile) REFERENCES profile(id)
|
||||||
);
|
);
|
||||||
|
30
src/main.rs
30
src/main.rs
@ -1,12 +1,16 @@
|
|||||||
use sqlx::sqlite::SqliteConnectOptions;
|
use sqlx::sqlite::SqliteConnectOptions;
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::sqlite::SqlitePool;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::process::Stdio;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||||
|
use tokio::process::Command;
|
||||||
use walkdir::DirEntry;
|
use walkdir::DirEntry;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
mod mpvctl;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), sqlx::Error> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
let _program = args.next().expect("argv[0] should be this program?");
|
let _program = args.next().expect("argv[0] should be this program?");
|
||||||
let profile = args.next().expect("Must provide a profile");
|
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());
|
files.sort_by_key(|file| file.path().to_owned());
|
||||||
for f in files {
|
|
||||||
println!("{}", f.path().display());
|
|
||||||
}
|
|
||||||
|
|
||||||
let db_path = dirs::home_dir()
|
let db_path = dirs::home_dir()
|
||||||
.map(|pb| pb.join(".record_watch.sqlite"))
|
.map(|pb| pb.join(".record_watch.sqlite"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let url = format!("sqlite://{}", db_path.as_path().display());
|
let url = format!("sqlite://{}", db_path.as_path().display());
|
||||||
|
|
||||||
println!("{}", &url);
|
|
||||||
|
|
||||||
let pool =
|
let pool =
|
||||||
SqlitePool::connect_with(SqliteConnectOptions::from_str(&url)?.create_if_missing(true))
|
SqlitePool::connect_with(SqliteConnectOptions::from_str(&url)?.create_if_missing(true))
|
||||||
.await?;
|
.await?;
|
||||||
sqlx::migrate!("./migrations").run(&pool).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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
3
src/mpvctl/mod.rs
Normal file
3
src/mpvctl/mod.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
mod mpvctl;
|
||||||
|
|
||||||
|
pub use mpvctl::MpvCtl;
|
1
src/mpvctl/mpvctl.rs
Normal file
1
src/mpvctl/mpvctl.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub struct MpvCtl;
|
Loading…
x
Reference in New Issue
Block a user