lastfm
is an async Rust client to fetch your
Add the following to your Cargo.toml
:
toml
[dependencies]
lastfm = "0.1.0"
Alternatively you can run:
```bash cargo add lastfm ````
To use this library you will need a Last.fm account and an API key. You can get one by registering an application. If you have already registered an application, you can find your API key in the API settings.
rust
let client = Client::new("YOUR_API_KEY", "YOUR_USERNAME");
If you have your API key exposed through the LASTFM_API_KEY
environment variable, you can use the from_env
method:
rust
let client = Client::from_env("YOUR_USERNAME");
Note: this method will panic if LASTFM_API_KEY
is not set.
```rust
async fn main() -> Result<(), Box
Ok(()) } ```
Note: You will need the futures-util
crate to use the Stream
returned by all_tracks
.
```rust use futuresutil::pinmut;
async fn main() -> Result<(), Box
let recenttracks = tracks.intostream(); pinmut!(recenttracks); // needed for iteration while let Some(track) = recenttracks.next().await { match track { Ok(track) => { println!( "{}: {} - {}", track.date.torfc2822(), track.artist.name, track.name ); } Err(e) => { println!("Error fetching data: {:?}", e); } } } Ok(()) } ```
This package provides some usage examples in the examples
folder.
You will need an API key to run the examples so you will need to:
.env~sample
into .env
cargo run --example fetch_all
This project is a port of something I have already done in JavaScript (Node.js). Check out lmammino/scrobbles
if you are curious.
Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.
Licensed under MIT License. © Luciano Mammino.