Skip to content

Commit 26f603a

Browse files
committed
Deprecate bus_name_player_name_part
1 parent 26176cb commit 26f603a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `Player::bus_name_trimmed()` which returns the player's bus name without the
13+
MPRIS2 prefix - [Kanjirito][Kanjirito]
14+
15+
### Deprecated
16+
17+
- `Player::bus_name_player_name_part()` is now deprecated and will be removed
18+
in the next major release. See the method's documentation and [#81][#81] for
19+
details and workarounds.
20+
1021
### Removed
1122

1223
- Removed `derive_is_enum_variant` dependency. - [poly000][poly000]
@@ -230,3 +241,4 @@ MetadataValue>, DBusError>`.
230241
[fengalin]: https://github.com/fengalin
231242
[fufexan]: https://github.com/fufexan
232243
[poly000]: https://github.com/poly000
244+
[#81]: https://github.com/Mange/mpris-rs/issues/81

src/player.rs

+35
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,32 @@ impl Player {
111111
///
112112
/// See: [MPRIS2 specification about bus names][bus_names].
113113
///
114+
/// **Deprecation information:** The MPRIS2 specification doesn't specify how the unique instance
115+
/// identifier part of the bus name should look, therefore every player can ignore the example
116+
/// and implement it in its own way. This method was trying to guess the instance part and was
117+
/// not always successful. See [this issue][issue] for the relevant discussion.
118+
/// In the case when [`identity`][Self::identity] is not able to differentiate the players so
119+
/// you need to filter out players by their bus names you should filter the results of [`PlayerFinder`][crate::find::PlayerFinder].
120+
/// For example:
121+
/// ```no_run
122+
/// use mpris::PlayerFinder;
123+
/// let finder = PlayerFinder::new().unwrap();
124+
/// for player in finder
125+
/// .iter_players()
126+
/// .unwrap()
127+
/// .map(|p| p.unwrap())
128+
/// .filter(|p| p.bus_name_trimmed().starts_with("mpv"))
129+
/// {
130+
/// // Do something with only mpv instances
131+
/// }
132+
///```
133+
///
114134
/// [bus_names]: https://specifications.freedesktop.org/mpris-spec/latest/#Bus-Name-Policy
135+
/// [issue]: https://github.com/Mange/mpris-rs/issues/81
136+
#[deprecated(
137+
since = "2.1.0",
138+
note = "See documentation for explanation, use `bus_name_trimmed` instead"
139+
)]
115140
pub fn bus_name_player_name_part(&self) -> &str {
116141
self.bus_name()
117142
.trim_start_matches(MPRIS2_PREFIX)
@@ -120,6 +145,16 @@ impl Player {
120145
.unwrap()
121146
}
122147

148+
/// Returns the player name part of the player's D-Bus bus name with the MPRIS2 prefix trimmed.
149+
///
150+
/// Examples:
151+
/// - `org.mpris.MediaPlayer2.io.github.celluloid_player.Celluloid` -> `io.github.celluloid_player.Celluloid`
152+
/// - `org.mpris.MediaPlayer2.Spotify.` -> `Spotify`
153+
/// - `org.mpris.MediaPlayer2.mpv.instance123` -> `mpv.instance123`
154+
pub fn bus_name_trimmed(&self) -> &str {
155+
self.bus_name().trim_start_matches(MPRIS2_PREFIX)
156+
}
157+
123158
/// Returns the player's unique D-Bus bus name (usually something like `:1.1337`).
124159
pub fn unique_name(&self) -> &str {
125160
&self.unique_name

0 commit comments

Comments
 (0)