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
use std::convert::Into;
use std::borrow::Cow;
use url::Url as StdUrl;
use lastfm_type::{LastfmType, Request, RequestParams};
use super::common::{Url, Image, Id2, Streamable, str_to_option, str_to_val};
#[derive(Debug)]
pub enum Params<'dt> {
Phantom(&'dt ()),
GetTopArtists {
limit: Option<u32>,
page: Option<u32>,
},
GetTopTags {
limit: Option<u32>,
page: Option<u32>,
},
GetTopTracks {
limit: Option<u32>,
page: Option<u32>,
},
}
impl<'pr> RequestParams for Params<'pr> {
fn method(&self) -> &str {
match *self {
Params::GetTopArtists { .. } => "chart.gettopartists",
Params::GetTopTags { .. } => "chart.gettoptags",
Params::GetTopTracks { .. } => "chart.gettoptracks",
Params::Phantom(_) => panic!("this is a dummy item"),
}
}
fn needs_signature(&self) -> bool {
false
}
fn needs_session_key(&self) -> bool {
false
}
fn append_to(&self, url: &mut StdUrl) {
let mut query = url.query_pairs_mut();
match *self {
Params::GetTopArtists { limit, page } => {
if let Some(limit) = limit {
query.append_pair("limit", &limit.to_string());
}
if let Some(page) = page {
query.append_pair("page", &page.to_string());
}
}
Params::GetTopTags { limit, page } => {
if let Some(limit) = limit {
query.append_pair("limit", &limit.to_string());
}
if let Some(page) = page {
query.append_pair("page", &page.to_string());
}
}
Params::GetTopTracks { limit, page } => {
if let Some(limit) = limit {
query.append_pair("limit", &limit.to_string());
}
if let Some(page) = page {
query.append_pair("page", &page.to_string());
}
}
Params::Phantom(_) => panic!("this is a dummy item"),
}
}
}
#[derive(Deserialize, Debug)]
pub struct Artist<'dt> {
pub name: Cow<'dt, str>,
pub mbid: Option<&'dt str>,
pub url: Url<'dt>,
#[serde(deserialize_with = "str_to_val")]
pub playcount: u32,
#[serde(deserialize_with = "str_to_val")]
pub listeners: u32,
#[serde(default)]
#[serde(deserialize_with = "str_to_option")]
pub streamable: Option<u32>,
pub image: Vec<Image<'dt>>,
}
#[derive(Deserialize, Debug)]
pub struct GetTopArtists<'dt> {
#[serde(borrow)]
pub artist: Option<Vec<Artist<'dt>>>,
}
lastfm_t!(
artists,
GetTopArtists,
_TopArtists,
Params,
GetTopArtists,
[limit: Option<u32>, page: Option<u32>]
);
#[derive(Deserialize, Debug)]
pub struct Tag<'dt> {
pub name: Cow<'dt, str>,
pub url: Url<'dt>,
#[serde(deserialize_with = "str_to_val")]
pub reach: u32,
#[serde(deserialize_with = "str_to_val")]
pub taggings: u32,
#[serde(deserialize_with = "str_to_val")]
pub streamable: u32,
}
#[derive(Deserialize, Debug)]
pub struct GetTopTags<'dt> {
#[serde(borrow)]
pub tag: Option<Vec<Tag<'dt>>>,
}
lastfm_t!(
tags,
GetTopTags,
_TopTags,
Params,
GetTopTags,
[limit: Option<u32>, page: Option<u32>]
);
#[derive(Deserialize, Debug)]
pub struct Track<'dt> {
pub name: Cow<'dt, str>,
pub mbid: Option<&'dt str>,
pub url: Url<'dt>,
#[serde(deserialize_with = "str_to_val")]
pub duration: u32,
#[serde(deserialize_with = "str_to_val")]
pub playcount: u32,
#[serde(deserialize_with = "str_to_val")]
pub listeners: u32,
pub streamable: Streamable,
pub artist: Id2<'dt>,
pub image: Vec<Image<'dt>>,
}
#[derive(Deserialize, Debug)]
pub struct GetTopTracks<'dt> {
#[serde(borrow)]
pub track: Option<Vec<Track<'dt>>>,
}
lastfm_t!(
tracks,
GetTopTracks,
_TopTracks,
Params,
GetTopTracks,
[limit: Option<u32>, page: Option<u32>]
);