1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
//! [Album API](https://developers.deezer.com/api/album) #[warn(missing_docs)] use serde::{Deserialize, Serialize}; use crate::models::{Artist, ContributorArtist, DeezerArray, DeezerObject, Genre, Track}; use crate::Result; /// Contains all the information provided for an Album. /// /// # Examples /// /// You can query an album by id via the [`DeezerObject::get()`] method: /// /// ```rust /// # use deezer::models::*; /// # use deezer::DeezerError; /// # /// # #[tokio::main] /// # async fn main() -> Result<(), DeezerError> { /// let album = Album::get(302127).await?.unwrap(); /// # assert_eq!(album.id, 302127); /// # println!("{:?}", album); /// # Ok(()) /// # } /// ``` /// /// Or you can use [`DeezerClient::album()`](crate::DeezerClient::album()): /// /// ```rust /// # use deezer::models::*; /// # use deezer::{DeezerClient, DeezerError}; /// # /// # #[tokio::main] /// # async fn main() -> Result<(), DeezerError> { /// let deezer = DeezerClient::new(); /// /// let album = deezer.album(302127).await?.unwrap(); /// # assert_eq!(album.id, 302127); /// # Ok(()) /// # } /// /// ``` #[derive(Deserialize, Serialize, Debug, Clone)] pub struct Album { /// `The Deezer album id` pub id: u64, /// `The album title` pub title: String, /// `The album UPC` pub upc: String, /// `The url of the album on Deezer` pub link: String, /// `The share link of the album on Deezer` #[serde(rename = "share")] pub share_link: String, /// `The url of the album's cover.` pub cover: String, /// `The url of the album's cover in size small.` pub cover_small: String, /// `The url of the album's cover in size medium.` pub cover_medium: String, /// `The url of the album's cover in size big.` pub cover_big: String, /// `The url of the album's cover in size xl.` pub cover_xl: String, /// `The album's first genre id (You should use the genre list instead).` pub genre_id: Option<i32>, /// `List of genre object` pub genres: DeezerArray<AlbumGenre>, /// `The album's label name` pub label: String, /// `Number of tracks in the album` pub nb_tracks: u64, /// `The album's duration in seconds` #[serde(rename = "duration")] pub duration_in_seconds: u64, /// `The number of album's Fans` pub fans: u64, /// `The album's rate` pub rating: u64, /// `The album's release date` pub release_date: String, /// `The record type of the album (EP / ALBUM / etc..)` pub record_type: String, /// `Whether it's available right now` pub available: bool, /// `Return an alternative album object if the current album is not available` #[serde(default)] #[serde(rename = "alternative")] pub alternative_album: Option<Box<Album>>, /// `API Link to the tracklist of this album` #[serde(rename = "tracklist")] tracklist_api_url: String, /// `Whether the album contains explicit lyrics` #[serde(rename = "explicit_lyrics")] pub has_explicit_lyrics: bool, /// `Return a list of contributors on the album` pub contributors: Vec<ContributorArtist>, /// `Returns an AlbumArtist object of the artist this album belongs to` pub artist: AlbumArtist, /// `list of Track objects that belong to this album` pub tracks: DeezerArray<AlbumTrack>, } impl DeezerObject for Album { fn get_api_url(id: u64) -> String { format!("album/{}", id) } } /// Subset of [`Artist`]. /// /// Use [`get_full()`] for the full [`Artist`]. /// /// [`get_full()`]: AlbumArtist::get_full #[derive(Deserialize, Serialize, Debug, Clone)] pub struct AlbumArtist { /// `The artist's Deezer id` pub id: u64, /// `The artist's name` pub name: String, /// `The url of the artist picture` pub picture: String, /// `The url of the artist picture in size small` pub picture_small: String, /// `The url of the artist picture in size medium` pub picture_medium: String, /// `The url of the artist picture in size big` pub picture_big: String, /// `The url of the artist picture in size xl` pub picture_xl: String, } impl AlbumArtist { /// Returns the corresponding [`Artist`]. /// /// # Panics /// /// Can panic when the [artist api](https://developers.deezer.com/api/artist) returns `404 - Not Found`. /// /// This should never happen as [`AlbumArtist`] references an existing [`Artist`]. pub async fn get_full(&self) -> Result<Artist> { // Safety: unwrap should be okay here, as the artist is referenced by the deezer api let artist = Artist::get(self.id).await?.unwrap(); Ok(artist) } } /// Subset of [`Artist`]. /// /// Use [`get_full()`] for the full [`Artist`]. /// /// [`get_full()`]: AlbumTrackArtist::get_full #[derive(Deserialize, Serialize, Debug, Clone)] pub struct AlbumTrackArtist { /// `Artist's Deezer Id` pub id: u64, /// `Artist's name` pub name: String, /// `Artist's Deezer tracklist` pub tracklist: String, } impl AlbumTrackArtist { /// Returns the corresponding [`Artist`]. /// /// # Panics /// /// Can panic when the [artist api](https://developers.deezer.com/api/artist) returns `404 - Not Found`. /// /// This should never happen as [`AlbumTrackArtist`] references an existing [`Artist`]. pub async fn get_full(&self) -> Result<Artist> { // Safety: unwrap should be okay here, as the artist is referenced by the deezer api let artist = Artist::get(self.id).await?.unwrap(); Ok(artist) } } /// Subset of [`Track`]. /// /// Use [`get_full()`] for the full [`Track`]. /// /// [`get_full()`]: AlbumTrack::get_full #[derive(Deserialize, Serialize, Debug, Clone)] pub struct AlbumTrack { /// `The track's Deezer id` pub id: u64, /// `True if the track is readable in the player for the current user` pub readable: bool, /// `The track's full title` pub title: String, /// `The track's short title` pub title_short: String, /// `The track version` pub title_version: String, /// `The url of the track on Deezer` pub link: String, /// `The track's duration in seconds` #[serde(rename = "duration")] pub duration_in_seconds: u64, /// `The track's Deezer rank` pub rank: u64, /// `Whether the track contains explicit lyrics` pub explicit_lyrics: bool, /// `The url of track's preview file. This file contains the first 30 seconds of the track` pub preview: String, /// `AlbumTrackArtist object` pub artist: AlbumTrackArtist, } impl AlbumTrack { /// Returns the corresponding [`Track`]. /// /// # Panics /// /// Can panic when the [track api](https://developers.deezer.com/api/track) returns `404 - Not Found`. /// /// This should never happen as [`AlbumTrack`] references an existing [`Track`]. pub async fn get_full(&self) -> Result<Track> { // Safety: unwrap should be okay here, as the artist is referenced by the deezer api let track = Track::get(self.id).await?.unwrap(); Ok(track) } } /// Subset of [`Genre`]. /// /// Use [`get_full()`] for the full [`Genre`]. /// /// [`get_full()`]: AlbumGenre::get_full #[derive(Deserialize, Serialize, Debug, Clone)] pub struct AlbumGenre { /// `The Genre's id` pub id: u64, /// `The Genre's name` pub name: String, /// `The url of the genre picture` pub picture: String, } impl AlbumGenre { /// Returns the corresponding [`Genre`]. /// /// # Panics /// /// Can panic when the [genre api](https://developers.deezer.com/api/genre) returns `404 - Not Found`. /// /// This should never happen as [`AlbumGenre`] references an existing [`Genre`]. pub async fn get_full(&self) -> Result<Genre> { // Safety: unwrap should be okay here, as the artist is referenced by the deezer api let genre = Genre::get(self.id).await?.unwrap(); Ok(genre) } }