Search

Lib.rs

› Multimedia › Audio
#youtube-music #spotify #lastfm #cli

bin+lib music-stats

Saves your music listening history to a GitHub Gist and aggregates plays from Last.fm and YouTube Music

Owned by totallynotdavid.

  • Install
  • API reference
  • GitHub repo (totallynotdavid)

2 releases

Uses new Rust 2024

0.2.1 Jan 8, 2026
0.2.0 Jan 7, 2026

#1306 in Audio

MIT license

34KB
828 lines

[pkg]: music stats archive

Crates.io docs.rs codecov

Saves your music listening history to a GitHub Gist. Supports Last.fm (which aggregates plays from Spotify, Tidal, Deezer, and other services) and YouTube Music directly.

Before you start, you will need:

  • A public GitHub Gist created at https://gist.github.com (copy the Gist ID from the URL)
  • A GitHub personal access token from https://github.com/settings/personal-access-tokens/new with the Gists permission
  • At least one provider:
    • Last.fm API key from https://www.last.fm/api and your username
    • YouTube Music cookie from your browser

Setup

Create a repository from the template at https://github.com/new?template_name=music-stats&template_owner=totallynotdavid.

Open the repository's Actions secrets settings at https://github.com/[username]/[repo]/settings/secrets/actions and add:

  • GIST_ID
  • GITHUB_TOKEN
  • CODECOV_TOKEN (optional — required for private repos to upload coverage)
  • At least one provider:
    • LASTFM_API_KEY and LASTFM_USERNAME
    • YOUTUBE_COOKIE

The action runs on the schedule defined in .github/workflows/gist.yml. Edit the cron expression to change the update frequency, or trigger it manually from the Actions tab.

Optional configuration:

  • DAYS: number of days to fetch (default: 7)
  • TOP_N: number of top tracks to show (default: 5)

Manual usage

Install the binary with cargo:

cargo install --git https://github.com/totallynotdavid/music-stats

Set the required environment variables and run:

export GIST_ID=
export GITHUB_TOKEN=
export LASTFM_API_KEY=       # optional if using YouTube
export LASTFM_USERNAME=      # optional if using YouTube
export YOUTUBE_COOKIE=       # optional if using Last.fm
music-stats

Optional configuration:

export DAYS=7                # number of days to fetch (default: 7)
export TOP_N=5               # number of top tracks to show (default: 5)

Publishing

This crate supports Trusted Publishing to crates.io using GitHub Actions (OIDC). The repository includes a release workflow that publishes tagged releases (e.g., v1.0.0) to crates.io — see .github/workflows/release.yml.

Note: the initial publish requires a crates.io API token (use cargo publish --token or set CARGO_REGISTRY_TOKEN as a secret); after configuring Trusted Publishing in your crate's settings, subsequent publishes can use the OIDC-based workflow.

Local development

On WSL, install the required system dependencies:

sudo apt update
sudo apt install gcc pkg-config libssl-dev # gcc (around 200 mb) / openssl (around 20 mb)

Clone the repository and build:

git clone https://github.com/totallynotdavid/music-stats
cd music-stats
cargo build

Copy .env.example to .env and fill in your credentials.

Run the development build with cargo run, or build a release binary with cargo build --release.

Dependencies

~20–37MB
~459K SLoC

  • anyhow
  • chrono+serde
  • dotenv
  • regex
  • reqwest 0.13.1+json
  • serde+derive
  • serde_json
  • sha1
  • tokio 1.48+macros+rt-multi-thread+time
  • tracing
  • tracing-subscriber+env-filter
  • unicode-width 0.2.2
See also: termusic, rustypipe, youtui, rustfm-scrobble-proxy, apple-to-last-fm, spotify_player, rspotify, librespot-metadata, spotatui, librespot-audio, krustens

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.