comparison src/beefweb.rs @ 4:26f695129c86

*: fixes - seeking is actually relative - added track IDs (yes these weren't implemented yet even though they're required), of the format /org/foobar2000/foobar2000/trackids/(hex encoded file path) - added playlist fetching for a possible implementation of the playlist protocol
author Paper <paper@tflc.us>
date Sun, 05 Apr 2026 02:26:19 -0400
parents 18f743c980fa
children 482bd968725f
comparison
equal deleted inserted replaced
3:18f743c980fa 4:26f695129c86
181 181
182 #[derive(serde::Serialize, serde::Deserialize, Debug)] 182 #[derive(serde::Serialize, serde::Deserialize, Debug)]
183 struct PlaylistItemsHelper { 183 struct PlaylistItemsHelper {
184 #[serde(rename = "playlistItems")] 184 #[serde(rename = "playlistItems")]
185 playlist_items: PlaylistItems, 185 playlist_items: PlaylistItems,
186 }
187
188 #[derive(serde::Serialize, serde::Deserialize, Debug)]
189 pub struct Playlist {
190 pub id: String,
191 pub index: i64,
192 pub title: String,
193 #[serde(rename = "isCurrent")]
194 pub current: bool,
195 #[serde(rename = "itemCount")]
196 pub item_count: i64,
197 #[serde(rename = "totalTime")]
198 pub total_time: f64,
199 }
200
201 #[derive(serde::Serialize, serde::Deserialize, Debug)]
202 pub struct Playlists {
203 pub playlists: Vec<Playlist>,
186 } 204 }
187 205
188 /* --- NOW, THE ACTUAL BEEFWEB THING */ 206 /* --- NOW, THE ACTUAL BEEFWEB THING */
189 207
190 pub struct Beefweb { 208 pub struct Beefweb {
367 relative_position: None, 385 relative_position: None,
368 options: None, 386 options: None,
369 }).await; 387 }).await;
370 } 388 }
371 389
390 pub async fn seek(&self, position: f64) -> Result<(), anyhow::Error>
391 {
392 return self.set_player(&SetPlayer {
393 volume: None,
394 relative_volume: None,
395 muted: None,
396 position: None,
397 relative_position: Some(position),
398 options: None,
399 }).await;
400 }
401
372 /* TODO -- finish this; need to link between string and enum 402 /* TODO -- finish this; need to link between string and enum
373 403
374 pub async fn set_playback_order(&self, ) -> Result<(), anyhow::Error> 404 pub async fn set_playback_order(&self, ) -> Result<(), anyhow::Error>
375 { 405 {
376 let p = self.set_player(&SetPlayer { 406 let p = self.set_player(&SetPlayer {
399 pub async fn playlist_item(&self, playlist_id: &str, index: i64, columns: &Vec<&str>) -> Result<PlaylistItems, anyhow::Error> 429 pub async fn playlist_item(&self, playlist_id: &str, index: i64, columns: &Vec<&str>) -> Result<PlaylistItems, anyhow::Error>
400 { 430 {
401 return self.playlist_items(playlist_id, index, 1, columns).await; 431 return self.playlist_items(playlist_id, index, 1, columns).await;
402 } 432 }
403 433
434 pub async fn playlists(&self) -> Result<Vec<Playlist>, anyhow::Error>
435 {
436 return Ok(self.client
437 .get(format!("{}/playlists", self.base_url))
438 .send()
439 .await?
440 .json::<Playlists>()
441 .await?
442 .playlists);
443 }
444
404 pub async fn artwork(&self, playlist_id: &str, index: i64) -> Result<bytes::Bytes, anyhow::Error> 445 pub async fn artwork(&self, playlist_id: &str, index: i64) -> Result<bytes::Bytes, anyhow::Error>
405 { 446 {
406 return Ok(self.client 447 return Ok(self.client
407 .get(format!("{}/artwork/{}/{}", self.base_url, playlist_id, index)) 448 .get(format!("{}/artwork/{}/{}", self.base_url, playlist_id, index))
408 .send() 449 .send()