fix examples and documentation
Build and test / check (pull_request) Successful in 1m58s
Details
Build and test / build (pull_request) Successful in 1m59s
Details
Build and test / docs (pull_request) Successful in 2m44s
Details
Build and test / test (pull_request) Successful in 3m19s
Details
Build and test / build (push) Successful in 1m56s
Details
Build and test / check (push) Successful in 1m50s
Details
Build and test / docs (push) Successful in 2m45s
Details
Build and test / test (push) Successful in 3m29s
Details
Build and test / check (pull_request) Successful in 1m58s
Details
Build and test / build (pull_request) Successful in 1m59s
Details
Build and test / docs (pull_request) Successful in 2m44s
Details
Build and test / test (pull_request) Successful in 3m19s
Details
Build and test / build (push) Successful in 1m56s
Details
Build and test / check (push) Successful in 1m50s
Details
Build and test / docs (push) Successful in 2m45s
Details
Build and test / test (push) Successful in 3m29s
Details
This commit is contained in:
parent
e044246cba
commit
2ed8025046
11
Cargo.toml
11
Cargo.toml
|
@ -1,12 +1,15 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mpvipc"
|
name = "mpvipc"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
authors = ["Jonas Frei <freijon@pm.me>"]
|
authors = [
|
||||||
|
"Jonas Frei <freijon@pm.me>",
|
||||||
|
"h7x4 <h7x4@nani.wtf>"
|
||||||
|
]
|
||||||
description = "A small library which provides bindings to control existing mpv instances through sockets."
|
description = "A small library which provides bindings to control existing mpv instances through sockets."
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
homepage = "https://gitlab.com/mpv-ipc/mpvipc"
|
homepage = "https://git.pvv.ntnu.no/oysteikt/mpvipc"
|
||||||
repository = "https://gitlab.com/mpv-ipc/mpvipc"
|
repository = "https://git.pvv.ntnu.no/oysteikt/mpvipc"
|
||||||
documentation = "https://docs.rs/mpvipc/"
|
documentation = "https://pvv.ntnu.no/~oysteikt/gitea/mpvipc/master/docs/mpvipc/"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.75"
|
rust-version = "1.75"
|
||||||
|
|
||||||
|
|
46
README.md
46
README.md
|
@ -5,46 +5,30 @@
|
||||||
|
|
||||||
A small library which provides bindings to control existing mpv instances through sockets.
|
A small library which provides bindings to control existing mpv instances through sockets.
|
||||||
|
|
||||||
To make use of this library, please make sure mpv is started with the following option:
|
|
||||||
`
|
|
||||||
$ mpv --input-ipc-server=/tmp/mpv.sock --idle ...
|
|
||||||
`
|
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
- `mpv`
|
- `mpv`
|
||||||
- `cargo` (makedep)
|
- `cargo` (make dependency)
|
||||||
|
- `cargo-nextest` (test depencency)
|
||||||
## Install
|
- `grcov` (test depencency)
|
||||||
|
|
||||||
- [Cargo](https://crates.io/crates/mpvipc)
|
|
||||||
|
|
||||||
You can use this package with cargo.
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
Make sure mpv is started with the following option:
|
Make sure mpv is started with the following option:
|
||||||
`
|
|
||||||
|
```bash
|
||||||
$ mpv --input-ipc-server=/tmp/mpv.sock --idle
|
$ mpv --input-ipc-server=/tmp/mpv.sock --idle
|
||||||
`
|
|
||||||
|
|
||||||
Here is a small code example which connects to the socket /tmp/mpv.sock and toggles playback.
|
|
||||||
|
|
||||||
```rust
|
|
||||||
extern crate mpvipc;
|
|
||||||
|
|
||||||
use mpvipc::*;
|
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mpv = Mpv::connect("/tmp/mpv.sock").unwrap();
|
|
||||||
let paused: bool = mpv.get_property("pause").unwrap();
|
|
||||||
mpv.set_property("pause", !paused).expect("Error pausing");
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
For a more extensive example and proof of concept, see project [mpvc](https://gitlab.com/mpv-ipc/mpvc).
|
Here is a small code example which connects to the socket `/tmp/mpv.sock` and toggles playback.
|
||||||
|
|
||||||
## Bugs / Ideas
|
```rust
|
||||||
|
use mpvipc::*;
|
||||||
|
|
||||||
Check out the [Issue Tracker](https://gitlab.com/mpv-ipc/mpvipc/issues)
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), MpvError> {
|
||||||
|
let mpv = Mpv::connect("/tmp/mpv.sock").await?;
|
||||||
|
let paused: bool = mpv.get_property("pause").await?;
|
||||||
|
mpv.set_property("pause", !paused).expect("Error pausing");
|
||||||
|
}
|
||||||
|
```
|
|
@ -1,15 +1,19 @@
|
||||||
use mpvipc::{MpvError, Mpv, MpvExt};
|
use mpvipc::{Mpv, MpvError, MpvExt};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), MpvError> {
|
async fn main() -> Result<(), MpvError> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let mpv = Mpv::connect("/tmp/mpv.sock").await?;
|
let mpv = Mpv::connect("/tmp/mpv.sock").await?;
|
||||||
|
|
||||||
let meta = mpv.get_metadata().await?;
|
let meta = mpv.get_metadata().await?;
|
||||||
println!("metadata: {:?}", meta);
|
println!("metadata: {:?}", meta);
|
||||||
|
|
||||||
let playlist = mpv.get_playlist().await?;
|
let playlist = mpv.get_playlist().await?;
|
||||||
println!("playlist: {:?}", playlist);
|
println!("playlist: {:?}", playlist);
|
||||||
|
|
||||||
let playback_time: f64 = mpv.get_property("playback-time").await?;
|
let playback_time: f64 = mpv.get_property("playback-time").await?;
|
||||||
println!("playback-time: {}", playback_time);
|
println!("playback-time: {}", playback_time);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use mpvipc::{MpvError, Mpv, MpvExt};
|
use futures::StreamExt;
|
||||||
|
use mpvipc::{parse_event_property, Event, Mpv, MpvDataType, MpvError, MpvExt, Property};
|
||||||
|
|
||||||
fn seconds_to_hms(total: f64) -> String {
|
fn seconds_to_hms(total: f64) -> String {
|
||||||
let total = total as u64;
|
let total = total as u64;
|
||||||
|
@ -14,55 +15,49 @@ async fn main() -> Result<(), MpvError> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let mpv = Mpv::connect("/tmp/mpv.sock").await?;
|
let mpv = Mpv::connect("/tmp/mpv.sock").await?;
|
||||||
let pause = false;
|
|
||||||
let playback_time = std::f64::NAN;
|
|
||||||
let duration = std::f64::NAN;
|
|
||||||
mpv.observe_property(1, "path").await?;
|
mpv.observe_property(1, "path").await?;
|
||||||
mpv.observe_property(2, "pause").await?;
|
mpv.observe_property(2, "pause").await?;
|
||||||
mpv.observe_property(3, "playback-time").await?;
|
mpv.observe_property(3, "playback-time").await?;
|
||||||
mpv.observe_property(4, "duration").await?;
|
mpv.observe_property(4, "duration").await?;
|
||||||
mpv.observe_property(5, "metadata").await?;
|
mpv.observe_property(5, "metadata").await?;
|
||||||
loop {
|
|
||||||
// TODO:
|
let mut events = mpv.get_event_stream().await;
|
||||||
// let event = mpv.event_listen()?;
|
while let Some(Ok(event)) = events.next().await {
|
||||||
// match event {
|
match event {
|
||||||
// Event::PropertyChange { id: _, property } => match property {
|
mpvipc::Event::PropertyChange { .. } => match parse_event_property(event)? {
|
||||||
// Property::Path(Some(value)) => println!("\nPlaying: {}[K", value),
|
(1, Property::Path(Some(value))) => println!("\nPlaying: {}", value),
|
||||||
// Property::Path(None) => (),
|
(2, Property::Pause(value)) => {
|
||||||
// Property::Pause(value) => pause = value,
|
println!("Pause: {}", value);
|
||||||
// Property::PlaybackTime(Some(value)) => playback_time = value,
|
}
|
||||||
// Property::PlaybackTime(None) => playback_time = std::f64::NAN,
|
(3, Property::PlaybackTime(Some(value))) => {
|
||||||
// Property::Duration(Some(value)) => duration = value,
|
println!("Playback time: {}", seconds_to_hms(value));
|
||||||
// Property::Duration(None) => duration = std::f64::NAN,
|
}
|
||||||
// Property::Metadata(Some(value)) => {
|
(4, Property::Duration(Some(value))) => {
|
||||||
// println!("File tags:[K");
|
println!("Duration: {}", seconds_to_hms(value));
|
||||||
// if let Some(MpvDataType::String(value)) = value.get("ARTIST") {
|
}
|
||||||
// println!(" Artist: {}[K", value);
|
(5, Property::Metadata(Some(value))) => {
|
||||||
// }
|
println!("File tags:");
|
||||||
// if let Some(MpvDataType::String(value)) = value.get("ALBUM") {
|
if let Some(MpvDataType::String(value)) = value.get("ARTIST") {
|
||||||
// println!(" Album: {}[K", value);
|
println!(" Artist: {}", value);
|
||||||
// }
|
}
|
||||||
// if let Some(MpvDataType::String(value)) = value.get("TITLE") {
|
if let Some(MpvDataType::String(value)) = value.get("ALBUM") {
|
||||||
// println!(" Title: {}[K", value);
|
println!(" Album: {}", value);
|
||||||
// }
|
}
|
||||||
// if let Some(MpvDataType::String(value)) = value.get("TRACK") {
|
if let Some(MpvDataType::String(value)) = value.get("TITLE") {
|
||||||
// println!(" Track: {}[K", value);
|
println!(" Title: {}", value);
|
||||||
// }
|
}
|
||||||
// }
|
if let Some(MpvDataType::String(value)) = value.get("TRACK") {
|
||||||
// Property::Metadata(None) => (),
|
println!(" Track: {}", value);
|
||||||
// Property::Unknown { name: _, data: _ } => (),
|
}
|
||||||
// },
|
}
|
||||||
// Event::Shutdown => return Ok(()),
|
_ => (),
|
||||||
// Event::Unimplemented => panic!("Unimplemented event"),
|
},
|
||||||
// _ => (),
|
Event::Shutdown => return Ok(()),
|
||||||
// }
|
Event::Unimplemented(_) => panic!("Unimplemented event"),
|
||||||
// print!(
|
_ => (),
|
||||||
// "{}{} / {} ({:.0}%)[K\r",
|
}
|
||||||
// if pause { "(Paused) " } else { "" },
|
|
||||||
// seconds_to_hms(playback_time),
|
|
||||||
// seconds_to_hms(duration),
|
|
||||||
// 100. * playback_time / duration
|
|
||||||
// );
|
|
||||||
// io::stdout().flush().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue