feat: shuffle play an album, artist or playlist with a long press
Holding South on a row, or shift+s on the keyboard, plays its tracks in random order with track shuffle on, so turning shuffle off goes back to their own order. On a song row it shuffles the page the song is on. An artist plays every track of every album, fetched a few albums at a time. South now acts on release, so a long press can mean something else. A long press on a row with nothing to shuffle activates as before.
This commit is contained in:
@@ -212,6 +212,28 @@ impl Client {
|
||||
Ok(r.artist)
|
||||
}
|
||||
|
||||
/// Every song on the artist's albums, album by album. A few albums are
|
||||
/// fetched at a time, so an artist with dozens does not flood the server.
|
||||
pub async fn artist_songs(&self, id: &str) -> Result<Vec<Song>> {
|
||||
let albums = self.artist(id).await?.album;
|
||||
let limit = std::sync::Arc::new(tokio::sync::Semaphore::new(4));
|
||||
let tasks: Vec<_> = albums
|
||||
.into_iter()
|
||||
.map(|a| {
|
||||
let (client, limit) = (self.clone(), limit.clone());
|
||||
tokio::spawn(async move {
|
||||
let _permit = limit.acquire_owned().await?;
|
||||
anyhow::Ok(client.album(&a.id).await?.song)
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let mut songs = Vec::new();
|
||||
for t in tasks {
|
||||
songs.extend(t.await??);
|
||||
}
|
||||
Ok(songs)
|
||||
}
|
||||
|
||||
pub async fn album(&self, id: &str) -> Result<AlbumDetail> {
|
||||
#[derive(Deserialize)]
|
||||
struct R {
|
||||
@@ -605,6 +627,9 @@ mod tests {
|
||||
assert!(!artists.is_empty(), "no artists");
|
||||
let artist = c.artist(&artists[0].id).await.unwrap();
|
||||
println!("artist: {} with {} albums", artist.name, artist.album.len());
|
||||
let songs = c.artist_songs(&artists[0].id).await.unwrap();
|
||||
assert!(!songs.is_empty(), "artist has no songs");
|
||||
println!("artist songs: {}", songs.len());
|
||||
|
||||
let playlists = c.playlists().await.unwrap();
|
||||
if let Some(p) = playlists.first() {
|
||||
|
||||
Reference in New Issue
Block a user