alt-art / genius-rs Goto Github PK
View Code? Open in Web Editor NEWRust library that allows interact with Genius API
Home Page: https://crates.io/crates/genius-rs
License: MIT License
Rust library that allows interact with Genius API
Home Page: https://crates.io/crates/genius-rs
License: MIT License
fn get_song(id: u32) -> Song
Line 121 in f9636b1
The type field of the Hit struct is currently explicitly escaped in the code to allow the keyword to line up with the API response. It's consistent with the rest of the design, which is nice, but causes issues for a user of the crate if they want to match against that type. Renaming it to something functionally identical that doesn't collide with the type keyword would be a good first step to making the library hide the details of the API responses and make it a little easier to use. :)
The ergonomics are already a little weird, but when having to escape the type keyword, it makes it almost too weird to use:
let search_result = Genius::new(token).search(artist_name.as_str()).await;
if let Ok(result) = search_result {
if (result.meta.status == 200) {
let hits = result.response.hits;
for hit in hits {
(hit.r#type == "song".to_string());
}
}
}
use genius_rs::Genius;
#[tokio::main]
async fn main() {
let genius = Genius::new(dotenv::var("TOKEN").unwrap());
let response = genius.search("Sia").await;
match response {
Ok(resp) => println!("{:?}", resp),
Err(e) => println!("{:?}", e),
}
}
I was checking the examples listed in the readme, but I couldn't reproduce them since the error says that the response can't be parsed because it's not a valid. The error is the following:
ParseError("error decoding response body: missing field `response` at line 1 column 134")
Line 87 in f9636b1
Line 76 in f9636b1
Making the Genius methods both labeled with ![tokio::main] is problematic, since effectively it makes them unusable as library calls. They're async functions that can't be executed by the user's runtime, you reproduce the tokio runtime with every call of those methods. It dodges compiler issues, okay, but in practice this barely works for performance, and makes using the methods more unwieldy. Try instead making your test methods use the tokio test attribute.
Looks like https://lyrics.altart.tk is no longer available.
code:
let lyrics = genius.get_lyrics("https://genius.com/Marty-robbins-big-iron-lyrics").await.unwrap();
println!("{:#?}", lyrics);
result:
[]
maybe a i did something wrong? Using the code provided on the readme doesnt seems to help.
Love this crate. API wrappers are the unsung heroes of any application ecosystem, and I'm glad to see any improvements to Rust's application-level situation. Having said that, I'm curious if this library can map to some common Rust idioms.
In this case, as of version 0.4.0, this library still uses a struct to represent a Hit, or search result from the Genius API.
Lines 5 to 11 in 283c082
Can this be changed? serde
allows the deserialization of enums, and if there are even types other than "song" that would appear in the type field, an enum could be used to represent them. It would certainly be much easier to use than having to read all the public fields of each type.
I couldn't find a complete list of "type"s that Genius search hits can have, but since they seem to only currently support a song type, it is likely they may simply have future proofed, intending to update their database later on to distinguish between music videos and songs, which they currently do not do. For the time being, a single-variant, #[non-exhaustive]
enum could represent this perfectly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.