diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/configuration.rs | 3 | ||||
| -rw-r--r-- | src/lyrics_engine/genius.rs | 15 | ||||
| -rw-r--r-- | src/lyrics_engine/mod.rs | 5 | ||||
| -rw-r--r-- | src/main.rs | 8 | ||||
| -rw-r--r-- | src/sources/mod.rs | 8 |
5 files changed, 18 insertions, 21 deletions
diff --git a/src/configuration.rs b/src/configuration.rs index 24beceb..742dd45 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -90,8 +90,7 @@ impl Configuration { Err(_) => match env::var("HOME") { Ok(directory) => PathBuf::from(directory).join(CONFIG_FALLBACK_LOCATION), Err(_) => panic!( - "Could not find required directory, {} or {} should be set and readable.", - CONFIG_ENV_VARIABLE, CONFIG_DEFAULT_LOCATION + "Could not find required directory, {CONFIG_ENV_VARIABLE} or {CONFIG_DEFAULT_LOCATION} should be set and readable." ), }, }, diff --git a/src/lyrics_engine/genius.rs b/src/lyrics_engine/genius.rs index 3c46362..f086fee 100644 --- a/src/lyrics_engine/genius.rs +++ b/src/lyrics_engine/genius.rs @@ -4,7 +4,7 @@ use scraper::{ node::Node::{Element, Text}, }; use serde::Deserialize; -use std::io::{Error, ErrorKind::Other, Result}; +use std::io::{Error, Result}; #[derive(Deserialize, Debug)] struct GeniusApiResponse { @@ -31,12 +31,11 @@ struct GeniusResult { pub async fn search(url: &str) -> Result<String> { let response = get(url) .await - .map_err(|_| Error::new(Other, "Could not perform lyrics search in engine."))? + .map_err(|_| Error::other("Could not perform lyrics search in engine."))? .json::<GeniusApiResponse>() .await .map_err(|_| { - Error::new( - Other, + Error::other( "Lyrics engine returned invalid response from search.", ) })?; @@ -46,7 +45,7 @@ pub async fn search(url: &str) -> Result<String> { .into_iter() .find(|hit| hit.hit_type == "song") .map(|hit| hit.result.url) - .ok_or_else(|| Error::new(Other, "Could not find a matching track in lyrics engine."))?; + .ok_or_else(|| Error::other("Could not find a matching track in lyrics engine."))?; Ok(url) } @@ -54,17 +53,17 @@ pub async fn search(url: &str) -> Result<String> { pub async fn get_lyrics(url: &str) -> Result<String> { let song_html = get(url) .await - .map_err(|_| Error::new(Other, "Could not fetch lyrics from engine."))? + .map_err(|_| Error::other("Could not fetch lyrics from engine."))? .text() .await - .map_err(|_| Error::new(Other, "Lyrics engine returned invalid response."))?; + .map_err(|_| Error::other("Lyrics engine returned invalid response."))?; let document = Html::parse_document(&song_html); let selector = Selector::parse(r#"div[data-lyrics-container="true"]"#).unwrap(); let lyrics_div = document .select(&selector) .next() - .ok_or_else(|| Error::new(Other, "Could not find lyrics in response."))?; + .ok_or_else(|| Error::other("Could not find lyrics in response."))?; let mut lyrics = String::new(); for node in lyrics_div.children() { diff --git a/src/lyrics_engine/mod.rs b/src/lyrics_engine/mod.rs index 81cbf29..746e804 100644 --- a/src/lyrics_engine/mod.rs +++ b/src/lyrics_engine/mod.rs @@ -17,13 +17,12 @@ pub async fn print_lyrics(track: Track, show_title: bool) -> Result<()> { let artist = utf8_percent_encode(&track.artist, NON_ALPHANUMERIC).to_string(); let name = utf8_percent_encode(&track.name, NON_ALPHANUMERIC).to_string(); let url = format!( - "{}?access_token={}&q={}%20{}", - GENIUS_API_URL, GENIUS_CLIENT_TOKEN, artist, name + "{GENIUS_API_URL}?access_token={GENIUS_CLIENT_TOKEN}&q={artist}%20{name}" ); let song_url = search(&url).await?; let lyrics = get_lyrics(&song_url).await?; - println!("{}", lyrics); + println!("{lyrics}"); Ok(()) } diff --git a/src/main.rs b/src/main.rs index 7b61a85..4a3c05f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod lyrics_engine; mod sources; use clap::Parser; -use std::io::{Error, ErrorKind::Other, Result}; +use std::io::{Error, Result}; use configuration::Configuration; use lyrics_engine::print_lyrics; @@ -53,7 +53,7 @@ async fn main() -> Result<()> { match result { Ok(_) => Ok(()), Err(e) => { - eprintln!("Error: {}", e); + eprintln!("Error: {e}"); std::process::exit(1); } } @@ -67,7 +67,7 @@ async fn run() -> Result<()> { if arguments.list_sources { let sources = list(); for source in sources { - print!("{}", source); + print!("{source}"); if configuration.is_enabled(&source) { print!(" (enabled)"); } @@ -102,7 +102,7 @@ async fn run() -> Result<()> { }; } else { current_track = - get_track().ok_or_else(|| Error::new(Other, "No Artist/Song could be found :("))? + get_track().ok_or_else(|| Error::other("No Artist/Song could be found :("))? } print_lyrics(current_track, arguments.show_title).await diff --git a/src/sources/mod.rs b/src/sources/mod.rs index c4122a4..bf68ec3 100644 --- a/src/sources/mod.rs +++ b/src/sources/mod.rs @@ -1,4 +1,4 @@ -use std::io::{Error, ErrorKind::Other, Result}; +use std::io::{Error, Result}; #[cfg(target_os = "macos")] mod apple_music; @@ -42,7 +42,7 @@ pub fn enable(source_name: &String) -> Result<()> { return source.enable(); } } - Err(Error::new(Other, "No such source was available.")) + Err(Error::other("No such source was available.")) } pub fn disable(source_name: &String) -> Result<()> { @@ -52,7 +52,7 @@ pub fn disable(source_name: &String) -> Result<()> { return source.disable(); } } - Err(Error::new(Other, "No such source was available.")) + Err(Error::other("No such source was available.")) } pub fn reset(source_name: &String) -> Result<()> { @@ -62,7 +62,7 @@ pub fn reset(source_name: &String) -> Result<()> { return source.reset(); } } - Err(Error::new(Other, "No such source was available.")) + Err(Error::other("No such source was available.")) } pub fn get_track() -> Option<Track> { |