@ -59,19 +59,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut mpvctl = MpvCtl ::connect ( "/tmp/recordwatchsocket" ) . await ? ;
let mut end_file_listener = mpvctl . listen ( & [ "end-file" ] ) ? ;
for f in files {
let canonicalized_path = f . path ( ) . canonicalize ( ) ? ;
let already_watched_count : i64 = sqlx ::query ( r#"SELECT count(*) FROM watched WHERE path = ? AND profile = (SELECT id FROM PROFILE WHERE name = ?)"# )
. bind ( f. path ( ) . as_os_str ( ) . to_str ( ) )
. bind ( canonicalized_path . as_os_str ( ) . to_str ( ) )
. bind ( & profile )
. fetch_one ( & mut dbconn ) . await ? . try_get ( "count(*)" ) ? ;
println! ( "Already watched count: {}" , already_watched_count ) ;
if already_watched_count > 0 {
println! ( "Skipping: Already watched {}" , f. path ( ) . display ( ) ) ;
println! ( "Skipping: Already watched {}" , canonicalized_path . display ( ) ) ;
continue ;
}
println! ( "Launching {}" , f. path ( ) . display ( ) ) ;
mpvctl . play_video ( f . path ( ) ) . await ? ;
println! ( "Launching {}" , canonicalized_path . display ( ) ) ;
mpvctl . play_video ( & canonicalized_path ) . await ? ;
if let Some ( evt ) = end_file_listener . recv ( ) . await {
println! ( "end file event {}" , evt ) ;
if let serde_json ::Value ::Object ( obj ) = evt {
@ -81,7 +82,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Watched the video until the end
let insert : u64 = 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 ( ) )
. bind ( canonicalized_path . as_os_str ( ) . to_str ( ) )
. execute ( & mut dbconn ) . await ? . rows_affected ( ) ;
println! ( "Insert: {:?}" , insert ) ;
assert! ( insert = = 1 ) ;