refactor: drop the dead REST play-queue sync
POST /queues answers every create with the placeholder id 000000000000000000000000 and GET /queues lists nothing, so publishing the queue never reached another device. Remove create_queue/update_queue_position, QueueContext, the QueueStarted/QueueMoved effects and the app's server_queue state. Yandex's apps sync through Ynison instead, but Ynison answers this account with 503 "temporary unavailable" (code 500140000) and the phone app offers no device handoff, so there is no working replacement yet.
This commit is contained in:
1 parent
52ad4a2e90
commit
24aa41e8fb
7 files changed
+4
-159
No files matched your search
@@ -69,8 +69,6 @@ pub struct App {
|
|||||||
lyrics: HashMap<String, Loadable<Option<Arc<Lyrics>>>>,
|
lyrics: HashMap<String, Loadable<Option<Arc<Lyrics>>>>,
|
||||||
/// The synced line last scrolled to.
|
/// The synced line last scrolled to.
|
||||||
lyric_line: Option<usize>,
|
lyric_line: Option<usize>,
|
||||||
/// The queue published to Yandex for the list playing now.
|
|
||||||
server_queue: Option<String>,
|
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
/// The OS appearance, used when settings say "Match system".
|
/// The OS appearance, used when settings say "Match system".
|
||||||
system_mode: Mode,
|
system_mode: Mode,
|
||||||
@@ -162,7 +160,6 @@ pub enum Message {
|
|||||||
Edited(Box<edit::Edited>),
|
Edited(Box<edit::Edited>),
|
||||||
LyricsLoaded(String, Result<Option<Arc<Lyrics>>, Error>),
|
LyricsLoaded(String, Result<Option<Arc<Lyrics>>, Error>),
|
||||||
RetryLyrics,
|
RetryLyrics,
|
||||||
QueueCreated(Result<Option<String>, Error>),
|
|
||||||
ToastTick,
|
ToastTick,
|
||||||
CoverWanted(String),
|
CoverWanted(String),
|
||||||
CoverLoaded(String, Option<Arc<[u8]>>),
|
CoverLoaded(String, Option<Arc<[u8]>>),
|
||||||
@@ -191,7 +188,6 @@ impl App {
|
|||||||
toast: None,
|
toast: None,
|
||||||
lyrics: HashMap::new(),
|
lyrics: HashMap::new(),
|
||||||
lyric_line: None,
|
lyric_line: None,
|
||||||
server_queue: None,
|
|
||||||
settings: Settings::default(),
|
settings: Settings::default(),
|
||||||
system_mode: Mode::Dark,
|
system_mode: Mode::Dark,
|
||||||
settings_dirty: None,
|
settings_dirty: None,
|
||||||
@@ -421,7 +417,6 @@ impl App {
|
|||||||
self.likes = LikedIds::default();
|
self.likes = LikedIds::default();
|
||||||
self.sheet = None;
|
self.sheet = None;
|
||||||
self.lyrics.clear();
|
self.lyrics.clear();
|
||||||
self.server_queue = None;
|
|
||||||
}
|
}
|
||||||
Message::Navigate(route) => {
|
Message::Navigate(route) => {
|
||||||
self.sheet = None;
|
self.sheet = None;
|
||||||
@@ -571,11 +566,6 @@ impl App {
|
|||||||
}
|
}
|
||||||
return self.want_lyrics();
|
return self.want_lyrics();
|
||||||
}
|
}
|
||||||
Message::QueueCreated(Ok(id)) => self.server_queue = id,
|
|
||||||
Message::QueueCreated(Err(e)) => {
|
|
||||||
eprintln!("publish queue: {e}");
|
|
||||||
self.server_queue = None;
|
|
||||||
}
|
|
||||||
Message::ToastTick => {
|
Message::ToastTick => {
|
||||||
if self.toast_expired() {
|
if self.toast_expired() {
|
||||||
self.toast = None;
|
self.toast = None;
|
||||||
@@ -1081,19 +1071,6 @@ impl App {
|
|||||||
})
|
})
|
||||||
.discard()
|
.discard()
|
||||||
}
|
}
|
||||||
Effect::QueueStarted { tracks, index } => Self::publish_queue(client, self.play_context(), tracks, index),
|
|
||||||
Effect::QueueMoved(index) => match self.server_queue.clone() {
|
|
||||||
Some(id) => {
|
|
||||||
let client = client.clone();
|
|
||||||
Task::future(async move {
|
|
||||||
if let Err(e) = client.update_queue_position(&id, index).await {
|
|
||||||
eprintln!("queue position: {e}");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.discard()
|
|
||||||
}
|
|
||||||
None => Task::none(),
|
|
||||||
},
|
|
||||||
Effect::Report(report) => {
|
Effect::Report(report) => {
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
Task::future(async move {
|
Task::future(async move {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::sync::Arc;
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use iced::Task;
|
use iced::Task;
|
||||||
use ym_api::{Error, PlaylistId, QueueContext, Track, YmClient};
|
use ym_api::{Error, PlaylistId};
|
||||||
|
|
||||||
use super::{App, Message};
|
use super::{App, Message};
|
||||||
use crate::player;
|
use crate::player;
|
||||||
@@ -282,23 +282,6 @@ impl App {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Publishes a newly started list to Yandex so other devices can continue it.
|
|
||||||
pub(super) fn publish_queue(client: &YmClient, context: QueueContext, tracks: Vec<Track>, index: usize) -> Task<Message> {
|
|
||||||
let client = client.clone();
|
|
||||||
Task::future(async move { client.create_queue(&context, &tracks, index).await }).map(Message::QueueCreated)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where a list being played comes from, judged by the page it was started on.
|
|
||||||
pub(super) fn play_context(&self) -> QueueContext {
|
|
||||||
match self.nav.current() {
|
|
||||||
Route::Album(id) => QueueContext::Album(id),
|
|
||||||
Route::Artist(id) => QueueContext::Artist(id),
|
|
||||||
Route::Playlist(id) => QueueContext::Playlist(id),
|
|
||||||
Route::Collection => QueueContext::MyMusic,
|
|
||||||
_ => QueueContext::Various,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn toast_expired(&self) -> bool {
|
pub(super) fn toast_expired(&self) -> bool {
|
||||||
self.toast.as_ref().is_some_and(|(_, at)| at.elapsed() >= TOAST)
|
self.toast.as_ref().is_some_and(|(_, at)| at.elapsed() >= TOAST)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,10 +79,6 @@ pub enum Effect {
|
|||||||
WaveFetch { station: String, session_id: Option<String>, queue: Vec<String> },
|
WaveFetch { station: String, session_id: Option<String>, queue: Vec<String> },
|
||||||
WaveFeedback { session_id: String, event: WaveEvent, batch_id: Option<String> },
|
WaveFeedback { session_id: String, event: WaveEvent, batch_id: Option<String> },
|
||||||
Report(PlayReport),
|
Report(PlayReport),
|
||||||
/// A new list started: publish it so other devices can continue (`tracks` in play order).
|
|
||||||
QueueStarted { tracks: Vec<Track>, index: usize },
|
|
||||||
/// The list moved on to another position.
|
|
||||||
QueueMoved(usize),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A station being played, endlessly topped up.
|
/// A station being played, endlessly topped up.
|
||||||
@@ -216,10 +212,6 @@ impl Player {
|
|||||||
self.queue = Queue::new(tracks.to_vec(), start, self.shuffle);
|
self.queue = Queue::new(tracks.to_vec(), start, self.shuffle);
|
||||||
self.skips = 0;
|
self.skips = 0;
|
||||||
self.notice = None;
|
self.notice = None;
|
||||||
if let Some(queue) = &self.queue {
|
|
||||||
let (order, index) = queue.in_order();
|
|
||||||
effects.push(Effect::QueueStarted { tracks: order.into_iter().cloned().collect(), index });
|
|
||||||
}
|
|
||||||
effects.extend(self.load_current());
|
effects.extend(self.load_current());
|
||||||
return effects;
|
return effects;
|
||||||
}
|
}
|
||||||
@@ -545,16 +537,6 @@ impl Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_current(&mut self) -> Vec<Effect> {
|
fn load_current(&mut self) -> Vec<Effect> {
|
||||||
let mut effects = self.load_track();
|
|
||||||
if self.wave.is_none()
|
|
||||||
&& let Some(queue) = &self.queue
|
|
||||||
{
|
|
||||||
effects.push(Effect::QueueMoved(queue.in_order().1));
|
|
||||||
}
|
|
||||||
effects
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_track(&mut self) -> Vec<Effect> {
|
|
||||||
let Some(track) = self.track().cloned() else { return vec![] };
|
let Some(track) = self.track().cloned() else { return vec![] };
|
||||||
self.generation += 1;
|
self.generation += 1;
|
||||||
self.position = Duration::ZERO;
|
self.position = Duration::ZERO;
|
||||||
@@ -897,17 +879,6 @@ mod tests {
|
|||||||
assert!(p.wave_station().is_none());
|
assert!(p.wave_station().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn list_play_publishes_queue_and_moves() {
|
|
||||||
let mut p = Player::default();
|
|
||||||
let tracks: Arc<[Track]> = (0..3).map(|i| track(&i.to_string(), 10)).collect();
|
|
||||||
let effects = p.update(Msg::Play { tracks, start: 1, shuffle: None });
|
|
||||||
assert!(matches!(&effects[0], Effect::QueueStarted { tracks, index: 1 } if tracks.len() == 3));
|
|
||||||
assert!(effects.contains(&Effect::QueueMoved(1)));
|
|
||||||
let effects = p.update(Msg::Next);
|
|
||||||
assert!(effects.contains(&Effect::QueueMoved(2)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn play_next_and_append() {
|
fn play_next_and_append() {
|
||||||
let mut p = playing(3, 0);
|
let mut p = playing(3, 0);
|
||||||
|
|||||||
@@ -161,11 +161,6 @@ impl<T> Queue<T> {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Items in play order, and the current position in it.
|
|
||||||
pub fn in_order(&self) -> (Vec<&T>, usize) {
|
|
||||||
(self.order.iter().map(|&i| &self.items[i]).collect(), self.pos)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Drops everything after the current item, e.g. when a station's settings change.
|
/// Drops everything after the current item, e.g. when a station's settings change.
|
||||||
pub fn clear_upcoming(&mut self) {
|
pub fn clear_upcoming(&mut self) {
|
||||||
let keep: Vec<usize> = self.order[..=self.pos].to_vec();
|
let keep: Vec<usize> = self.order[..=self.pos].to_vec();
|
||||||
@@ -285,9 +280,7 @@ mod tests {
|
|||||||
q.set_shuffle(true);
|
q.set_shuffle(true);
|
||||||
assert!(q.insert_next(99, |a, b| a == b));
|
assert!(q.insert_next(99, |a, b| a == b));
|
||||||
assert_eq!(q.upcoming().next().map(|(_, &x)| x), Some(99));
|
assert_eq!(q.upcoming().next().map(|(_, &x)| x), Some(99));
|
||||||
let (order, pos) = q.in_order();
|
assert_eq!(*q.current(), 1);
|
||||||
assert_eq!(*order[pos], 1);
|
|
||||||
assert_eq!(*order[pos + 1], 99);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::library::{
|
|||||||
AlbumPage, AlbumSummary, ArtistPage, ArtistSummary, LibraryPlaylists, PlaylistId, PlaylistPage,
|
AlbumPage, AlbumSummary, ArtistPage, ArtistSummary, LibraryPlaylists, PlaylistId, PlaylistPage,
|
||||||
PlaylistSummary,
|
PlaylistSummary,
|
||||||
};
|
};
|
||||||
use crate::edit::{LikedIds, Lyrics, QueueContext};
|
use crate::edit::{LikedIds, Lyrics};
|
||||||
use crate::discover::{ChartEntry, Genre, Home, SearchKind, SearchResults};
|
use crate::discover::{ChartEntry, Genre, Home, SearchKind, SearchResults};
|
||||||
use crate::models::{Stream, Track, best_variant, file_info_stream};
|
use crate::models::{Stream, Track, best_variant, file_info_stream};
|
||||||
use crate::wave::{PlayReport, Station, WaveBatch, WaveEvent, WaveSettings, iso_millis, numeric_id};
|
use crate::wave::{PlayReport, Station, WaveBatch, WaveEvent, WaveSettings, iso_millis, numeric_id};
|
||||||
@@ -61,11 +61,6 @@ fn recent_track_ids(history: &yamuse::models::MusicHistory, limit: usize) -> Vec
|
|||||||
.collect()
|
.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<String>) -> Option<String> {
|
|
||||||
id.filter(|id| !id.is_empty() && !id.bytes().all(|b| b == b'0'))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The signed-in user as the UI needs them.
|
/// The signed-in user as the UI needs them.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Account {
|
pub struct Account {
|
||||||
@@ -688,41 +683,6 @@ impl YmClient {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Server queue ----
|
|
||||||
|
|
||||||
/// 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<Option<String>> {
|
|
||||||
let tracks: Vec<serde_json::Value> = tracks
|
|
||||||
.iter()
|
|
||||||
.map(|t| {
|
|
||||||
serde_json::json!({
|
|
||||||
"trackId": t.id.split(':').next().unwrap_or(&t.id),
|
|
||||||
"albumId": t.album.as_ref().map(|a| a.id.to_string()).unwrap_or_default(),
|
|
||||||
"from": "musyx-desktop",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let body = serde_json::json!({
|
|
||||||
"context": context.to_json(),
|
|
||||||
"tracks": tracks,
|
|
||||||
"currentIndex": current,
|
|
||||||
"from": "musyx-desktop",
|
|
||||||
"isInteractive": true,
|
|
||||||
});
|
|
||||||
Ok(real_queue_id(self.inner.create_queue(&body, None).await?))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn update_queue_position(&self, queue_id: &str, index: usize) -> Result<()> {
|
|
||||||
self.inner.update_queue_position(queue_id, index as i64, None).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Downloads an image (covers are a few kilobytes).
|
/// Downloads an image (covers are a few kilobytes).
|
||||||
pub async fn image(&self, url: &str) -> Result<Vec<u8>> {
|
pub async fn image(&self, url: &str) -> Result<Vec<u8>> {
|
||||||
Ok(yamuse::download::Downloader::new(self.inner.transport(), [url.to_owned()])
|
Ok(yamuse::download::Downloader::new(self.inner.transport(), [url.to_owned()])
|
||||||
@@ -798,14 +758,6 @@ mod tests {
|
|||||||
assert_eq!(recent_track_ids(&history, 10).len(), 4);
|
assert_eq!(recent_track_ids(&history, 10).len(), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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]
|
#[test]
|
||||||
fn anonymous_status_is_not_an_account() {
|
fn anonymous_status_is_not_an_account() {
|
||||||
assert!(Account::from_status(status(r#"{"account":{"now":"2026-10-15"}}"#)).is_none());
|
assert!(Account::from_status(status(r#"{"account":{"now":"2026-10-15"}}"#)).is_none());
|
||||||
|
|||||||
@@ -89,31 +89,6 @@ fn parse_stamp(s: &str) -> Option<Duration> {
|
|||||||
Some(Duration::from_millis((min * 60 + whole) * 1000 + millis))
|
Some(Duration::from_millis((min * 60 + whole) * 1000 + millis))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Where a server queue's tracks come from; other devices show it as "Playing from…".
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub enum QueueContext {
|
|
||||||
Album(i64),
|
|
||||||
Playlist(PlaylistId),
|
|
||||||
Artist(i64),
|
|
||||||
/// Liked tracks.
|
|
||||||
MyMusic,
|
|
||||||
/// Search results, the chart, anything else.
|
|
||||||
Various,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl QueueContext {
|
|
||||||
pub(crate) fn to_json(&self) -> serde_json::Value {
|
|
||||||
let (kind, id) = match self {
|
|
||||||
QueueContext::Album(id) => ("album", id.to_string()),
|
|
||||||
QueueContext::Playlist(p) => ("playlist", format!("{}:{}", p.owner, p.kind)),
|
|
||||||
QueueContext::Artist(id) => ("artist", id.to_string()),
|
|
||||||
QueueContext::MyMusic => ("my_music", String::new()),
|
|
||||||
QueueContext::Various => ("various", String::new()),
|
|
||||||
};
|
|
||||||
serde_json::json!({ "type": kind, "id": id, "description": "" })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -147,10 +122,4 @@ mod tests {
|
|||||||
assert_eq!(parse_stamp("00:01.1234"), None);
|
assert_eq!(parse_stamp("00:01.1234"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn queue_contexts_match_the_api_shape() {
|
|
||||||
let p = QueueContext::Playlist(PlaylistId { owner: 9, kind: 3 }).to_json();
|
|
||||||
assert_eq!(p, serde_json::json!({"type": "playlist", "id": "9:3", "description": ""}));
|
|
||||||
assert_eq!(QueueContext::MyMusic.to_json()["type"], "my_music");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,5 @@ pub use wave::{
|
|||||||
Character, Language, MY_WAVE, Mood, PlayReport, Station, WaveBatch, WaveEvent, WaveSettings,
|
Character, Language, MY_WAVE, Mood, PlayReport, Station, WaveBatch, WaveEvent, WaveSettings,
|
||||||
};
|
};
|
||||||
pub use discover::{BestMatch, ChartEntry, Genre, Home, Personal, SearchKind, SearchResults, Totals};
|
pub use discover::{BestMatch, ChartEntry, Genre, Home, Personal, SearchKind, SearchResults, Totals};
|
||||||
pub use edit::{LikedIds, LyricLine, Lyrics, QueueContext};
|
pub use edit::{LikedIds, LyricLine, Lyrics};
|
||||||
pub use error::{Error, Result};
|
pub use error::{Error, Result};
|
||||||
Reference in new issue
Block a user