Inserting watched entries but not reading them correctly.

master
Tom Alexander 2 years ago
parent 2310889e80
commit 9f51c953fe
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -1,10 +1,6 @@
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::sqlite::SqlitePool;
use std::env;
use std::path::Path;
use std::process::Stdio;
use std::str::FromStr;
use tokio::io::{AsyncBufReadExt, BufReader};
use std::{env, str::FromStr};
use tokio::process::Command;
use walkdir::DirEntry;
use walkdir::WalkDir;
@ -41,15 +37,14 @@ 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 (?)"#)
let profiles_created: u64 = 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);
.await?
.rows_affected();
if profiles_created != 0 {
println!("Created a new profile");
}
println!("Profile: {:?}", profile_result);
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 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 = ?)"#)
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(&profile)
.execute(&pool).await?;
println!("Result: {:?}", result);
.execute(&pool).await?.rows_affected();
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());
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 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);
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(&profile)
.bind(f.path().as_os_str().to_str())
.execute(&pool).await?;
println!("Insert: {:?}", insert);
continue;
}

Loading…
Cancel
Save