Files
yuriy.p 5dbdc04cd4 feat: My server, browse and play a Navidrome library
Adds a "My server" sidebar item (⌘5) for Navidrome and other
Subsonic-compatible servers: albums, artists, playlists, starred songs
and search, with album, artist and playlist pages. Server songs share the
player and queue with Yandex tracks and scrobble back to the server.

- New subsonic-api crate: token auth, envelope and error parsing, and a
  stream plan that keeps files the player decodes and asks the server to
  transcode the rest to MP3.
- ym_api::Track gains a Subsonic source; the player fetches, reports and
  scrobbles by source. Server errors never sign out of Yandex, and the
  Yandex client never fetches server audio or covers.
- Server credentials live in the keychain; connect and disconnect from
  the page or Settings.
- Server tracks have no likes; lyrics come from LRCLIB.
2026-11-16 12:21:02 +06:00

39 lines
1.7 KiB
Rust

//! Talks to a real server. Run with
//! `SUBSONIC_URL=… SUBSONIC_USER=… SUBSONIC_PASSWORD=… cargo test -p subsonic-api -- --ignored`.
use subsonic_api::{AlbumSort, Client, Config, StreamPlan};
fn client() -> Client {
let var = |name: &str| std::env::var(name).unwrap_or_else(|_| panic!("set {name}"));
Client::new(&Config { url: var("SUBSONIC_URL"), username: var("SUBSONIC_USER"), password: var("SUBSONIC_PASSWORD") })
.expect("server address")
}
#[tokio::test]
#[ignore = "network"]
async fn browses_and_streams_the_first_album() {
let client = client();
client.ping().await.expect("ping");
let albums = client.albums(AlbumSort::Newest, 0, 5).await.expect("albums");
let first = albums.first().expect("the library has an album");
let album = client.album(&first.id).await.expect("album");
let song = album.songs.first().expect("the album has a song");
let plan = StreamPlan::for_song(&song.suffix, song.bit_rate, Some(128), false);
let audio = client.stream(&song.id, plan).await.expect("stream");
assert!(audio.bytes.len() > 10_000);
if let Some(cover) = &first.cover_art {
assert!(!client.cover_art(cover, 100).await.expect("cover").is_empty());
}
client.artists().await.expect("artists");
client.playlists().await.expect("playlists");
client.starred().await.expect("starred");
}
#[tokio::test]
#[ignore = "network"]
async fn wrong_password_is_unauthorized() {
let url = std::env::var("SUBSONIC_URL").expect("set SUBSONIC_URL");
let client = Client::new(&Config { url, username: "musyx-nobody".into(), password: "wrong".into() }).unwrap();
assert!(matches!(client.ping().await, Err(subsonic_api::Error::Unauthorized(_))));
}