Weekly summaries (Monday 09:00 in each user's time zone) and milestones, followers-only by default: a core stats-window addition, idempotent posts keyed per week/threshold, Note/Create/Delete with visibility addressing, fan-out to followers' shared inboxes, no retroactive posts (baselines on enabling sharing and after imports), deletable posts and deletion when sharing is switched off, a paged outbox, API/UI, metrics and an alert, and interop checks with GoToSocial. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
Scrobbler
A self-hosted music scrobbling service. It speaks the Last.fm (Audioscrobbler 2.0) API, so players and scrobblers that let you set a custom Last.fm server can use it unchanged. It also has a web UI for your listening history.
players / scrobblers ──► API /2.0/ Last.fm-compatible
web UI (static files) ──► API /api/v1/ JSON API for the UI
API ──► PostgreSQL
Prometheus ◄── API :9100/metrics, postgres-exporter ──► Grafana
- API (
src/scrobbler/): Flask under gunicorn. It is API-only and serves no pages. - Web UI (
frontend/): plain HTML, CSS and JavaScript with no build step. Host it anywhere static files can be served. - Docs: OpenAPI at
/api/openapi.json, Swagger UI at/api/docsand ReDoc at/api/redoc. A copy of the spec is committed atdocs/openapi.json. - Worker:
flask workerruns background work, such as importing Last.fm history from export files or straight from Last.fm. - Monitoring: Prometheus metrics, four provisioned Grafana dashboards, and alert rules.
Run it
cp .env.example .env # then set SECRET_KEY and POSTGRES_PASSWORD
docker compose up -d # db, api (:5050), worker, ui (:8080)
docker compose --profile monitoring up -d # + Prometheus (:9090), Grafana (:3000)
Open http://localhost:8080, create an account, then go to Apps and create an app for each player.
To run the published images instead of building them locally:
SCROBBLER_IMAGE_TAG=main docker compose up -d --no-build
The images are pkgs.daubney.dev/scrobbler/scrobbler-api and pkgs.daubney.dev/scrobbler/scrobbler-ui.
Configuration
| Variable | Used by | Default | Purpose |
|---|---|---|---|
DATABASE_URL |
api | local Postgres | SQLAlchemy URL (postgresql+psycopg://…) |
SECRET_KEY |
api | dev-insecure-secret |
Flask secret |
CORS_ORIGINS |
api | http://localhost:8080 |
Comma-separated UI origins allowed to call /api/v1 |
UI_BASE_URL |
api | http://localhost:8080 |
Where /api/auth/ sends users to approve desktop sign-ins |
OPENAPI_DOCS_ENABLED |
api | 1 |
Set to 0 to hide /api/docs and /api/redoc |
METRICS_PORT |
api | 9100 |
Prometheus metrics port (keep it off the public network) |
WEB_CONCURRENCY |
api | 2 |
gunicorn workers |
RUN_MIGRATIONS |
api image | 1 |
Apply database migrations on start |
LASTFM_API_KEY |
api, worker | (unset) | Enables importing straight from Last.fm (get a key) |
IMPORT_MAX_BYTES |
api | 200 MB | Largest export file accepted |
WORKER_METRICS_PORT |
worker | 9101 |
The worker's Prometheus metrics port (IMPORT_WORKER_METRICS_PORT still works) |
API_BASE_URL |
ui image | http://localhost:5050 |
API location, written into config.js and the CSP |
In docker compose the host ports are set with DB_PORT, API_PORT, UI_PORT, PROMETHEUS_PORT and GRAFANA_PORT.
Connecting a player
In the player's scrobbling settings, choose a custom or self-hosted Last.fm server and enter:
- API URL:
https://your-host/2.0/ - API key and shared secret: from an app on the Apps page
- Username and password: your Scrobbler account
Two ways of signing in are supported:
- Mobile:
auth.getMobileSessionwith a username and password, sent as a POST body over HTTPS. - Desktop:
auth.getToken, then the user approves at/api/auth/(which redirects to the web UI), thenauth.getSession.
The legacy authToken = md5(username + md5(password)) form is not supported, because checking it would mean storing unsalted password hashes. pylast's password_hash option uses that form. With pylast, use SessionKeyGenerator (the desktop flow) instead.
Supported methods:
auth.getMobileSession,auth.getToken,auth.getSessiontrack.scrobble(up to 50 per request),track.updateNowPlayinguser.getInfo,user.getRecentTracks,user.getTopArtists,user.getTopAlbums,user.getTopTracks
/api/docs lists the parameters, rules and example responses for each method.
Scrobbles are ignored (not rejected) if the artist or track is empty, or if the timestamp is more than 14 days old or more than 5 minutes in the future. Sending the same scrobble again is accepted and stored once, so client retries are safe.
Importing Last.fm history
Open Import in the web UI. You can import from:
- An export file:
- CSV from lastfm-to-csv, with no header row and artist, album, track and date columns.
- Any CSV or TSV with a header row naming artist, track and a date or Unix-time column. Comma, semicolon and tab delimiters all work.
- A JSON export of
user.getRecentTrackspages (such as lastfm.ghan.nl's), a singlerecenttracksresponse, or a flat list of tracks. - Files can be gzipped.
- Last.fm directly: enter a Last.fm username and the worker pages through that account's public history. This option only appears when the server has
LASTFM_API_KEYset.
Imports run in the background in the worker service. The page shows progress, and an import can be cancelled.
Unlike live scrobbles, imports keep plays of any age. They still skip rows with no artist or track, and plays dated in the future. Plays already in your history are skipped, so importing again is safe.
Sharing on the fediverse (in development)
Users can make their profile findable from Mastodon and other fediverse apps as @name@<your UI host>, and be followed:
- Follows are accepted automatically, or wait for approval if the user turns that on.
- The Followers page lists requests, followers and blocked accounts, with approve, decline, remove, block and unblock.
Posts (weekly summaries, milestones, now playing) are still being built; see docs/design/activitypub.md. Federation is tested in CI against a real GoToSocial server (scripts/interop/run.sh).
It's off unless the server enables it, and then off for each user until they switch it on under Sharing. To enable it:
- Set these on the API and worker:
FEDERATION_ENABLED=1FEDERATION_DOMAIN: the UI's host, e.g.scrobble.exampleFEDERATION_BASE_URL: the UI's origin, e.g.https://scrobble.exampleFEDERATION_KEY_SECRET: 32 or more random characters
- Give the UI container
API_INTERNAL_URL(compose setshttp://api:8000). It then forwards these paths to the API:/.well-known/webfinger,/.well-known/nodeinfo,/.well-known/host-meta,/nodeinfo/,/users/,/inboxand/actor. - Serve the UI over HTTPS on that domain. Other servers only talk to HTTPS.
Handles and actor URLs can't change once anyone follows a user, so choose the domain carefully.
FEDERATION_KEY_SECRET encrypts each user's signing key. Back it up, and never change it: losing it means users' keys can't be read, and followers would have to follow again.
Optional settings:
FEDERATION_BLOCKED_DOMAINS: comma-separated domains, including subdomains, whose deliveries and follows are refused.FEDERATION_DELIVERY_CONCURRENCY: parallel outgoing deliveries per worker (default 4).FEDERATION_SIGNATURE_SCHEMES: the signing order (defaultdraft-cavage,rfc9421).
The worker must be running: it processes incoming activities and delivers outgoing ones.
Develop
docker compose up -d db # Postgres with a scrobbler_test database
uv sync
uv run flask --app scrobbler db upgrade heads
uv run flask --app scrobbler run --port 5050 # API (port 5000 is taken by AirPlay on macOS)
python -m http.server 8080 -d frontend # UI
uv run flask --app scrobbler worker # background work (imports, …)
uv run pytest # needs TEST_DATABASE_URL (see .env.example)
uv run ruff check && uv run ruff format --check
- Migrations come in two branches,
coreandfederation. After changing core models, runuv run flask --app scrobbler db migrate --head core@head -m "…"; federation tables use--head federation@head(seesrc/scrobbler/federation/README.md). Apply them withdb upgrade heads. CI fails if the models and migrations disagree. - API docs: after changing an endpoint, run
uv run python -m scrobbler.openapi.export docs/openapi.json. It documents the API with every optional module (such as federation) switched on. A test fails if the committed spec is stale. Every route has to appear in the spec, and every UI route has to declare bearer auth. - Demo traffic:
uv run python scripts/generate_traffic.py --minutes 5sends a realistic mix of scrobbles and errors, so the dashboards have something to show.
The test suite includes an end-to-end run with pylast over HTTPS and a real two-worker gunicorn run, which checks that metrics aggregate across workers.
Monitoring
The API serves Prometheus metrics on METRICS_PORT, summed across gunicorn workers. All series are prefixed scrobbler_:
- HTTP: request rate, errors and latency per endpoint
- Last.fm: calls, errors by Last.fm error code, and authentication failures by reason
- Scrobbles: accepted, duplicate and ignored (with the reason), batch size, and how late scrobbles arrive
- Database: query latency and connection-pool use
- Users: registered, active, and listening now (computed from the database and cached for 60s)
Labels never contain users, keys or track names.
With the monitoring profile, Grafana (admin password GRAFANA_ADMIN_PASSWORD) has a Scrobbler folder with four dashboards:
- API overview
- Last.fm API
- Usage
- Database
Alert rules live in deploy/prometheus/alerts.yml:
- API down
- import worker down, or imports left waiting
- 5xx ratio
- p95 latency
- authentication-failure spike
- ignored-scrobble ratio
- database pool saturated
- Postgres down
They're evaluated by Prometheus and appear in Grafana. Nothing routes them anywhere yet; that needs Alertmanager.
Tests check that every metric a dashboard or alert uses actually exists.
CI/CD (Gitea Actions)
Everything runs from .gitea/workflows/ci.yml:
- Every push and PR:
- lint
- the migrations check
- tests against Postgres
promtoolchecks of the Prometheus config and alert rules
- Pushes to
mainandv*tags, once every check has passed:- both images are pushed to the ProGet
scrobblerDocker feed.mainbuilds are taggedmainandsha-<commit>; tags are tagged<version>,latestandsha-<commit>. - the OpenAPI spec, dashboards and Prometheus config are uploaded to the
scrobbler-assetsfeed underscrobbler/<version>/orscrobbler/main/.
- both images are pushed to the ProGet
v*tags also publish the wheel and sdist to thescrobbler-pythonPyPI feed, as thescrobbydistribution. The import name isscrobbler. (scrobbleron public PyPI is an unrelated project.)- Every run is posted to the
ScrobblingServicetopic on notify.daubney.dev.
The workflow needs these repository secrets and variables:
- Secrets:
PKGS_USER,PKGS_PASSWORD,PKGS_API_KEY,NTFY_USER,NTFY_PASSWORD - Variables:
PKGS_HOST,PKGS_DOCKER_FEED,PKGS_PYPI_FEED,PKGS_ASSET_FEED,NTFY_URL,NTFY_TOPIC
To release, tag vX.Y.Z on main and push the tag. The tag sets the package and image version.
Licence
BSD 3-Clause; see LICENSE. The fonts vendored in frontend/fonts/ are under the SIL Open Font License 1.1.