Skip to content
/ rust-fm Public

Rust project to asynchronously interact with the last.fm API with modern authentication flows.

Notifications You must be signed in to change notification settings

hchap1/rust-fm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
}

About

Rust project to asynchronously interact with the last.fm API with modern authentication flows.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages