Skip to main content

bluos_api_rs/device/
responses.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize, PartialEq)]
4#[serde(rename_all = "camelCase")]
5pub struct Status {
6    pub etag: String,
7    ////////////////
8    // Volume
9    /////////////////
10    /// The player volume level in percentage
11    /// -1 means player volume fixed.
12    pub volume: i64,
13    /// Volume in decibel
14    #[serde(rename = "db")]
15    pub volume_decibel: f64,
16    /// Mute state. Set to 1 if volume is muted
17    pub mute: u8,
18    /// If the player is muted, then this contains the unmuted volume level.
19    /// Values are from 0 to 100.
20    #[serde(rename = "muteVolume")]
21    pub muted_volume: Option<i64>,
22    /// If the player is muted, then this contains the unmuted volume in dB.
23    #[serde(rename = "muteDb")]
24    pub muted_decibel: Option<i64>,
25
26    ////////////////
27    // Playback
28    /////////////////
29    /// The title of the current playing audio track. Also see title1 attribute.
30    pub name: Option<String>,
31    /// Album name of the current active track. Also see title1 attribute.
32    pub album: Option<String>,
33    /// Artist name of the current active track. Also see title1 attribute.
34    pub artist: Option<String>,
35    /// Total length of the current track, in seconds
36    #[serde(rename = "totlen")]
37    pub total_length: Option<i64>,
38    /// The number of seconds the current audio track has been played
39    #[serde(rename = "secs")]
40    pub seconds_played: Option<i64>,
41
42    /// 0, 1, or 2. 0 means repeat play queue, 1 means repeat a track, and 2 means repeat off
43    pub repeat: u8,
44    /// 0 or 1. 0 means shuffle off and 1 means shuffle on
45    pub shuffle: u8,
46
47    /// The position of the current track in the play queue. Also see streamUrl.
48    #[serde(rename = "song")]
49    pub song_queue_position: i64,
50    /// Quality of the playing source audio:
51    ///
52    /// • cd - losless audio at CD quality
53    /// • hd – lossless audio with higher resolution that CD quality or samplerate of 88200 samples/s or more
54    /// • dolbyAudio – DolbyDigital or AC3
55    /// • mqa – valid MQA audio decoded
56    /// • mqaAuthored - valid MQA-Authored audio decoded
57    /// A numeric value is the approximate bitrate of a compressed audio source quality of the file.
58    pub quality: Option<Quality>,
59    #[serde(rename = "fn")]
60    pub filename: Option<String>,
61    ////////////////
62    // Display
63    /////////////////
64    /// URL of image associated with the current audio (album, station, input, etc.)
65    pub image: Option<String>,
66    /// The first line of information describing the current audio.
67    /// title1, title2 and title3 MUST be used as the text of any UI that displays three lines of now-playing
68    // metadata. Do not use values such as album, artist and name.
69    pub title1: Option<String>,
70    /// The second line of information describing the current audio.
71    pub title2: Option<String>,
72    /// The third line of information describing the current audio.
73    pub title3: Option<String>,
74
75    /// The first of two lines describing the current audio.
76    /// twoline_title1 & twoline_title2, if present, MUST be used as the text of any UI that displays two
77    /// lines of now-playing metadata.
78    pub twoline_title1: Option<String>,
79    /// The second of two lines describing the current audio.
80    pub twoline_title2: Option<String>,
81
82    /// What the player displays currently?
83    pub current_image: Option<String>,
84
85    ////////////////
86    // Group
87    /////////////////
88    /// Name of the group. The player must be the primary player in the group.
89    pub group_name: Option<String>,
90    /// Volume level of the group. The player must be the primary player in the group
91    pub group_volume: Option<String>,
92
93    ////////////////
94    // Abiltes
95    /////////////////
96    pub actions: Option<Actions>,
97    pub can_seek: Option<u8>,
98    pub can_move_playback: Option<bool>,
99
100    ////////////////
101    // System
102    /////////////////
103    ///URL for a pop up notification
104    notify_url: Option<String>,
105
106    pub mode: i64,
107    /// The unique play queue id. It matches the id attribute of the /Playlist response. If
108    /// the play queue is changed this number will change
109    pub pid: i64,
110    /// The unique preset id. It matches the prid attribute in the /Presets response. If a
111    /// preset is changed this number will change indicating that any cached response to
112    /// /Presets should be purged.
113    pub prid: u8,
114
115    pub sid: i64,
116    /// The current player state. It could be play, pause, stop, stream, connecting, etc.
117    /// /Play can be used to resume when in a pause state but not when in stop state
118    pub state: String,
119    pub stream_url: Option<String>,
120    pub sync_stat: i64,
121
122    ////////////////
123    // Undocumented
124    /////////////////
125    pub cursor: Option<i64>,
126    /// Most likely inidicating if the player is currently indexing
127    pub indexing: i64,
128    pub mid: i64,
129}
130
131#[derive(Debug, Serialize, Deserialize, PartialEq)]
132pub struct Actions {
133    pub action: Vec<Action>,
134}
135
136#[derive(Debug, Serialize, Deserialize, PartialEq)]
137pub struct Action {
138    pub hide: u8,
139    pub name: String,
140}
141
142#[derive(Debug, Serialize, Deserialize, PartialEq)]
143#[serde(rename_all = "camelCase")]
144#[serde(rename = "$value")]
145pub enum State {
146    Stop,
147    Play,
148    Pause,
149    Stream,
150    Connecting,
151}
152
153#[derive(Debug, Serialize, Deserialize, PartialEq)]
154#[serde(rename_all = "camelCase", from = "String")]
155pub enum Quality {
156    /// losless audio at CD quality
157    Cd,
158    /// lossless audio with higher resolution that CD quality or samplerate of 88200 samples/s or more
159    Hd,
160    /// DolbyDigital or AC3
161    DolbyAudio,
162    ///  valid MQA audio decoded
163    Mqa,
164    /// valid MQA-Authored audio decoded
165    MqaAuthored,
166    /// A numeric value is the approximate bitrate of a compressed audio source quality
167    Compressed(i64),
168}
169
170impl From<String> for Quality {
171    fn from(s: String) -> Self {
172        use Quality::*;
173
174        return match s.as_str() {
175            "cd" => Cd,
176            "hd" => Hd,
177            "dolbyAudio" => DolbyAudio,
178            "mqa" => Mqa,
179            "mqaAuthored" => MqaAuthored,
180            _ => Compressed(s.parse::<i64>().unwrap_or_default()),
181        };
182    }
183}
184
185#[derive(Debug, Serialize, Deserialize, PartialEq)]
186#[serde(rename_all = "camelCase")]
187pub struct StateResponse {
188    #[serde(rename = "$value")]
189    pub state: State,
190}
191
192#[derive(Debug, Serialize, Deserialize, PartialEq)]
193#[serde(rename_all = "camelCase")]
194pub struct IdResponse {
195    #[serde(rename = "$value")]
196    pub id: Option<i64>,
197}
198
199#[derive(Debug, Serialize, Deserialize, PartialEq)]
200#[serde(rename_all = "camelCase")]
201pub struct Playlist {
202    /// unique id for the current queue state
203    pub id: i64,
204    /// The current play queue name.
205    pub name: Option<String>,
206    /// 0 means the queue hasn’t been modified since it was loaded.
207    /// 1 means the queue has been modified since it was loaded.
208    pub modified: i64,
209    /// total number of tracks in the current queue
210    pub length: i64,
211    #[serde(rename = "$value")]
212    pub entries: Vec<PlaylistEntry>,
213}
214
215#[derive(Debug, Serialize, Deserialize, PartialEq)]
216#[serde(rename_all = "camelCase")]
217pub struct PlaylistEntry {
218    /// track position in the current queue.
219    /// If the track is currently selected, track id is same as <song> in /Status response.
220    pub id: i64,
221    #[serde(rename = "songid")]
222    pub song_id: Option<String>,
223    /// = id of the album the track is in
224    #[serde(rename = "albumid")]
225    pub album_id: Option<String>,
226    #[serde(rename = "artistid")]
227    pub artist_id: Option<String>,
228    pub service: Option<String>,
229
230    pub title: Option<String>,
231    pub art: Option<String>,
232    pub alb: Option<String>,
233    #[serde(rename = "fn")]
234    pub filename: Option<String>,
235    pub quality: Option<Quality>,
236}
237
238#[derive(Debug, Serialize, Deserialize, PartialEq)]
239#[serde(rename_all = "camelCase")]
240pub struct Browse {
241    pub sid: String,
242    #[serde(rename = "type")]
243    pub browse_type: String,
244
245    #[serde(rename = "$value")]
246    pub items: Vec<BrowseItem>,
247}
248
249#[derive(Debug, Serialize, Deserialize, PartialEq)]
250#[serde(rename_all = "camelCase")]
251pub struct BrowseItem {
252    pub image: Option<String>,
253    pub service_icon: Option<String>,
254    pub service_name: Option<String>,
255    pub search_key: Option<String>,
256    pub next_key: Option<String>,
257    pub parent_key: Option<String>,
258    pub browse_key: Option<String>,
259    pub text: Option<String>,
260    pub text2: Option<String>,
261    #[serde(rename = "type")]
262    pub item_type: Option<String>,
263    pub play_url: Option<String>,
264    pub autoplay_url: Option<String>,
265    pub context_menu_key: Option<String>,
266    pub action_url: Option<String>,
267}