From 66eac50be43750c802dfdf73a926c96e3555925e Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 4 Aug 2024 03:17:23 +0200 Subject: [PATCH] WIP --- Cargo.lock | 2 +- Cargo.toml | 3 ++- src/main.rs | 40 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d40c6e7..c068665 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -480,6 +480,7 @@ dependencies = [ "axum", "clap", "env_logger", + "futures", "log", "mpvipc-async", "serde", @@ -711,7 +712,6 @@ dependencies = [ [[package]] name = "mpvipc-async" version = "0.1.0" -source = "git+https://git.pvv.ntnu.no/oysteikt/mpvipc-async.git?rev=v0.1.0#467cac3c503887c4d6371ec5fdf1b23b3e0eb515" dependencies = [ "futures", "log", diff --git a/Cargo.toml b/Cargo.toml index 1a29c73..9b291bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,9 @@ anyhow = "1.0.82" axum = { version = "0.6.20", features = ["macros"] } clap = { version = "4.4.1", features = ["derive"] } env_logger = "0.10.0" +futures = "0.3.30" log = "0.4.20" -mpvipc-async = { git = "https://git.pvv.ntnu.no/oysteikt/mpvipc-async.git", rev = "v0.1.0" } +mpvipc-async = { path = "../mpvipc-async" } serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.105" tokio = { version = "1.32.0", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index bbd7a3b..7995e47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ use anyhow::Context; use axum::{Router, Server}; use clap::Parser; -use mpvipc_async::Mpv; +use futures::StreamExt; +use mpvipc_async::{parse_property, Mpv, MpvExt, Switch}; use std::{ fs::create_dir_all, net::{IpAddr, SocketAddr}, @@ -155,6 +156,43 @@ async fn main() -> anyhow::Result<()> { mpv.disconnect().await?; proc.kill().await?; } + /* DEBUG */ + _ = async { + let mut event_stream = mpv.get_event_stream().await; + mpv.set_playback(Switch::Off).await.unwrap(); + mpv.observe_property(1, "volume").await.unwrap(); + mpv.observe_property(2, "pause").await.unwrap(); + mpv.observe_property(3, "time-pos").await.unwrap(); + mpv.observe_property(4, "duration").await.unwrap(); + mpv.observe_property(5, "playlist").await.unwrap(); + mpv.observe_property(6, "playlist-pos").await.unwrap(); + mpv.observe_property(7, "tick").await.unwrap(); + mpv.observe_property(8, "eof-reached").await.unwrap(); + mpv.observe_property(9, "speed").await.unwrap(); + mpv.observe_property(10, "filename").await.unwrap(); + mpv.observe_property(11, "media-title").await.unwrap(); + mpv.observe_property(12, "loop-file").await.unwrap(); + mpv.observe_property(13, "loop-playlist").await.unwrap(); + mpv.observe_property(14, "mute").await.unwrap(); + + loop { + let event = event_stream.next().await; + if let Some(Ok(event)) = event { + match &event { + mpvipc_async::Event::PropertyChange { name, data, id } => { + let parsed_event_property = parse_property(name, data.clone()); + log::info!("PropertyChange({}): {:#?}", id, parsed_event_property); + } + event => { + log::info!("Event: {:?}", event); + } + } + } + } + } => { + + } + /* END_DEBUG */ result = async { match Server::try_bind(&addr.clone()).context("Failed to bind server") { Ok(server) => server.serve(app.into_make_service()).await.context("Failed to serve app"),