Git Product home page Git Product logo

rustfm-scrobble's Introduction

rustfm-scrobble

Latest Version Rust

rustfm-scrobble is a Last.fm Scrobble API 2.0 crate for Rust. It allows easy acccess to the "scrobble" and "now playing" notification endpoints through a simple Rust API. It can be used to record song-plays from music players, build analog scrobbling tools similar to VinylScrobbler or work with IoT Devices. It was initially built to implement a Spotify scrobbling service using the Spotify Connect Protocol when the Alexa Spotify client did not support scrobbling plays to Last.fm.

Features

  • Scrobble songs to Last.fm ('scrobble' API endpoint)
  • Publish now-playing song to Last.fm ('now playing' API endpoint)
  • Batch scrobble support in Scrobbler::scrobble_batch and ScrobbleBatch
  • Multiple authentication flows to gain permissions to publish to Last.fm user profile
    • Store a pre-authenticated session key & throw away secret data after initial authentication
  • Simple error handling; each API operation returns a Result with a simple Error type on failure
  • Unit tested

Install

Add rustfm-scrobble to your Cargo.toml.

[dependencies]
rustfm-scrobble="1.1"

Usage

  • API Documentation
  • Code Examples
    • Example now-playing & scrobbling client
    • Example batch scrobbling client
    • cargo build --examples
    • ./target/debug/examples/example
  • Build: cargo build
  • Run Unit tests: cargo test
extern crate rustfm_scrobble;
use rustfm_scrobble::{Scrobble, Scrobbler};

let username = "last-fm-username";
let password = "last-fm-password";
let api_key = "client-api-key";
let api_secret = "client-api-secret";
 
let mut scrobbler = Scrobbler::new(api_key, api_secret);
scrobbler.authenticate_with_password(username, password);
 
let song = Scrobble::new("Example Artist", "Example Song", "Example Album");
scrobbler.scrobble(song);

In Use

rustfm-scrobble is used in several projects including polaris, connectr, rescrobbled and rb-scrobbler.

Status

The API is stable & backwards compatibility will be guaranteed for all 1.0 releases.

License

MIT license, see ./LICENSE.

rustfm-scrobble's People

Contributors

agersant avatar anderender avatar andy128k avatar bobbo avatar david-tn avatar dmfutcher avatar gbmor avatar gchicha avatar inputusername avatar skneko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rustfm-scrobble's Issues

Update README.md

  • Improve Usage documentation (quick code example, update authentication)
  • Look at the other sections, improve or expand where useful
  • Update Status section

Remove deprecated methods for v1.0

Scrobbler::authenticate is deprecated as of v0.9.1, in favour of using authenticate_with_password, authenticate_with_token or authenticate_with_session_key.

Version 1.0 feels like a good place to remove this old method.

Out of date Serde depdency

Currently depends on Serde 0.9. Serde 1.0.x is out, rustfm-scrobble should be upgraded. There's a big change to how to write custom Deserialisers (used in dto.rs), which makes this nontrivial.

Add Libre.fm support.

It would be good to see Libre.fm support for this library. As Libre.fm aims to mimic Last.fm's scrobbler API, I think one solution would be to allow a custom API endpoint URI to be specifed when Scrobbler::new() is specified; this could be used to specify the Libre.fm API base URI instead, but by default, it would use Last.fm's endpoint.

I'd be glad to have a crack at implementing a PR to implement the above proposed solution, if it'll work. I'd need to test it first..

Thoughts? 😄

Batch scrobbling support

Scrobbles can be submitted to the Last.fm API in batches (for example adding whole albums listened to in the past, or for migrating data to a new account). Depends on #2 to make sense.

Improve example code

Example code could be improved, particularly making it clearer how it works, adding docs/comments and probably moving Scrobble type generation out of the scrobble macro (unless we want to put that into the crate?)

Does not work behind a proxy

Hi, a user of rescrobbled ran into an issue where they couldn't authenticate with Last.fm behind a proxy. I think the problem is one of two things:

  1. ureq doesn't automatically pick up proxy configuration from the environment;
  2. ureq doesn't support HTTPS proxies.

I've managed to fix this by replacing ureq with attohttpc in my fork. attohttpc also has a tiny footprint and is based on cURL, so in general should be reliable.

I could create a PR, but I understand if you'd rather keep ureq and fix the issue in rustfm-scrobble instead.

Async Client

Investigate the potential of adding async support to the crate. Need to look at the async landscape in Rust & whether it makes sense to support it in-crate.

Add unit tests

There are no unit tests. At all. For 1.0 there should be. It's not a big crate so adding tests shoudln't be too painful. A CI pipeline to run them would be even better.

I can`t build the code

D:\prj\rustfm-scrobble (master -> origin)
λ cargo test
Compiling try-lock v0.2.2
Compiling crc32fast v1.2.0
Compiling regex-syntax v0.6.12
Compiling native-tls v0.2.3
Compiling percent-encoding v2.1.0
error: local variables in const fn are unstable
--> C:\Users\Андрей.cargo\registry\src\github.com-1ecc6299db9ec823\percent-encoding-2.1.0\lib.rs:72:13
|
72 | let chunk = self.mask[byte as usize / BITS_PER_CHUNK];
| ^^^^^

error: aborting due to previous error

error: Could not compile percent-encoding.
warning: build failed, waiting for other jobs to finish...
error: build failed

D:\prj\rustfm-scrobble (master -> origin)

Track metadata type

Refactor API to use a track data type to pass track data around, instead of using bare strings as params. This will allow easier implementation of #7 as well as tidy up the API.

Add Album metadata support

Currently only Track/Artist pair are used for Scrobbles. However, this leads to inadequate tracking of played albums on Last.fm. Last.fm does not automatically match a Track & Artist name to an album name, so album play counts are incorrect for plays scrobbled through this lib.

Scrobble server?

Hi,

thank you very much for implementing this! Is it, by any means, possible to reuse your code to implement a scrobble server? If yes, would you do that?

Would be awesome to build a scrobble server so I do not have to rely on last.fm services, for example!

Either way, thanks for developing this and I hope you continue to develop it! ❤️

Variable scrobble timestamp

Allow modification of the Scrobble timestamp. Right now the API assumes the scrobble is to be recorded at the instant of the API call. However, it should be possible for the library user to specify the scrobble time. This feature is useful on sites like https://vinylscrobbler.com/, where the music has been listened to in the past.

scrobble_batch fails if only one track is given

Scrobble succeeds but response parsing fails:

invalid type: map, expected a sequence at line 1 column 60

Easily fixed by checking if there's only one track to be scrobbled like in w4/dobble@69fb931 but might be surprising behaviour since it's a runtime failure. Caused thousands of extra scrobbles in my case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.