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
use crate::{
client::{
TidalClient,
models::album::{
AlbumCreditsResponse, AlbumInfoResponse, AlbumItemsResponse,
AlbumItemsWithCreditsResponse,
},
},
error::TidalError,
ids::AlbumId,
};
impl TidalClient {
/// Retrieves album information by album ID
///
/// # Example
///
/// ```no_run
/// # use tidlers::{TidalClient, auth::init::TidalAuth};
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let auth = TidalAuth::with_oauth();
/// # let client = TidalClient::new(&auth);
/// let album = client.get_album("123456789").await?;
/// println!("Album: {} by {}", album.title, album.artist.name);
/// println!("Tracks: {}", album.number_of_tracks);
/// # Ok(())
/// # }
/// ```
pub async fn get_album(
&self,
album_id: impl Into<AlbumId>,
) -> Result<AlbumInfoResponse, TidalError> {
let album_id = album_id.into();
self.request(reqwest::Method::GET, format!("/albums/{}/", album_id))
.with_country_code()
.send()
.await
}
/// Retrieves tracks from an album with pagination support
///
/// # Example
///
/// ```no_run
/// # use tidlers::{TidalClient, auth::init::TidalAuth};
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let auth = TidalAuth::with_oauth();
/// # let client = TidalClient::new(&auth);
/// // Get first 50 tracks
/// let items = client.get_album_items("123456789", Some(50), Some(0)).await?;
/// for album_item in items.items {
/// println!("{}", album_item.item.title);
/// }
/// # Ok(())
/// # }
/// ```
pub async fn get_album_items(
&self,
album_id: impl Into<AlbumId>,
limit: Option<u64>,
offset: Option<u64>,
) -> Result<AlbumItemsResponse, TidalError> {
let album_id = album_id.into();
let limit = limit.unwrap_or(20);
let offset = offset.unwrap_or(0);
if limit > 100 {
return Err(TidalError::InvalidArgument(
"limit cannot be greater than 100".to_string(),
));
}
self.request(reqwest::Method::GET, format!("/albums/{}/items", album_id))
.with_country_code()
.with_param("limit", limit.to_string())
.with_param("offset", offset.to_string())
.send()
.await
}
/// Retrieves album credits information
pub async fn get_album_credits(
&self,
album_id: impl Into<AlbumId>,
) -> Result<AlbumCreditsResponse, TidalError> {
let album_id = album_id.into();
self.request(
reqwest::Method::GET,
format!("/albums/{}/credits", album_id),
)
.with_country_code()
.send()
.await
}
pub async fn get_album_items_credits(
&self,
album_id: impl Into<AlbumId>,
limit: Option<u64>,
offset: Option<u64>,
) -> Result<AlbumItemsWithCreditsResponse, TidalError> {
let album_id = album_id.into();
let limit = limit.unwrap_or(20);
let offset = offset.unwrap_or(0);
if limit > 100 {
return Err(TidalError::InvalidArgument(
"limit cannot be greater than 100".to_string(),
));
}
self.request(
reqwest::Method::GET,
format!("/albums/{}/items/credits", album_id),
)
.with_country_code()
.with_param("limit", limit.to_string())
.with_param("offset", offset.to_string())
.send()
.await
}
}