librespot_metadata/
lib.rs1#[macro_use]
2extern crate log;
3
4#[macro_use]
5extern crate async_trait;
6
7use protobuf::Message;
8
9use librespot_core::{Error, Session, SpotifyUri};
10
11pub mod album;
12pub mod artist;
13pub mod audio;
14pub mod availability;
15pub mod content_rating;
16pub mod copyright;
17pub mod episode;
18pub mod error;
19pub mod external_id;
20pub mod image;
21pub mod lyrics;
22pub mod playlist;
23mod request;
24pub mod restriction;
25pub mod sale_period;
26pub mod show;
27pub mod track;
28mod util;
29pub mod video;
30
31pub use error::MetadataError;
32use request::RequestResult;
33
34pub use album::Album;
35pub use artist::Artist;
36pub use episode::Episode;
37pub use lyrics::Lyrics;
38pub use playlist::Playlist;
39pub use show::Show;
40pub use track::Track;
41
42#[async_trait]
43pub trait Metadata: Send + Sized + 'static {
44 type Message: protobuf::Message + std::fmt::Debug;
45
46 async fn request(session: &Session, id: &SpotifyUri) -> RequestResult;
48
49 async fn get(session: &Session, id: &SpotifyUri) -> Result<Self, Error> {
51 let response = Self::request(session, id).await?;
52 let msg = Self::Message::parse_from_bytes(&response)?;
53 trace!("Received metadata: {msg:#?}");
54 Self::parse(&msg, id)
55 }
56
57 fn parse(msg: &Self::Message, _: &SpotifyUri) -> Result<Self, Error>;
58}