diff --git a/migrations/00001_create_watched_table.sql b/migrations/00001_create_watched_table.sql index 33abc6b..e5f3e19 100644 --- a/migrations/00001_create_watched_table.sql +++ b/migrations/00001_create_watched_table.sql @@ -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) ); diff --git a/src/main.rs b/src/main.rs index 920a196..f2496d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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> { 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> { + 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(()) } diff --git a/src/mpvctl/mod.rs b/src/mpvctl/mod.rs new file mode 100644 index 0000000..43251b4 --- /dev/null +++ b/src/mpvctl/mod.rs @@ -0,0 +1,3 @@ +mod mpvctl; + +pub use mpvctl::MpvCtl; diff --git a/src/mpvctl/mpvctl.rs b/src/mpvctl/mpvctl.rs new file mode 100644 index 0000000..eaff0a3 --- /dev/null +++ b/src/mpvctl/mpvctl.rs @@ -0,0 +1 @@ +pub struct MpvCtl;