Inserting profiles.

This commit is contained in:
Tom Alexander 2022-02-21 21:49:56 -05:00
parent 466af9f1b3
commit 2310889e80
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 24 additions and 2 deletions

View File

@ -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,

View File

@ -41,6 +41,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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;
}
}