diff --git a/crates/ym-api/src/client.rs b/crates/ym-api/src/client.rs index 22605c3..ab4e64a 100644 --- a/crates/ym-api/src/client.rs +++ b/crates/ym-api/src/client.rs @@ -38,6 +38,11 @@ fn tag_playlist_ids(raw: &serde_json::Value) -> Vec { .collect() } +/// A queue id, unless it's the all-zero placeholder Yandex returns for a queue it didn't keep. +fn real_queue_id(id: Option) -> Option { + id.filter(|id| !id.is_empty() && !id.bytes().all(|b| b == b'0')) +} + /// The signed-in user as the UI needs them. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Account { @@ -581,7 +586,13 @@ impl YmClient { // ---- Server queue ---- - /// Publishes what's playing so other devices can continue it. Returns the queue id. + /// Publishes what's playing so other devices can continue it. Returns the queue id, + /// or `None` when Yandex didn't keep the queue. + /// + /// Yandex now answers every create with the placeholder id `000000000000000000000000` + /// and lists no queues afterwards, whatever device header is sent (a stable + /// `device_id` was tried): the phone apps sync through Ynison instead. The + /// placeholder is dropped so no position updates go to a queue that doesn't exist. pub async fn create_queue(&self, context: &QueueContext, tracks: &[Track], current: usize) -> Result> { let tracks: Vec = tracks .iter() @@ -600,7 +611,7 @@ impl YmClient { "from": "musyx-desktop", "isInteractive": true, }); - Ok(self.inner.create_queue(&body, None).await?) + Ok(real_queue_id(self.inner.create_queue(&body, None).await?)) } pub async fn update_queue_position(&self, queue_id: &str, index: usize) -> Result<()> { @@ -664,6 +675,14 @@ mod tests { assert_eq!(tag_playlist_ids(&wrapped), vec!["9:8"]); } + #[test] + fn placeholder_queue_ids_are_dropped() { + assert_eq!(real_queue_id(Some("000000000000000000000000".into())), None); + assert_eq!(real_queue_id(Some(String::new())), None); + assert_eq!(real_queue_id(None), None); + assert_eq!(real_queue_id(Some("6702a1f0c3".into())).as_deref(), Some("6702a1f0c3")); + } + #[test] fn anonymous_status_is_not_an_account() { assert!(Account::from_status(status(r#"{"account":{"now":"2026-10-15"}}"#)).is_none());