rust_fm

Crates.iorust_fm
lib.rsrust_fm
version0.1.4
created_at2025-06-12 04:16:47.798914+00
updated_at2025-06-12 11:55:23.09825+00
descriptionlast.fm OAUTH and scrobbling
homepage
repositoryhttps://github.com/hchap1/rust-fm
max_upload_size
id1709352
size62,727
Hchap1 (hchap1)

documentation

README

Rust-FM is a lightweight client for integrating with the last.fm API, including the following featureset:

  • Web OAUTH flow
    • Automatically redirects users to authentication page
    • Creates a local webserver to host a redirect
    • Grabs token from local webserver
    • Automatically creates a session token from this
  • Now playing
    • Asynchronously set the now playing status of the user
  • Scrobbling
    • Push a scrobble, relies on you to implement the LAST.FM rules
    • Generate timestamp if one is not provided

Full example:

use rust_fm::auth::WebOAuth;
use rust_fm::token::WebCallback;
use rust_fm::session::WebSession;
use rust_fm::playing::{Scrobble, NowPlaying};

#[tokio::main]
async fn main() {
    let auth = WebOAuth::from_key_and_secret(
        Some("my_key".to_string()),
        Some("my_secret".to_string()),
        None // Do not yet have permanent session token
    );

    let (auth, res) = WebCallback::oauth(auth).await;
    res.expect("Failed to retrieve Authentication Token");
    println!("Token: {:?}", auth.get_token());

    let (auth, res) = WebSession::get(auth).await;
    res.expect("Failed to retrieve Web Session Token");
    println!("Session: {:?}", auth.get_session());

    let scrobble = Scrobble::new(
        "Song title".to_string(),
        "Song artist".to_string(),
        Some("Optional Album".to_string())
    );

    let _ = NowPlaying::set_now_playing(auth.clone(), scrobble.clone());

    // Optionally specify the timestamp the song started playing.
    let _ = NowPlaying::push_scrobble(auth, scrobble, None);
}

Commit count: 21

cargo fmt