]> git.r.bdr.sh - rbdr/lyricli/blame - src/lyrics_engine/mod.rs
Remove the openssl stuff
[rbdr/lyricli] / src / lyrics_engine / mod.rs
CommitLineData
738ec06d
RBR
1use std::io::Result;
2use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
3
4mod genius;
5
6use crate::Track;
7use genius::{get_lyrics, search};
8
9const GENIUS_CLIENT_TOKEN: &str = env!("LYRICLI_GENIUS_TOKEN");
10const GENIUS_API_URL: &str = "https://api.genius.com/search";
11
12pub async fn print_lyrics(track: Track, show_title: bool) -> Result<()> {
13 if show_title {
14 println!("{} - {}", track.artist, track.name);
15 }
16
17 let artist = utf8_percent_encode(&track.artist, NON_ALPHANUMERIC).to_string();
18 let name = utf8_percent_encode(&track.name, NON_ALPHANUMERIC).to_string();
19 let url = format!("{}?access_token={}&q={}%20{}", GENIUS_API_URL, GENIUS_CLIENT_TOKEN, artist, name);
20
21 let song_url = search(&url).await?;
22 let lyrics = get_lyrics(&song_url).await?;
23
24 println!("{}", lyrics);
25 Ok(())
26}