0.1.1: browse through Spotify's internal endpoints
Some checks failed
release / release (push) Failing after 13s
Some checks failed
release / release (push) Failing after 13s
The public Web API answers librespot's client id with 429 on every call (and the old keymaster token endpoint with 403), so every page failed. Browsing now goes through the same librespot session as playback: metadata, /playlist/v2 (rootlist and lists), /collection/v2 (liked songs, saved albums, followed artists and podcasts; save and like too), recently played, the search context, and a Connect command for the queue. - Home: recently played albums/playlists/artists, your playlists, your artists, saved albums, podcasts (no top lists or new releases there). - Search finds songs; artists and albums come from them. - Playlists without a picture get Spotify's mosaic cover. - The queue panel is gone (the internal API does not show the queue). - The Web API client stays for the mock server only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
//! Kezdőlap: rows: recently played, your playlists (with the
|
||||
//! liked songs first), your top artists and tracks, saved albums, new
|
||||
//! releases. Every row loads on its own; a failing one just stays away.
|
||||
//! Kezdőlap: rows: recently played (albums, playlists, artists...), your
|
||||
//! playlists (with the liked songs first), your artists, saved albums, your
|
||||
//! podcasts. Every row loads on its own; a failing one just stays away.
|
||||
|
||||
use std::any::Any;
|
||||
|
||||
use crate::api::{Album, Artist, Playlist, Played, Track};
|
||||
use crate::api::{self, Album, Artist, Entity, Playlist, Show};
|
||||
use crate::app::{Cx, Look, Screen};
|
||||
use crate::page::{Frame, L, Spec};
|
||||
use crate::screens::{self, album_card, artist_card, liked_card, playlist_card, track_card};
|
||||
use crate::page::{C, Frame, L, Spec};
|
||||
use crate::screens::{self, album_card, artist_card, liked_card, playlist_card, show_card};
|
||||
|
||||
#[derive(Default)]
|
||||
struct Data {
|
||||
recent: Option<Vec<Played>>,
|
||||
recent: Option<Vec<Entity>>,
|
||||
playlists: Option<Vec<Playlist>>,
|
||||
liked_total: Option<u32>,
|
||||
top_artists: Option<Vec<Artist>>,
|
||||
top_tracks: Option<Vec<Track>>,
|
||||
artists: Option<Vec<Artist>>,
|
||||
albums: Option<Vec<Album>>,
|
||||
releases: Option<Vec<Album>>,
|
||||
shows: Option<Vec<Show>>,
|
||||
errors: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -38,34 +37,41 @@ impl Home {
|
||||
cx.spawn::<Home, _>(
|
||||
move || {
|
||||
std::thread::scope(|s| {
|
||||
let recent = s.spawn(|| api.recently_played());
|
||||
let recent = s.spawn(|| api.recent());
|
||||
let playlists = s.spawn(|| api.my_playlists(0));
|
||||
let liked = s.spawn(|| api.liked(0));
|
||||
let artists = s.spawn(|| api.top_artists());
|
||||
let tracks = s.spawn(|| api.top_tracks());
|
||||
let artists = s.spawn(|| api.followed_artists(""));
|
||||
let albums = s.spawn(|| api.saved_albums(0));
|
||||
let releases = s.spawn(|| api.new_releases());
|
||||
let mut d = Data::default();
|
||||
let e = &mut d.errors;
|
||||
let shows = s.spawn(|| api.saved_shows(0));
|
||||
let mut errors = Vec::new();
|
||||
let e = &mut errors;
|
||||
let recent = keep(recent.join(), e);
|
||||
let playlists = keep(playlists.join(), e).map(|p| p.list());
|
||||
let liked_total = keep(liked.join(), e).map(|p| p.total);
|
||||
let top_artists = keep(artists.join(), e);
|
||||
let top_tracks = keep(tracks.join(), e);
|
||||
let artists = keep(artists.join(), e).map(|a| a.0);
|
||||
let albums = keep(albums.join(), e).map(|p| p.list());
|
||||
let releases = keep(releases.join(), e);
|
||||
Data { recent, playlists, liked_total, top_artists, top_tracks, albums, releases, ..d }
|
||||
let shows = keep(shows.join(), e).map(|p| p.list());
|
||||
Data { recent, playlists, liked_total, artists, albums, shows, errors }
|
||||
})
|
||||
},
|
||||
|s, cx, d| {
|
||||
s.data = d;
|
||||
s.loading = false;
|
||||
// The first picture of the page tints the background.
|
||||
let first = s.data.recent.as_ref().and_then(|r| r.first()).map(|p| p.track.image(640)).unwrap_or_default();
|
||||
cx.backdrop(&first, Look::Soft, "home");
|
||||
cx.backdrop(&s.first_image(), Look::Soft, "home");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn first_image(&self) -> String {
|
||||
match self.data.recent.as_ref().and_then(|r| r.first()) {
|
||||
Some(Entity::Album(a)) => api::pick(&a.images, 640),
|
||||
Some(Entity::Playlist(p)) => p.image(640),
|
||||
Some(Entity::Artist(a)) => api::pick(&a.images, 640),
|
||||
Some(Entity::Show(s)) => api::pick(&s.images, 640),
|
||||
_ => String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A row's result: the data, or its error noted.
|
||||
@@ -81,18 +87,16 @@ fn keep<T>(r: std::thread::Result<anyhow::Result<T>>, errors: &mut Vec<String>)
|
||||
}
|
||||
}
|
||||
|
||||
/// Recently played tracks, each once (newest first).
|
||||
fn recent_cards(items: &[Played]) -> Vec<crate::page::C> {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
items
|
||||
.iter()
|
||||
.filter(|p| seen.insert(p.track.uri.clone()))
|
||||
.take(20)
|
||||
.map(|p| track_card(&p.track, p.context.as_ref().map(|c| c.uri.as_str()).unwrap_or("")))
|
||||
.collect()
|
||||
fn entity_card(e: &Entity, liked_total: Option<u32>) -> C {
|
||||
match e {
|
||||
Entity::Album(a) => album_card(a),
|
||||
Entity::Playlist(p) => playlist_card(p),
|
||||
Entity::Artist(a) => artist_card(a),
|
||||
Entity::Show(s) => show_card(s),
|
||||
Entity::Liked => liked_card(liked_total),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Screen for Home {
|
||||
fn spec(&mut self, cx: &Cx) -> Spec {
|
||||
if !self.started {
|
||||
@@ -107,45 +111,33 @@ impl Screen for Home {
|
||||
}
|
||||
let d = &self.data;
|
||||
if let Some(r) = d.recent.as_ref().filter(|r| !r.is_empty()) {
|
||||
lines.push(L::cards("recent", "Legutóbb játszott", "square", recent_cards(r)).captions());
|
||||
lines.push(L::cards("recent", "Legutóbb játszott", "square", r.iter().map(|e| entity_card(e, d.liked_total)).collect()).captions());
|
||||
}
|
||||
let mut pl = vec![liked_card(d.liked_total)];
|
||||
pl.extend(d.playlists.iter().flatten().map(playlist_card));
|
||||
lines.push(L::cards("playlists", "Lejátszási listáid", "square", pl).captions());
|
||||
if let Some(a) = d.top_artists.as_ref().filter(|a| !a.is_empty()) {
|
||||
lines.push(L::cards("artists", "Kedvenc előadóid", "round", a.iter().map(artist_card).collect()).captions());
|
||||
}
|
||||
if let Some(t) = d.top_tracks.as_ref().filter(|t| !t.is_empty()) {
|
||||
lines.push(L::cards("top", "Mostanában sokat hallgatod", "square", t.iter().map(|t| track_card(t, "")).collect()).captions());
|
||||
if let Some(a) = d.artists.as_ref().filter(|a| !a.is_empty()) {
|
||||
lines.push(L::cards("artists", "Előadóid", "round", a.iter().take(30).map(artist_card).collect()).captions());
|
||||
}
|
||||
if let Some(a) = d.albums.as_ref().filter(|a| !a.is_empty()) {
|
||||
lines.push(L::cards("albums", "Elmentett albumaid", "square", a.iter().map(album_card).collect()).captions());
|
||||
lines.push(L::cards("albums", "Elmentett albumaid", "square", a.iter().take(30).map(album_card).collect()).captions());
|
||||
}
|
||||
if let Some(a) = d.releases.as_ref().filter(|a| !a.is_empty()) {
|
||||
lines.push(L::cards("releases", "Új megjelenések", "square", a.iter().map(album_card).collect()).captions());
|
||||
if let Some(s) = d.shows.as_ref().filter(|s| !s.is_empty()) {
|
||||
lines.push(L::cards("shows", "Podcastjaid", "square", s.iter().map(show_card).collect()).captions());
|
||||
}
|
||||
if d.recent.is_none() && d.playlists.is_none() && d.top_artists.is_none() {
|
||||
if d.recent.is_none() && d.playlists.is_none() && d.artists.is_none() {
|
||||
let why = d.errors.first().cloned().unwrap_or_default();
|
||||
lines.push(L::notice("error", "bad", "Nem sikerült betölteni a kezdőlapot", why));
|
||||
}
|
||||
Spec { lines, frame }
|
||||
}
|
||||
|
||||
fn activate(&mut self, cx: &Cx, line: &str, item: &str) {
|
||||
if line == "top" {
|
||||
// Top tracks play as a list, from the chosen one.
|
||||
if let Some(t) = &self.data.top_tracks {
|
||||
let i = t.iter().position(|x| item == format!("t:{}|", x.uri)).unwrap_or(0);
|
||||
screens::play_from(cx, "", t, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
fn activate(&mut self, cx: &Cx, _line: &str, item: &str) {
|
||||
screens::open_card(cx, item);
|
||||
}
|
||||
|
||||
fn shown(&mut self, cx: &Cx) {
|
||||
let first = self.data.recent.as_ref().and_then(|r| r.first()).map(|p| p.track.image(640)).unwrap_or_default();
|
||||
cx.backdrop(&first, Look::Soft, "home");
|
||||
cx.backdrop(&self.first_image(), Look::Soft, "home");
|
||||
}
|
||||
|
||||
fn as_any(&mut self) -> &mut dyn Any {
|
||||
|
||||
Reference in New Issue
Block a user