-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add spotify dbus wrapper * fix: minor stuff * fix: missing dep * fix: no change signal * feat: add dbus module * refactor: rename module to `mpris_dbus` * refactor: better layout for `mpris-dbus` * refactor: transform macro into function * refactor: make all metadata optional * feat: add support for track number * docs: add documentation on dbus * fix: make `no_autostart` windows only * chore: fix formatting
- Loading branch information
Showing
15 changed files
with
1,274 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "mpris-dbus" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "A wrapper around the org.mpris.MediaPlayer2.Player DBus interface" | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/Nerixyz/current-song2" | ||
keywords = ["unix", "spotify", "dbus"] | ||
categories = ["multimedia"] | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
chrono = "0.4" | ||
derive_more = "0.99.17" | ||
futures = "0.3" | ||
serde = { version = "1", features = ["derive"] } | ||
tap = "1" | ||
thiserror = "1" | ||
tokio = { version = "1.32", features = ["sync", "rt", "macros"] } | ||
tracing = "0.1" | ||
zbus = { version = "3.14", default-features = false, features = ["tokio"] } | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1.32", features = ["sync", "macros", "rt-multi-thread"] } | ||
tracing-subscriber = { version = "0.3", features = ["env-filter"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use mpris_dbus::player; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
tracing_subscriber::fmt() | ||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) | ||
.init(); | ||
|
||
let mut listener = player::listen("org.mpris.MediaPlayer2.spotify") | ||
.await | ||
.unwrap(); | ||
println!("Waiting for events..."); | ||
while let Some(state) = listener.recv().await { | ||
println!("{state:#?}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
use std::collections::HashMap; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use zbus::{dbus_proxy, fdo, zvariant}; | ||
|
||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, zvariant::Type, Deserialize, Serialize)] | ||
#[zvariant(signature = "s")] | ||
pub enum PlaybackStatus { | ||
Playing, | ||
Paused, | ||
#[default] | ||
Stopped, | ||
} | ||
|
||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, zvariant::Type, Deserialize, Serialize)] | ||
#[zvariant(signature = "s")] | ||
pub enum LoopStatus { | ||
#[default] | ||
None, | ||
Track, | ||
Playlist, | ||
} | ||
|
||
#[dbus_proxy( | ||
interface = "org.mpris.MediaPlayer2.Player", | ||
default_path = "/org/mpris/MediaPlayer2", | ||
gen_blocking = false | ||
)] | ||
trait SpotifyPlayer { | ||
// Methods | ||
fn next(&self) -> fdo::Result<()>; | ||
fn previous(&self) -> fdo::Result<()>; | ||
fn pause(&self) -> fdo::Result<()>; | ||
fn play_pause(&self) -> fdo::Result<()>; | ||
fn stop(&self) -> fdo::Result<()>; | ||
fn play(&self) -> fdo::Result<()>; | ||
fn seek(&self, offset: i64) -> fdo::Result<()>; | ||
fn set_position(&self, track_id: zvariant::ObjectPath<'_>, position: i64) -> fdo::Result<()>; | ||
fn open_uri(&self, uri: zvariant::Str<'_>) -> fdo::Result<()>; | ||
|
||
// Signals | ||
#[dbus_proxy(signal)] | ||
fn seeked(&self, position: i64) -> fdo::Result<()>; | ||
|
||
// Properties | ||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn playback_status(&self) -> fdo::Result<PlaybackStatus>; | ||
|
||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn loop_status(&self) -> fdo::Result<LoopStatus>; | ||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn set_loop_status(&self, status: LoopStatus) -> fdo::Result<()>; | ||
|
||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn rate(&self) -> fdo::Result<f64>; | ||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn set_rate(&self, rate: f64) -> fdo::Result<()>; | ||
|
||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn shuffle(&self) -> fdo::Result<bool>; | ||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn set_shuffle(&self, enabled: bool) -> fdo::Result<()>; | ||
|
||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn volume(&self) -> fdo::Result<f64>; | ||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn set_volume(&self, volume: f64) -> fdo::Result<()>; | ||
|
||
#[dbus_proxy(property(emits_changed_signal = "true"))] | ||
fn metadata(&self) -> fdo::Result<HashMap<zvariant::Str<'static>, zvariant::Value>>; | ||
|
||
#[dbus_proxy(property(emits_changed_signal = "false"))] | ||
fn position(&self) -> fdo::Result<i64>; | ||
#[dbus_proxy(property)] | ||
fn minimum_rate(&self) -> fdo::Result<i64>; | ||
#[dbus_proxy(property)] | ||
fn maximum_rate(&self) -> fdo::Result<f64>; | ||
#[dbus_proxy(property)] | ||
fn can_go_next(&self) -> fdo::Result<bool>; | ||
#[dbus_proxy(property)] | ||
fn can_go_previous(&self) -> fdo::Result<bool>; | ||
#[dbus_proxy(property)] | ||
fn can_play(&self) -> fdo::Result<bool>; | ||
#[dbus_proxy(property)] | ||
fn can_pause(&self) -> fdo::Result<bool>; | ||
#[dbus_proxy(property)] | ||
fn can_seek(&self) -> fdo::Result<bool>; | ||
#[dbus_proxy(property)] | ||
fn can_control(&self) -> fdo::Result<bool>; | ||
} | ||
|
||
macro_rules! string_enum_conversions { | ||
($en:ty; $($val:ident => $str:literal),+) => { | ||
impl<'a> From<$en> for zvariant::Value<'a> { | ||
fn from(value: $en) -> Self { | ||
zvariant::Value::Str(zvariant::Str::from_static(match value { | ||
$(<$en>::$val => $str),+ | ||
})) | ||
} | ||
} | ||
|
||
impl TryFrom<zvariant::OwnedValue> for $en { | ||
type Error = zvariant::Error; | ||
|
||
fn try_from(value: zvariant::OwnedValue) -> Result<Self, Self::Error> { | ||
let Ok(s) = <&str>::try_from(&value) else { | ||
return Err(Self::Error::IncorrectType); | ||
}; | ||
match s { | ||
$($str => Ok(Self::$val)),+, | ||
_ => Err(Self::Error::IncorrectType), | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
string_enum_conversions! { LoopStatus; | ||
None => "None", | ||
Track => "Track", | ||
Playlist => "Playlist" | ||
} | ||
|
||
string_enum_conversions! { PlaybackStatus; | ||
Playing => "Playing", | ||
Paused => "Paused", | ||
Stopped => "Stopped" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#![cfg(unix)] | ||
|
||
pub mod interface; | ||
pub mod player; |
Oops, something went wrong.