librespot/metadata/src/lib.rs

52 lines
1.1 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
2019-09-16 19:00:09 +00:00
use librespot_core::session::Session;
use librespot_core::spotify_id::SpotifyId;
pub mod album;
pub mod artist;
pub mod audio;
pub mod availability;
pub mod content_rating;
pub mod copyright;
pub mod date;
pub mod episode;
pub mod error;
pub mod external_id;
pub mod image;
pub mod playlist;
mod request;
pub mod restriction;
pub mod sale_period;
pub mod show;
pub mod track;
mod util;
pub mod video;
use error::MetadataError;
use request::RequestResult;
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;
// Request a protobuf
async fn request(session: &Session, id: SpotifyId) -> RequestResult;
// Request a metadata struct
async fn get(session: &Session, id: SpotifyId) -> Result<Self, MetadataError> {
let response = Self::request(session, id).await?;
let msg = Self::Message::parse_from_bytes(&response)?;
trace!("Received metadata: {:?}", msg);
Self::parse(&msg, id)
2018-09-28 18:10:22 +00:00
}
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, MetadataError>;
2018-02-13 07:33:50 +00:00
}