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>
141 lines
5.1 KiB
Rust
141 lines
5.1 KiB
Rust
//! An artist: photo, followers, Lejátszás / Keverés / Követés, the popular
|
|
//! tracks, then albums, singles and appearances.
|
|
|
|
use std::any::Any;
|
|
|
|
use crate::api::{self, Album, Artist, Track};
|
|
use crate::app::{Cx, Look, Screen};
|
|
use crate::format;
|
|
use crate::page::{Ch, Frame, Kind, L, Spec};
|
|
use crate::screens::{self, Load, album_card, row_index, track_line};
|
|
use crate::spotify::Cmd;
|
|
|
|
#[derive(Default)]
|
|
struct Data {
|
|
artist: Artist,
|
|
top: Vec<Track>,
|
|
albums: Vec<Album>,
|
|
singles: Vec<Album>,
|
|
appears: Vec<Album>,
|
|
}
|
|
|
|
pub struct ArtistPage {
|
|
id: String,
|
|
data: Load<Data>,
|
|
following: Option<bool>,
|
|
started: bool,
|
|
}
|
|
|
|
impl ArtistPage {
|
|
pub fn new(id: &str) -> ArtistPage {
|
|
ArtistPage { id: id.into(), data: Load::Loading, following: None, started: false }
|
|
}
|
|
|
|
fn load(&mut self, cx: &Cx) {
|
|
let api = cx.api();
|
|
let id = self.id.clone();
|
|
let market = cx.user().country;
|
|
cx.spawn::<ArtistPage, _>(
|
|
move || -> anyhow::Result<(Data, Option<bool>)> {
|
|
let (artist, top, albums, singles, appears) = api.artist_page(&id, &market)?;
|
|
let following = api.following_artist(&id).ok();
|
|
Ok((Data { artist, top, albums, singles, appears }, following))
|
|
},
|
|
|s, cx, r| match r {
|
|
Ok((d, following)) => {
|
|
s.following = following;
|
|
let img = api::pick(&d.artist.images, 960);
|
|
cx.backdrop(&img, Look::Sharp, &format!("ar:{}", s.id));
|
|
s.data = Load::Ready(d);
|
|
}
|
|
Err(e) => s.data = Load::Failed(api::describe(&e)),
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
impl Screen for ArtistPage {
|
|
fn spec(&mut self, cx: &Cx) -> Spec {
|
|
if !self.started {
|
|
self.started = true;
|
|
self.load(cx);
|
|
}
|
|
let frame = Frame::default();
|
|
let Some(d) = self.data.ready() else {
|
|
return Spec { lines: vec![self.data.status("status").unwrap()], frame };
|
|
};
|
|
let a = &d.artist;
|
|
let mut hero = L::new("hero", Kind::Hero).cover(api::pick(&a.images, 400), true);
|
|
hero.style = "ELŐADÓ".into();
|
|
hero.title = a.name.clone();
|
|
hero.subtitle = a.followers.as_ref().map(|f| format::followers(f.total)).unwrap_or_default();
|
|
|
|
hero.meta = a.genres.iter().take(4).cloned().collect::<Vec<_>>().join(" · ");
|
|
let mut chips = vec![Ch::new("play", "Lejátszás").icon("play").tone("primary"), Ch::new("shuffle", "Keverés").icon("shuffle")];
|
|
if let Some(f) = self.following {
|
|
chips.push(if f { Ch::new("follow", "Követed").icon("check").active(true) } else { Ch::new("follow", "Követés").icon("plus") });
|
|
}
|
|
hero.chips = chips;
|
|
let mut lines = vec![hero];
|
|
let playing = cx.playing_uri();
|
|
if !d.top.is_empty() {
|
|
lines.push(L::heading("top-h", "Népszerű"));
|
|
for (i, t) in d.top.iter().take(10).enumerate() {
|
|
lines.push(track_line(format!("trk#{i}"), t, None, true, &playing));
|
|
}
|
|
}
|
|
for (id, title, list) in [("albums", "Albumok", &d.albums), ("singles", "Kislemezek és EP-k", &d.singles), ("appears", "Közreműködések", &d.appears)] {
|
|
if !list.is_empty() {
|
|
lines.push(L::cards(id, title, "square", list.iter().map(album_card).collect()).captions());
|
|
}
|
|
}
|
|
Spec { lines, frame }
|
|
}
|
|
|
|
fn activate(&mut self, cx: &Cx, line: &str, item: &str) {
|
|
let Some(d) = self.data.ready() else { return };
|
|
let uri = d.artist.uri.clone();
|
|
if line == "hero" {
|
|
match item {
|
|
"play" | "shuffle" => cx.play(Cmd::Context { uri, start: None, shuffle: item == "shuffle" }),
|
|
"follow" => {
|
|
let Some(on) = self.following.map(|f| !f) else { return };
|
|
let api = cx.api();
|
|
let id = self.id.clone();
|
|
cx.call::<ArtistPage>("follow", move || api.set_following_artist(&id, on), move |s, cx, ok| {
|
|
if ok {
|
|
s.following = Some(on);
|
|
cx.toast(if on { "Követed" } else { "Már nem követed" });
|
|
}
|
|
});
|
|
}
|
|
_ => {}
|
|
}
|
|
return;
|
|
}
|
|
if line.starts_with("trk#") {
|
|
let Some(i) = row_index(line) else { return };
|
|
let top: Vec<Track> = d.top.iter().take(10).cloned().collect();
|
|
if item == "more" {
|
|
if let Some(t) = top.get(i) {
|
|
screens::track_menu(cx, t);
|
|
}
|
|
} else {
|
|
screens::play_from(cx, &uri, &top, i);
|
|
}
|
|
return;
|
|
}
|
|
screens::open_card(cx, item);
|
|
}
|
|
|
|
fn shown(&mut self, cx: &Cx) {
|
|
if let Some(d) = self.data.ready() {
|
|
cx.backdrop(&api::pick(&d.artist.images, 960), Look::Sharp, &format!("ar:{}", self.id));
|
|
}
|
|
}
|
|
|
|
fn as_any(&mut self) -> &mut dyn Any {
|
|
self
|
|
}
|
|
}
|