Spotify for Fennec OS: native TV client
All checks were successful
release / release (push) Successful in 12m14s
All checks were successful
release / release (push) Successful in 12m14s
Rust + Slint on sf-ui's Liquid Glass, with the page engine of Netflex TV. librespot plays (GStreamer on the TV) and makes the TV a Spotify Connect device; the Web API (token from the session) feeds the pages. - Sign-in with the phone: a pairing code / QR code (spotify.com/pair, OAuth device flow) or picking the TV in the Spotify app (zeroconf). - Home, search, library, playlist / album / liked songs / podcast pages, artist pages, settings; the user's picture top right. - Now playing: seek, shuffle, repeat, like, synced lyrics, queue. - package.sh builds x86-64 and aarch64 (Raspberry Pi); the Gitea CI releases both on a tag. - tools/mock_server.py and SPOTIFY_MOCK for work without an account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
146
src/screens/artist.rs
Normal file
146
src/screens/artist.rs
Normal file
@@ -0,0 +1,146 @@
|
||||
//! 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 = api.artist(&id)?;
|
||||
let (top, albums, singles, appears, following) = std::thread::scope(|s| {
|
||||
let top = s.spawn(|| api.artist_top(&id, &market).unwrap_or_default());
|
||||
let albums = s.spawn(|| api.artist_albums(&id, "album").unwrap_or_default());
|
||||
let singles = s.spawn(|| api.artist_albums(&id, "single").unwrap_or_default());
|
||||
let appears = s.spawn(|| api.artist_albums(&id, "appears_on,compilation").unwrap_or_default());
|
||||
let following = s.spawn(|| api.following_artist(&id).ok());
|
||||
(top.join().unwrap_or_default(), albums.join().unwrap_or_default(), singles.join().unwrap_or_default(), appears.join().unwrap_or_default(), following.join().ok().flatten())
|
||||
});
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user