Files
musyx/crates/musyx/examples/api_probe.rs
T
Yuriy Panov e7726aac3a feat: search, home landing, chart, genres and podcasts
- ym-api: search by kind with paging and best match, suggestions, landing
  (personal playlists, new releases and playlists) plus the full chart
  with movement, genres, tag playlists and featured podcasts
- Tag playlist ids are parsed from raw JSON: yamuse types them as strings
  but the API sends {uid, kind} objects
- Featured podcasts capped at 48 (the API lists thousands)
- Search screen: debounced suggestions floating under the field, tabs with
  totals, top result card, Show more paging, genre browsing when empty
- Home with personal playlists, top-10 chart, new releases and playlists,
  genre tiles; Chart page; Genre pages with sub-genres; Podcasts page
- Chart lists show position movement; top-N lists are built once so
  cached rows survive playback ticks
- Snapshot mode can sign in live; api_probe example for discovery calls
2026-10-15 15:04:37 +06:00

55 lines
2.5 KiB
Rust

//! Read-only check of the discovery endpoints with the signed-in account:
//! `cargo run -p musyx --example api_probe`. Prints counts and a few titles.
use ym_api::auth::Credentials;
use ym_api::{SearchKind, YmClient};
#[tokio::main(flavor = "current_thread")]
async fn main() {
let raw = keyring::Entry::new("musyx", "yandex-music")
.and_then(|e| e.get_password())
.expect("sign in with Musyx first");
let credentials: Credentials = serde_json::from_str(&raw).expect("stored credentials");
let (client, account) = YmClient::connect(&credentials).await.expect("connect");
println!("account: {} (plus: {})", account.login, account.has_plus);
match client.home().await {
Ok(h) => println!(
"home: {} personal {:?}, {} chart, {} new releases, {} new playlists",
h.personal.len(),
h.personal.iter().map(|p| p.playlist.title.as_str()).collect::<Vec<_>>(),
h.chart.len(),
h.new_releases.len(),
h.new_playlists.len()
),
Err(e) => println!("home: ERROR {e}"),
}
match client.genres().await {
Ok(g) => {
println!("genres: {} {:?}", g.len(), g.iter().take(8).map(|g| (&g.id, &g.title)).collect::<Vec<_>>());
for genre in g.iter().skip(1).take(4) {
match client.tag_playlists(&genre.id).await {
Ok(p) => println!("tag {}: {} playlists {:?}", genre.id, p.len(), p.iter().take(2).map(|p| &p.title).collect::<Vec<_>>()),
Err(e) => println!("tag {}: ERROR {e}", genre.id),
}
}
}
Err(e) => println!("genres: ERROR {e}"),
}
match client.featured_podcasts().await {
Ok(p) => println!("podcasts: {} {:?}", p.len(), p.iter().take(3).map(|a| &a.title).collect::<Vec<_>>()),
Err(e) => println!("podcasts: ERROR {e}"),
}
match client.search("земфира", SearchKind::All, 0).await {
Ok(r) => println!(
"search: best {:?}, {} tracks ({}), {} albums, {} artists, {} playlists, {} podcasts",
r.best.as_ref().map(|b| format!("{b:?}").chars().take(60).collect::<String>()),
r.tracks.len(), r.totals.tracks, r.albums.len(), r.artists.len(), r.playlists.len(), r.podcasts.len()
),
Err(e) => println!("search: ERROR {e}"),
}
match client.suggest("зем").await {
Ok(s) => println!("suggest: {:?}", s.iter().take(5).collect::<Vec<_>>()),
Err(e) => println!("suggest: ERROR {e}"),
}
}