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
use reqwest::Error;
use serde::Deserialize;
#[derive(Deserialize)]
struct Lyrics {
lyrics: String,
}
pub async fn get_lyrics(title: &str, author: &str) -> Result<String, Error> {
let resp = reqwest::get(&format!("https://api.lyrics.ovh/v1/{}/{}", author, title))
.await?
.json::<Lyrics>()
.await?;
Ok(resp.lyrics)
}
#[cfg(test)]
#[tokio::test]
async fn test_fetch_lyrics() {
let lyrics = get_lyrics("popular monster", "Falling in Reverse").await;
assert!(lyrics.is_ok());
let lyrics = lyrics.unwrap();
assert!(lyrics.starts_with("Yeah"));
assert!(lyrics.contains("And my doctor tries to tell me that I'm going through a phase"));
}