librespot/metadata/src/lib.rs

59 lines
1.3 KiB
Rust
Raw Normal View History

2019-09-22 19:21:44 +00:00
#[macro_use]
extern crate log;
2021-01-21 21:07:16 +00:00
#[macro_use]
extern crate async_trait;
use protobuf::Message;
2015-06-23 14:38:29 +00:00
use librespot_core::{Error, Session, SpotifyId};
pub mod album;
pub mod artist;
pub mod audio;
pub mod availability;
pub mod content_rating;
pub mod copyright;
pub mod episode;
pub mod error;
pub mod external_id;
pub mod image;
pub mod lyrics;
pub mod playlist;
mod request;
pub mod restriction;
pub mod sale_period;
pub mod show;
pub mod track;
mod util;
pub mod video;
2021-12-07 22:52:34 +00:00
pub use error::MetadataError;
use request::RequestResult;
2021-12-07 22:52:34 +00:00
pub use album::Album;
pub use artist::Artist;
pub use episode::Episode;
pub use lyrics::Lyrics;
2021-12-07 22:52:34 +00:00
pub use playlist::Playlist;
pub use show::Show;
pub use track::Track;
2021-01-21 21:07:16 +00:00
#[async_trait]
2018-02-12 20:02:27 +00:00
pub trait Metadata: Send + Sized + 'static {
type Message: protobuf::Message + std::fmt::Debug;
// Request a protobuf
2022-08-03 20:26:52 +00:00
async fn request(session: &Session, id: &SpotifyId) -> RequestResult;
// Request a metadata struct
2022-08-03 20:26:52 +00:00
async fn get(session: &Session, id: &SpotifyId) -> Result<Self, Error> {
let response = Self::request(session, id).await?;
let msg = Self::Message::parse_from_bytes(&response)?;
2021-12-11 19:45:08 +00:00
trace!("Received metadata: {:#?}", msg);
Self::parse(&msg, id)
2018-09-28 18:10:22 +00:00
}
2022-08-03 20:26:52 +00:00
fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error>;
2018-02-13 07:33:50 +00:00
}