Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Lyric_finder to retrieve correct lyrics instead of its translation #564

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions lyric_finder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,30 @@ impl Client {

/// Get the lyric of a song satisfying a given `query`.
pub async fn get_lyric(&self, query: &str) -> anyhow::Result<LyricResult> {
// The function first searches songs satisfying the query
// then it retrieves the song's lyric by crawling the "genius.com" website.

let result = {
let mut results = self.search_songs(query).await?;
log::debug!("search results: {results:?}");
if results.is_empty() {
return Ok(LyricResult::None);
}
results.remove(0)
// Perform the search for songs
let results = self.search_songs(query).await?;

// Filter to find the first result where the artist names do not contain 'Genius'
let result = results.into_iter()
.find(|result| !result.artist_names.contains("Genius"));

// If no valid result is found, return LyricResult::None
let result = match result {
Some(res) => res,
None => return Ok(LyricResult::None),
};


// Retrieve the song lyrics from the URL of the result
let lyric = self.retrieve_lyric(&result.url).await?;

// Return a LyricResult::Some with the song information
Ok(LyricResult::Some {
track: result.title,
artists: result.artist_names,
lyric: Self::process_lyric(lyric),
})
}

}

impl Default for Client {
Expand Down
Loading