This commit is contained in:
Oystein Kristoffer Tveit 2024-08-04 03:17:23 +02:00
parent 894cc4e146
commit 66eac50be4
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
3 changed files with 42 additions and 3 deletions

2
Cargo.lock generated
View File

@ -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",

View File

@ -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"] }

View File

@ -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"),