diff --git a/migrations/00001_create_watched_table.sql b/migrations/00001_create_watched_table.sql index e5f3e19..06c833e 100644 --- a/migrations/00001_create_watched_table.sql +++ b/migrations/00001_create_watched_table.sql @@ -1,11 +1,11 @@ CREATE TABLE profile ( - id INTEGER PRIMARY KEY AUTOINCREMENT, + id INTEGER PRIMARY KEY, name TEXT NOT NULL, UNIQUE(name) ); CREATE TABLE watched ( - id INTEGER PRIMARY KEY AUTOINCREMENT, + id INTEGER PRIMARY KEY, profile INTEGER NOT NULL, path TEXT NOT NULL, watched_at DATE NOT NULL, diff --git a/src/main.rs b/src/main.rs index f501901..7313bbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,16 @@ async fn main() -> Result<(), Box> { .await?; sqlx::migrate!("./migrations").run(&pool).await?; + let profile_result = sqlx::query(r#"INSERT OR IGNORE INTO profile (name) VALUES (?)"#) + .bind(&profile) + .execute(&pool) + .await?; + let count = profile_result.rows_affected(); + if count != 0 { + println!("Profile: {:?}", count); + } + println!("Profile: {:?}", profile_result); + launch_mpv().await?; // TODO: Figure out a better way to wait for the socket to exist and be connectable @@ -50,6 +60,12 @@ async fn main() -> Result<(), Box> { let mut end_file_listener = mpvctl.listen(&["end-file"])?; let client_name = mpvctl.get_client_name().await?; for f in files { + let result = sqlx::query(r#"SELECT 1 FROM watched WHERE path = ? AND profile = (SELECT id FROM PROFILE WHERE name = ?)"#) + .bind(f.path().as_os_str().to_str()) + .bind(&profile) + .execute(&pool).await?; + println!("Result: {:?}", result); + println!("Launching {}", f.path().display()); mpvctl.play_video(f.path()).await?; if let Some(evt) = end_file_listener.recv().await { @@ -59,6 +75,12 @@ async fn main() -> Result<(), Box> { if let Some(serde_json::Value::String(reason_body)) = reason { if reason_body == "eof" { // Watched the video until the end + // let insert = sqlx::query(r#"INTO INTO watched (profile, path, watched_at)WHERE path = ? AND profile = (SELECT id FROM PROFILE WHERE name = ?)"#) + // .bind(f.path().as_os_str().to_str()) + // .bind(&profile) + // .execute(&pool).await?; + // println!("Insert: {:?}", insert); + continue; } }