@@ -111,7 +111,32 @@ impl Player {
111
111
///
112
112
/// See: [MPRIS2 specification about bus names][bus_names].
113
113
///
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
+ ///
114
134
/// [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
+ ) ]
115
140
pub fn bus_name_player_name_part ( & self ) -> & str {
116
141
self . bus_name ( )
117
142
. trim_start_matches ( MPRIS2_PREFIX )
@@ -120,6 +145,16 @@ impl Player {
120
145
. unwrap ( )
121
146
}
122
147
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
+
123
158
/// Returns the player's unique D-Bus bus name (usually something like `:1.1337`).
124
159
pub fn unique_name ( & self ) -> & str {
125
160
& self . unique_name
0 commit comments