lastfm
lastfm is an async Rust client to fetch your Last.fm listening history or the track you are currently playing
Installation
Add the following to your Cargo.toml:
[]
= "*"
Replace the * with the actual version you want to use.
Alternatively you can run:
Usage
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.
Create a new client
If you have your API key exposed through the LASTFM_API_KEY environment variable, you can use the from_env method:
let client = from_env;
Note: this method will panic if LASTFM_API_KEY is not set.
Alternatively, you can use try_from_env which will return a Result.
let maybe_client = try_from_env;
match maybe_client
Finally, for more advanced configurations you can use a Client::builder():
let client = builder.api_key.username.build;
Fetch the track you are currently playing
async
Fetch your listening history
Note: You will need the futures-util crate to use the Stream returned by all_tracks.
use pin_mut;
use StreamExt;
async
Examples
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:
- copy
.env~sampleinto.env - add your last.fm API Key in there
- run a give example. E.g.:
cargo run --example fetch_all
Other implementations
This project is a port of something I have already done in JavaScript (Node.js). Check out lmammino/scrobbles if you are curious.
Contributing
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.
License
Licensed under MIT License. © Luciano Mammino.