Inserting profiles.
This commit is contained in:
parent
466af9f1b3
commit
2310889e80
@ -1,11 +1,11 @@
|
|||||||
CREATE TABLE profile (
|
CREATE TABLE profile (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
UNIQUE(name)
|
UNIQUE(name)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE watched (
|
CREATE TABLE watched (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY,
|
||||||
profile INTEGER NOT NULL,
|
profile INTEGER NOT NULL,
|
||||||
path TEXT NOT NULL,
|
path TEXT NOT NULL,
|
||||||
watched_at DATE NOT NULL,
|
watched_at DATE NOT NULL,
|
||||||
|
22
src/main.rs
22
src/main.rs
@ -41,6 +41,16 @@ 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 (?)"#)
|
||||||
|
.bind(&profile)
|
||||||
|
.execute(&pool)
|
||||||
|
.await?;
|
||||||
|
let count = profile_result.rows_affected();
|
||||||
|
if count != 0 {
|
||||||
|
println!("Profile: {:?}", count);
|
||||||
|
}
|
||||||
|
println!("Profile: {:?}", profile_result);
|
||||||
|
|
||||||
launch_mpv().await?;
|
launch_mpv().await?;
|
||||||
|
|
||||||
// TODO: Figure out a better way to wait for the socket to exist and be connectable
|
// 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 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 = ?)"#)
|
||||||
|
.bind(f.path().as_os_str().to_str())
|
||||||
|
.bind(&profile)
|
||||||
|
.execute(&pool).await?;
|
||||||
|
println!("Result: {:?}", result);
|
||||||
|
|
||||||
println!("Launching {}", f.path().display());
|
println!("Launching {}", f.path().display());
|
||||||
mpvctl.play_video(f.path()).await?;
|
mpvctl.play_video(f.path()).await?;
|
||||||
if let Some(evt) = end_file_listener.recv().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 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 = ?)"#)
|
||||||
|
// .bind(f.path().as_os_str().to_str())
|
||||||
|
// .bind(&profile)
|
||||||
|
// .execute(&pool).await?;
|
||||||
|
// println!("Insert: {:?}", insert);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user