diff 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
line wrap: on
line diff
--- a/src/beefweb.rs	Sat Apr 04 17:03:22 2026 -0400
+++ b/src/beefweb.rs	Sun Apr 05 02:26:19 2026 -0400
@@ -185,6 +185,24 @@
 	playlist_items: PlaylistItems,
 }
 
+#[derive(serde::Serialize, serde::Deserialize, Debug)]
+pub struct Playlist {
+	pub id: String,
+	pub index: i64,
+	pub title: String,
+	#[serde(rename = "isCurrent")]
+	pub current: bool,
+	#[serde(rename = "itemCount")]
+	pub item_count: i64,
+	#[serde(rename = "totalTime")]
+	pub total_time: f64,
+}
+
+#[derive(serde::Serialize, serde::Deserialize, Debug)]
+pub struct Playlists {
+	pub playlists: Vec<Playlist>,
+}
+
 /* --- NOW, THE ACTUAL BEEFWEB THING */
 
 pub struct Beefweb {
@@ -369,6 +387,18 @@
 		}).await;
 	}
 
+	pub async fn seek(&self, position: f64) -> Result<(), anyhow::Error>
+	{
+		return self.set_player(&SetPlayer {
+			volume: None,
+			relative_volume: None,
+			muted: None,
+			position: None,
+			relative_position: Some(position),
+			options: None,
+		}).await;
+	}
+
 /* TODO -- finish this; need to link between string and enum
 
 	pub async fn set_playback_order(&self, ) -> Result<(), anyhow::Error>
@@ -401,6 +431,17 @@
 		return self.playlist_items(playlist_id, index, 1, columns).await;
 	}
 
+	pub async fn playlists(&self) -> Result<Vec<Playlist>, anyhow::Error>
+	{
+		return Ok(self.client
+			.get(format!("{}/playlists", self.base_url))
+			.send()
+			.await?
+			.json::<Playlists>()
+			.await?
+			.playlists);
+	}
+
 	pub async fn artwork(&self, playlist_id: &str, index: i64) -> Result<bytes::Bytes, anyhow::Error>
 	{
 		return Ok(self.client