feat: My Wave and stations with feedback, play reporting and animated hero
- ym-api: stations, station settings (mood/character/language), track batches, rotor feedback (started, track started/finished, skip) and play-audio reports - Play reports send millisecond ISO timestamps: yamuse's default drops the milliseconds and /play-audio rejects it - Player: station mode tops up the queue when two tracks remain, waits instead of ending when a batch runs dry, ignores shuffle and batches from other stations, and reports every track left (finished or skipped with time played); feedback names the batch each track came in - Queue can grow (radio batches) and drop upcoming items (new settings) - My Wave screen with settings chips and station tiles; Home and My Wave hero draws drifting lines on a canvas, animated only while My Wave plays - Genre pages get a Play radio button
This commit is contained in:
1 parent
e7726aac3a
commit
03aa180840
12 files changed
+1115
-87
No files matched your search
@@ -7,6 +7,7 @@ use crate::library::{
|
||||
};
|
||||
use crate::discover::{ChartEntry, Genre, Home, SearchKind, SearchResults};
|
||||
use crate::models::{Stream, Track, best_variant};
|
||||
use crate::wave::{PlayReport, Station, WaveBatch, WaveEvent, WaveSettings, iso_millis, numeric_id};
|
||||
use crate::{Error, Result};
|
||||
|
||||
/// How many featured podcasts to resolve.
|
||||
@@ -297,6 +298,83 @@ impl YmClient {
|
||||
Ok(albums.into_iter().filter_map(AlbumSummary::from_yamuse).collect())
|
||||
}
|
||||
|
||||
/// Stations Yandex suggests to this user.
|
||||
pub async fn stations(&self) -> Result<Vec<Station>> {
|
||||
let dashboard = self.inner.rotor_dashboard().await?;
|
||||
Ok(dashboard.stations.into_iter().filter_map(Station::from_yamuse).collect())
|
||||
}
|
||||
|
||||
pub async fn wave_settings(&self, station: &str) -> Result<WaveSettings> {
|
||||
let info = self.inner.rotor_station_info(station).await?;
|
||||
Ok(info
|
||||
.into_iter()
|
||||
.next()
|
||||
.and_then(|r| r.settings2.or(r.settings))
|
||||
.map(|s| WaveSettings::from_api(&s))
|
||||
.unwrap_or_default())
|
||||
}
|
||||
|
||||
pub async fn set_wave_settings(&self, station: &str, settings: WaveSettings) -> Result<()> {
|
||||
let (mood, diversity, language) = settings.to_yamuse();
|
||||
self.inner
|
||||
.rotor_set_station_settings(station, mood, diversity, language, yamuse::StationType::Rotor)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The next tracks of a station. Pass the last track played as `after` to
|
||||
/// continue the sequence; `None` starts fresh.
|
||||
pub async fn wave_tracks(&self, station: &str, after: Option<&str>) -> Result<WaveBatch> {
|
||||
let queue = after.and_then(numeric_id);
|
||||
Ok(WaveBatch::from_yamuse(self.inner.rotor_station_tracks(station, queue).await?))
|
||||
}
|
||||
|
||||
/// Tells a station what happened, so the next batch fits better.
|
||||
pub async fn wave_feedback(&self, station: &str, event: &WaveEvent, batch_id: Option<&str>) -> Result<()> {
|
||||
use yamuse::RotorFeedback as F;
|
||||
let mut report = yamuse::RotorFeedbackReport {
|
||||
batch_id: batch_id.map(str::to_owned),
|
||||
..Default::default()
|
||||
};
|
||||
let kind = match event {
|
||||
WaveEvent::Started => {
|
||||
report.from = Some("musyx-wave".into());
|
||||
F::RadioStarted
|
||||
}
|
||||
WaveEvent::TrackStarted { track_id } => {
|
||||
report.track_id = numeric_id(track_id);
|
||||
F::TrackStarted
|
||||
}
|
||||
WaveEvent::TrackFinished { track_id, played } => {
|
||||
report.track_id = numeric_id(track_id);
|
||||
report.total_played_seconds = Some(played.as_secs_f64());
|
||||
F::TrackFinished
|
||||
}
|
||||
WaveEvent::Skipped { track_id, played } => {
|
||||
report.track_id = numeric_id(track_id);
|
||||
report.total_played_seconds = Some(played.as_secs_f64());
|
||||
F::Skip
|
||||
}
|
||||
};
|
||||
self.inner.rotor_feedback(station, kind, &report).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Records a listen in the user's history. Tracks without numeric ids are skipped.
|
||||
pub async fn report_play(&self, report: &PlayReport) -> Result<()> {
|
||||
let Some(track_id) = numeric_id(&report.track_id) else { return Ok(()) };
|
||||
let mut r = yamuse::PlayAudioReport::new(track_id, report.album_id.unwrap_or(0), report.from.clone());
|
||||
r.track_length_seconds = report.length.as_secs();
|
||||
r.total_played_seconds = report.played.as_secs();
|
||||
r.end_position_seconds = report.end_position.as_secs();
|
||||
// yamuse's default timestamps drop the milliseconds, which the endpoint rejects.
|
||||
let now = iso_millis(std::time::SystemTime::now());
|
||||
r.timestamp = Some(now.clone());
|
||||
r.client_now = Some(now);
|
||||
self.inner.play_audio(&r).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Downloads an image (covers are a few kilobytes).
|
||||
pub async fn image(&self, url: &str) -> Result<Vec<u8>> {
|
||||
Ok(yamuse::download::Downloader::new(self.inner.transport(), [url.to_owned()])
|
||||
|
||||
Reference in new issue
Block a user