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
|
|
|
|
2021-12-26 20:18:42 +00:00
|
|
|
use librespot_core::{Error, Session, SpotifyId};
|
2021-12-07 22:22:24 +00:00
|
|
|
|
|
|
|
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;
|
2022-12-26 17:03:27 +00:00
|
|
|
pub mod lyrics;
|
2021-12-07 22:22:24 +00:00
|
|
|
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;
|
2022-12-26 17:03:27 +00:00
|
|
|
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 {
|
2023-01-17 20:46:14 +00:00
|
|
|
type Message: protobuf::Message + std::fmt::Debug;
|
2015-12-28 15:53:54 +00:00
|
|
|
|
2021-12-07 22:22:24 +00:00
|
|
|
// Request a protobuf
|
2022-08-03 20:26:52 +00:00
|
|
|
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
|
2022-08-03 20:26:52 +00:00
|
|
|
async fn get(session: &Session, id: &SpotifyId) -> Result<Self, Error> {
|
2021-11-26 22:21:27 +00:00
|
|
|
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);
|
2021-12-07 22:22:24 +00:00
|
|
|
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
|
|
|
}
|