rename project from `mpvipc` to `mpvipc-async`
This commit is contained in:
parent
cbd8b1aed2
commit
3574c55664
10
Cargo.toml
10
Cargo.toml
|
@ -1,15 +1,15 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mpvipc"
|
name = "mpvipc-async"
|
||||||
version = "1.3.0"
|
version = "0.1.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Jonas Frei <freijon@pm.me>",
|
"Jonas Frei <freijon@pm.me>",
|
||||||
"h7x4 <h7x4@nani.wtf>"
|
"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://git.pvv.ntnu.no/oysteikt/mpvipc"
|
homepage = "https://git.pvv.ntnu.no/oysteikt/mpvipc-async"
|
||||||
repository = "https://git.pvv.ntnu.no/oysteikt/mpvipc"
|
repository = "https://git.pvv.ntnu.no/oysteikt/mpvipc-async"
|
||||||
documentation = "https://pvv.ntnu.no/~oysteikt/gitea/mpvipc/master/docs/mpvipc/"
|
documentation = "https://pvv.ntnu.no/~oysteikt/gitea/mpvipc-async/master/docs/mpvipc-async/"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.75"
|
rust-version = "1.75"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[![Coverage](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc/master/coverage/badges/for_the_badge.svg)](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc/master/coverage/src/)
|
[![Coverage](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc-async/master/coverage/badges/for_the_badge.svg)](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc-async/master/coverage/src/)
|
||||||
[![Docs](https://img.shields.io/badge/docs-blue?style=for-the-badge&logo=rust)](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc/master/docs/mpvipc/)
|
[![Docs](https://img.shields.io/badge/docs-blue?style=for-the-badge&logo=rust)](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc-async/master/docs/mpvipc-async/)
|
||||||
|
|
||||||
# mpvipc
|
# mpvipc-async
|
||||||
|
|
||||||
> **NOTE:** This is a fork of [gitlab.com/mpv-ipc/mpvipc](https://gitlab.com/mpv-ipc/mpvipc), which introduces a lot of changes to be able to use the library asynchronously with [tokio](https://github.com/tokio-rs/tokio).
|
> **NOTE:** This is a fork of [gitlab.com/mpv-ipc/mpvipc](https://gitlab.com/mpv-ipc/mpvipc), which introduces a lot of changes to be able to use the library asynchronously with [tokio](https://github.com/tokio-rs/tokio).
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ $ 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.
|
Here is a small code example which connects to the socket `/tmp/mpv.sock` and toggles playback.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use mpvipc::*;
|
use mpvipc_async::*;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), MpvError> {
|
async fn main() -> Result<(), MpvError> {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use mpvipc::{Mpv, MpvError, MpvExt};
|
use mpvipc_async::{Mpv, MpvError, MpvExt};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), MpvError> {
|
async fn main() -> Result<(), MpvError> {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use mpvipc::{parse_property, Event, Mpv, MpvDataType, MpvError, MpvExt, Property};
|
use mpvipc_async::{parse_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;
|
||||||
|
@ -25,7 +25,7 @@ async fn main() -> Result<(), MpvError> {
|
||||||
let mut events = mpv.get_event_stream().await;
|
let mut events = mpv.get_event_stream().await;
|
||||||
while let Some(Ok(event)) = events.next().await {
|
while let Some(Ok(event)) = events.next().await {
|
||||||
match event {
|
match event {
|
||||||
mpvipc::Event::PropertyChange { name, data, .. } => {
|
mpvipc_async::Event::PropertyChange { name, data, .. } => {
|
||||||
match parse_property(&name, data)? {
|
match parse_property(&name, data)? {
|
||||||
Property::Path(Some(value)) => println!("\nPlaying: {}", value),
|
Property::Path(Some(value)) => println!("\nPlaying: {}", value),
|
||||||
Property::Pause(value) => {
|
Property::Pause(value) => {
|
||||||
|
|
|
@ -321,7 +321,7 @@ impl Mpv {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use mpvipc::{Mpv, MpvError};
|
/// use mpvipc_async::{Mpv, MpvError};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), MpvError> {
|
/// async fn main() -> Result<(), MpvError> {
|
||||||
|
@ -453,7 +453,7 @@ impl Mpv {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use mpvipc::{Mpv, MpvError};
|
/// use mpvipc_async::{Mpv, MpvError};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), MpvError> {
|
/// async fn main() -> Result<(), MpvError> {
|
||||||
|
@ -482,7 +482,7 @@ impl Mpv {
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use mpvipc::{Mpv, MpvError};
|
/// use mpvipc_async::{Mpv, MpvError};
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() -> Result<(), MpvError> {
|
/// async fn main() -> Result<(), MpvError> {
|
||||||
|
@ -521,7 +521,7 @@ impl Mpv {
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use mpvipc::{Mpv, MpvError};
|
/// use mpvipc_async::{Mpv, MpvError};
|
||||||
/// async fn main() -> Result<(), MpvError> {
|
/// async fn main() -> Result<(), MpvError> {
|
||||||
/// let mpv = Mpv::connect("/tmp/mpvsocket").await?;
|
/// let mpv = Mpv::connect("/tmp/mpvsocket").await?;
|
||||||
/// mpv.set_property("pause", true).await?;
|
/// mpv.set_property("pause", true).await?;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use futures::{stream::StreamExt, Stream};
|
use futures::{stream::StreamExt, Stream};
|
||||||
use mpvipc::{parse_property, Event, Mpv, MpvError, MpvExt};
|
use mpvipc_async::{parse_property, Event, Mpv, MpvError, MpvExt, Property};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use tokio::time::{timeout, Duration};
|
use tokio::time::{timeout, Duration};
|
||||||
|
@ -13,14 +13,14 @@ const MPV_CHANNEL_ID: usize = 1337;
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
enum PropertyCheckingThreadError {
|
enum PropertyCheckingThreadError {
|
||||||
#[error("Unexpected property: {0:?}")]
|
#[error("Unexpected property: {0:?}")]
|
||||||
UnexpectedPropertyError(mpvipc::Property),
|
UnexpectedPropertyError(Property),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
MpvError(#[from] MpvError),
|
MpvError(#[from] MpvError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function will create an ongoing tokio task that collects [`Event::PropertyChange`] events,
|
/// This function will create an ongoing tokio task that collects [`Event::PropertyChange`] events,
|
||||||
/// and parses them into [`mpvipc::Property`]s. It will then run the property through the provided
|
/// and parses them into [`Property`]s. It will then run the property through the provided
|
||||||
/// closure, and return an error if the closure returns false.
|
/// closure, and return an error if the closure returns false.
|
||||||
///
|
///
|
||||||
/// The returned cancellation token can be used to stop the task.
|
/// The returned cancellation token can be used to stop the task.
|
||||||
|
@ -32,7 +32,7 @@ fn create_interruptable_event_property_checking_thread<T>(
|
||||||
tokio_util::sync::CancellationToken,
|
tokio_util::sync::CancellationToken,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
T: Fn(mpvipc::Property) -> bool + Send + 'static,
|
T: Fn(Property) -> bool + Send + 'static,
|
||||||
{
|
{
|
||||||
let cancellation_token = tokio_util::sync::CancellationToken::new();
|
let cancellation_token = tokio_util::sync::CancellationToken::new();
|
||||||
let cancellation_token_clone = cancellation_token.clone();
|
let cancellation_token_clone = cancellation_token.clone();
|
||||||
|
@ -122,7 +122,7 @@ async fn test_highlevel_event_pause() -> Result<(), MpvError> {
|
||||||
let events = mpv.get_event_stream().await;
|
let events = mpv.get_event_stream().await;
|
||||||
let (handle, cancellation_token) =
|
let (handle, cancellation_token) =
|
||||||
create_interruptable_event_property_checking_thread(events, |property| match property {
|
create_interruptable_event_property_checking_thread(events, |property| match property {
|
||||||
mpvipc::Property::Pause(_) => {
|
Property::Pause(_) => {
|
||||||
log::debug!("{:?}", property);
|
log::debug!("{:?}", property);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ async fn test_highlevel_event_volume() -> Result<(), MpvError> {
|
||||||
let events = mpv.get_event_stream().await;
|
let events = mpv.get_event_stream().await;
|
||||||
let (handle, cancellation_token) =
|
let (handle, cancellation_token) =
|
||||||
create_interruptable_event_property_checking_thread(events, |property| match property {
|
create_interruptable_event_property_checking_thread(events, |property| match property {
|
||||||
mpvipc::Property::Volume(_) => {
|
Property::Volume(_) => {
|
||||||
log::trace!("{:?}", property);
|
log::trace!("{:?}", property);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ async fn test_highlevel_event_mute() -> Result<(), MpvError> {
|
||||||
let events = mpv.get_event_stream().await;
|
let events = mpv.get_event_stream().await;
|
||||||
let (handle, cancellation_token) =
|
let (handle, cancellation_token) =
|
||||||
create_interruptable_event_property_checking_thread(events, |property| match property {
|
create_interruptable_event_property_checking_thread(events, |property| match property {
|
||||||
mpvipc::Property::Mute(_) => {
|
Property::Mute(_) => {
|
||||||
log::trace!("{:?}", property);
|
log::trace!("{:?}", property);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ async fn test_highlevel_event_duration() -> Result<(), MpvError> {
|
||||||
let events = mpv.get_event_stream().await;
|
let events = mpv.get_event_stream().await;
|
||||||
let (handle, cancellation_token) =
|
let (handle, cancellation_token) =
|
||||||
create_interruptable_event_property_checking_thread(events, |property| match property {
|
create_interruptable_event_property_checking_thread(events, |property| match property {
|
||||||
mpvipc::Property::Duration(_) => {
|
Property::Duration(_) => {
|
||||||
log::trace!("{:?}", property);
|
log::trace!("{:?}", property);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use mpvipc::{MpvError, MpvExt};
|
use mpvipc_async::{MpvError, MpvExt};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{path::Path, time::Duration};
|
use std::{path::Path, time::Duration};
|
||||||
|
|
||||||
use mpvipc::{Mpv, MpvError};
|
use mpvipc_async::{Mpv, MpvError};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
process::{Child, Command},
|
process::{Child, Command},
|
||||||
time::{sleep, timeout},
|
time::{sleep, timeout},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use futures::{stream::StreamExt, SinkExt};
|
use futures::{stream::StreamExt, SinkExt};
|
||||||
use mpvipc::{Event, Mpv, MpvDataType, MpvExt};
|
use mpvipc_async::{Event, Mpv, MpvDataType, MpvExt};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use test_log::test;
|
use test_log::test;
|
||||||
use tokio::{net::UnixStream, task::JoinHandle};
|
use tokio::{net::UnixStream, task::JoinHandle};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{panic, time::Duration};
|
use std::{panic, time::Duration};
|
||||||
|
|
||||||
use futures::{stream::FuturesUnordered, SinkExt, StreamExt};
|
use futures::{stream::FuturesUnordered, SinkExt, StreamExt};
|
||||||
use mpvipc::{Mpv, MpvError, MpvExt, Playlist, PlaylistEntry};
|
use mpvipc_async::{Mpv, MpvError, MpvExt, Playlist, PlaylistEntry};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use test_log::test;
|
use test_log::test;
|
||||||
use tokio::{net::UnixStream, task::JoinHandle};
|
use tokio::{net::UnixStream, task::JoinHandle};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{panic, time::Duration};
|
use std::{panic, time::Duration};
|
||||||
|
|
||||||
use futures::{stream::FuturesUnordered, SinkExt, StreamExt};
|
use futures::{stream::FuturesUnordered, SinkExt, StreamExt};
|
||||||
use mpvipc::{Mpv, MpvError};
|
use mpvipc_async::{Mpv, MpvError};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use test_log::test;
|
use test_log::test;
|
||||||
use tokio::{net::UnixStream, task::JoinHandle};
|
use tokio::{net::UnixStream, task::JoinHandle};
|
||||||
|
|
Loading…
Reference in New Issue