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;
|
|
|
|
|
2021-12-07 22:22:24 +00:00
|
|
|
use protobuf::Message;
|
2015-06-23 14:38:29 +00:00
|
|
|
|
2019-09-16 19:00:09 +00:00
|
|
|
use librespot_core::session::Session;
|
2021-12-07 22:22:24 +00:00
|
|
|
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;
|
|
|
|
|
2021-12-07 22:52:34 +00:00
|
|
|
pub use error::MetadataError;
|
2021-12-07 22:22:24 +00:00
|
|
|
use request::RequestResult;
|
2021-11-26 22:21:27 +00:00
|
|
|
|
2021-12-07 22:52:34 +00:00
|
|
|
pub use album::Album;
|
|
|
|
pub use artist::Artist;
|
|
|
|
pub use episode::Episode;
|
|
|
|
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 {
|
2018-09-28 10:02:38 +00:00
|
|
|
type Message: protobuf::Message;
|
2015-12-28 15:53:54 +00:00
|
|
|
|
2021-12-07 22:22:24 +00:00
|
|
|
// Request a protobuf
|
|
|
|
async fn request(session: &Session, id: SpotifyId) -> RequestResult;
|
2017-05-16 00:04:10 +00:00
|
|
|
|
2021-12-07 22:22:24 +00:00
|
|
|
// Request a metadata struct
|
2021-11-26 22:21:27 +00:00
|
|
|
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)?;
|
2021-12-07 22:22:24 +00:00
|
|
|
trace!("Received metadata: {:?}", msg);
|
|
|
|
Self::parse(&msg, id)
|
2018-09-28 18:10:22 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 22:22:24 +00:00
|
|
|
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, MetadataError>;
|
2018-02-13 07:33:50 +00:00
|
|
|
}
|