[GH-ISSUE #858] Two qestions about the Rust library - metadata and cover art #431

Closed
opened 2026-02-27 19:30:34 +03:00 by kerem · 2 comments
Owner

Originally created by @unsuited1 on GitHub (Oct 5, 2021).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/858

I am working on a native Rust Spotify binary for GNU/Linux to get more familiar with this language.

I tried to get more metadata of Tracks / Albums than is given in librespot_metadata::Track. librespot_protocol::metadata::Track implements much more functions like get_disc_number(), so there must somehow be a way to get this data via librespot. Since I am new to Rust I was not able to fetch this data yet. Can anyone please give me a hint on how to obtain more metadata about a given librespot_metadata::Track / librespot_metadata::Album (I assume the workflow is similar for tracks / albums / artists)?

My second issue involves fetching a cover art of an album. librespot_metadata::cover has a function get() which returns ChannelData which implements Stream / StreamExt. StreamExt has a function next() which should yield a Result containing either Bytes or a ChannelError (in this implementation) after having being awaited. For some reason I always get a ChannelError, the warning log prints this: ERROR librespot_core::channel] channel error: 2 0. Looking into the source code did not help much, because I am, as I said, pretty new to Rust. My code looks like this:

pub async fn get_album_cover(
  album: &Album,
  session: &Session,
) -> Vec<u8> {
  let mut covers = Vec::new();
  'outer: for file_id in album.covers.iter() {
    info!("{:?}", file_id.0);
    let mut channel = cover::get(session, *file_id);
    let mut cover: Vec<u8> = Vec::new();

    while let Some(result) = channel.next().await {
      match result {
        Ok(data) => {
          info!("Got cover data: {:?}", data);
          data.into_iter().for_each(|byte| {
            cover.push(byte);
          });
        }
        Err(e) => {
          warn!("Error downloading cover: {:?}", e);
          continue 'outer;
        }
      }
    }
    covers.push(cover);
  }

  // -- determine best, return that --
  // [...]

}

Somehow channel.next().await always returns Some(Err(ChannelError)) (eg. the program always goes into the Err(e) part of the match statement). Why is that and how can I fix that?

Thanks in advance for every bit of help. If that is not the right place to ask about the library, where can I ask about it?

Originally created by @unsuited1 on GitHub (Oct 5, 2021). Original GitHub issue: https://github.com/librespot-org/librespot/issues/858 I am working on a native Rust Spotify binary for GNU/Linux to get more familiar with this language. I tried to get more metadata of Tracks / Albums than is given in [librespot_metadata::Track](https://docs.rs/librespot-metadata/0.2.0/librespot_metadata/struct.Track.html). [librespot_protocol::metadata::Track](https://docs.rs/librespot-protocol/0.2.0/librespot_protocol/metadata/struct.Track.html) implements much more functions like `get_disc_number()`, so there must somehow be a way to get this data via `librespot`. Since I am new to Rust I was not able to fetch this data yet. Can anyone please give me a hint on how to obtain more metadata about a given `librespot_metadata::Track` / `librespot_metadata::Album` (I assume the workflow is similar for tracks / albums / artists)? My second issue involves fetching a cover art of an album. [librespot_metadata::cover](https://docs.rs/librespot-metadata/0.2.0/librespot_metadata/cover/index.html) has a function `get()` which returns `ChannelData` which implements `Stream` / `StreamExt`. `StreamExt` has a function `next()` which should yield a `Result` containing either `Bytes` or a `ChannelError` (in this implementation) after having being awaited. For some reason I always get a `ChannelError`, the warning log prints this: `ERROR librespot_core::channel] channel error: 2 0`. Looking into the source code did not help much, because I am, as I said, pretty new to Rust. My code looks like this: ```rust pub async fn get_album_cover( album: &Album, session: &Session, ) -> Vec<u8> { let mut covers = Vec::new(); 'outer: for file_id in album.covers.iter() { info!("{:?}", file_id.0); let mut channel = cover::get(session, *file_id); let mut cover: Vec<u8> = Vec::new(); while let Some(result) = channel.next().await { match result { Ok(data) => { info!("Got cover data: {:?}", data); data.into_iter().for_each(|byte| { cover.push(byte); }); } Err(e) => { warn!("Error downloading cover: {:?}", e); continue 'outer; } } } covers.push(cover); } // -- determine best, return that -- // [...] } ``` Somehow `channel.next().await` always returns `Some(Err(ChannelError))` (eg. the program always goes into the `Err(e)` part of the `match` statement). Why is that and how can I fix that? Thanks in advance for every bit of help. If that is not the right place to ask about the library, where can I ask about it?
kerem 2026-02-27 19:30:34 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@roderickvd commented on GitHub (Oct 5, 2021):

You could try on the chat over at Gitter. This isn't really a librespot bug, so I'm closing this issue.

If you use the search, you will find a couple of old issues with channel errors. Usually they have been server errors if my memory serves correctly, or at least protocol errors. Best of luck with your endeavour and while learning Rust, do drop by and contribute to librespot if you can! It's how I learned Rust and look at me now 😆 still learning!

<!-- gh-comment-id:934642804 --> @roderickvd commented on GitHub (Oct 5, 2021): You could try on the chat over at [Gitter](https://gitter.im/librespot-org/spotify-connect-resources). This isn't really a `librespot` bug, so I'm closing this issue. If you use the search, you will find a couple of old issues with channel errors. Usually they have been server errors if my memory serves correctly, or at least protocol errors. Best of luck with your endeavour and while learning Rust, do drop by and contribute to `librespot` if you can! It's how I learned Rust and look at me now 😆 still learning!
Author
Owner

@unsuited1 commented on GitHub (Oct 5, 2021):

Thanks for the fast answer!

I'll go and ask over at gitter.

<!-- gh-comment-id:934645287 --> @unsuited1 commented on GitHub (Oct 5, 2021): Thanks for the fast answer! I'll go and ask over at gitter.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#431
No description provided.