Inserting watched entries but not reading them correctly.
This commit is contained in:
parent
2310889e80
commit
9f51c953fe
37
src/main.rs
37
src/main.rs
@ -1,10 +1,6 @@
|
|||||||
use sqlx::sqlite::SqliteConnectOptions;
|
use sqlx::sqlite::SqliteConnectOptions;
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::sqlite::SqlitePool;
|
||||||
use std::env;
|
use std::{env, str::FromStr};
|
||||||
use std::path::Path;
|
|
||||||
use std::process::Stdio;
|
|
||||||
use std::str::FromStr;
|
|
||||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
use walkdir::DirEntry;
|
use walkdir::DirEntry;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
@ -41,15 +37,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.await?;
|
.await?;
|
||||||
sqlx::migrate!("./migrations").run(&pool).await?;
|
sqlx::migrate!("./migrations").run(&pool).await?;
|
||||||
|
|
||||||
let profile_result = sqlx::query(r#"INSERT OR IGNORE INTO profile (name) VALUES (?)"#)
|
let profiles_created: u64 = sqlx::query(r#"INSERT OR IGNORE INTO profile (name) VALUES (?)"#)
|
||||||
.bind(&profile)
|
.bind(&profile)
|
||||||
.execute(&pool)
|
.execute(&pool)
|
||||||
.await?;
|
.await?
|
||||||
let count = profile_result.rows_affected();
|
.rows_affected();
|
||||||
if count != 0 {
|
if profiles_created != 0 {
|
||||||
println!("Profile: {:?}", count);
|
println!("Created a new profile");
|
||||||
}
|
}
|
||||||
println!("Profile: {:?}", profile_result);
|
|
||||||
|
|
||||||
launch_mpv().await?;
|
launch_mpv().await?;
|
||||||
|
|
||||||
@ -60,11 +55,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let mut end_file_listener = mpvctl.listen(&["end-file"])?;
|
let mut end_file_listener = mpvctl.listen(&["end-file"])?;
|
||||||
let client_name = mpvctl.get_client_name().await?;
|
let client_name = mpvctl.get_client_name().await?;
|
||||||
for f in files {
|
for f in files {
|
||||||
let result = sqlx::query(r#"SELECT 1 FROM watched WHERE path = ? AND profile = (SELECT id FROM PROFILE WHERE name = ?)"#)
|
let already_watched_count = 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(f.path().as_os_str().to_str())
|
||||||
.bind(&profile)
|
.bind(&profile)
|
||||||
.execute(&pool).await?;
|
.execute(&pool).await?.rows_affected();
|
||||||
println!("Result: {:?}", result);
|
println!("Already watched count: {}", already_watched_count);
|
||||||
|
if already_watched_count > 0 {
|
||||||
|
println!("Skipping: Already watched {}", f.path().display());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
println!("Launching {}", f.path().display());
|
println!("Launching {}", f.path().display());
|
||||||
mpvctl.play_video(f.path()).await?;
|
mpvctl.play_video(f.path()).await?;
|
||||||
@ -75,11 +74,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
if let Some(serde_json::Value::String(reason_body)) = reason {
|
if let Some(serde_json::Value::String(reason_body)) = reason {
|
||||||
if reason_body == "eof" {
|
if reason_body == "eof" {
|
||||||
// Watched the video until the end
|
// 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 = ?)"#)
|
let insert = sqlx::query(r#"INSERT INTO watched (profile, path, watched_at) SELECT (SELECT id FROM PROFILE WHERE name = ?) profile, ? path, DATETIME('now') watched_at"#)
|
||||||
// .bind(f.path().as_os_str().to_str())
|
.bind(&profile)
|
||||||
// .bind(&profile)
|
.bind(f.path().as_os_str().to_str())
|
||||||
// .execute(&pool).await?;
|
.execute(&pool).await?;
|
||||||
// println!("Insert: {:?}", insert);
|
println!("Insert: {:?}", insert);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user