- Import jobs (import_jobs table): uploaded exports stored gzipped,
processed by `flask imports worker`, which claims jobs with
SKIP LOCKED, inserts in chunks with progress, supports cancelling and
re-queues jobs whose worker died
- CSV: lastfm-to-csv (no header) or any header-labelled CSV/TSV with
comma, semicolon or tab delimiters; several date formats and Unix
seconds/milliseconds
- JSON: pages of user.getRecentTracks (e.g. lastfm.ghan.nl), a single
recenttracks response, or a flat list; gzipped files accepted
- Last.fm API pull (only when LASTFM_API_KEY is set): pages through
user.getRecentTracks up to the job's creation time, rate limited,
with retries and resume
- Imports keep plays older than 14 days, skip empty/future ones and
dedupe against existing history
- Import metrics and pending/running job gauges
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Serves the app over HTTPS with a throwaway certificate and drives it
with pylast: web-auth sign-in, now playing, single and batch
scrobbles (non-ASCII too), recent tracks, top artists, play count,
and Last.fm error codes surfacing as pylast WSError
- README: architecture, running with compose, configuration, connecting
players, development workflow, monitoring and CI/CD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- API image (uv multi-stage, non-root, gunicorn, migrations on start,
health check) and UI image (nginx, CSP, config.js rendered from
API_BASE_URL); /healthz documented in OpenAPI
- docker compose runs db, api and ui; the "monitoring" profile adds
Prometheus, postgres-exporter and Grafana, all provisioned from files
- Grafana dashboards: API overview (RED), Last.fm API, Usage, Database
- Prometheus alert rules: API down, error rate, latency, auth failure
spike, ignored scrobbles, DB pool saturation, Postgres down
- Pool checkout gauge counts events (the pool's own counters lag the
checkin event); error ratios show 0 instead of "No data"
- Tests check dashboards and alerts only use metrics that exist
- scripts/generate_traffic.py drives realistic traffic for demos
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Statement latency by operation and connection-pool gauges via
SQLAlchemy events
- Users, active users (1h/24h/7d) and now-playing gauges computed at
scrape time, cached for 60s, from a NullPool engine that is safe in
the gunicorn master; exports nothing (not an error) if the DB is down
- gunicorn.conf.py: multiprocess metrics aggregated across workers and
served by the master on METRICS_PORT, stale files cleared at start,
dead workers marked
- Tests cover labels, in-flight gauge, DB metrics, the collector and a
real two-worker gunicorn aggregation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- /2.0/ and /api/auth/ are described from the Last.fm method registry:
method enum, per-method parameter tables, auth requirements, notes,
request schemas and XML example responses
- Readable tags (Auth, Apps, Sessions, Tokens, Stats, Last.fm)
- docs/openapi.json is exported with `flask openapi write`; tests fail
if it drifts from the code, if any route is undocumented, or if a UI
route is missing its bearer-auth security declaration
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Stats service shared by both APIs: recent scrobbles, top artists,
albums and tracks over Last.fm periods, per-day/week/month counts
(with empty days filled) and totals
- Case-insensitive grouping that displays the most common spelling
- user.getInfo, user.getRecentTracks (now playing first, from/to),
user.getTopArtists/Albums/Tracks with Last.fm paging attributes
- /api/v1/me: now-playing, recent, top/{artists,albums,tracks},
counts and summary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- track.scrobble: batches of up to 50 (array params or a single track),
Last.fm ignore rules (empty artist/track, too old, too new), duplicate
submissions accepted but stored once
- track.updateNowPlaying: upserted per user, expiring after the track's
duration; cleared when the same track is scrobbled
- Scrobble result, ignore reason, batch size, lag and now-playing metrics
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- auth.getMobileSession (username + password), auth.getToken and
auth.getSession with Last.fm error codes 4/14/15
- /api/auth/ redirects clients' approval links to the web UI's
approve page; /api/v1/tokens lets the UI show and approve a token
- Tokens expire after an hour, are single use and bound to their app
- The legacy md5 authToken form is deliberately unsupported (it needs
unsalted password hashes)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- flask-smorest API under /api/v1 with a uniform JSON error shape;
spec at /api/openapi.json, Swagger UI at /api/docs, ReDoc at /api/redoc
- Register/login/logout/me with hashed, expiring bearer tokens,
documented as an OpenAPI bearer security scheme
- API application and client-session management endpoints
- CORS restricted to the configured UI origin(s)
- Flask no longer serves static files: it is API-only
- Login and registration metrics
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- /2.0/ dispatcher backed by a method registry that declares each
method's params and signature/session requirements
- api_sig verification per the Last.fm auth spec
- XML (default) and Last.fm-style JSON rendering, including error shapes
and HTTP statuses per error code
- Last.fm request, error and auth-failure metrics with bounded labels
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Flask app factory with env-driven config (.env loaded at import)
- SQLAlchemy models: users, API apps, UI tokens, Last.fm auth tokens,
sessions, scrobbles (deduplicated) and now-playing
- Initial Alembic migration; CI checks migrations match the models
- Prometheus metric definitions, per-endpoint RED hooks with bounded
labels, and a standalone metrics server
- docker compose Postgres with a test database; CI test job runs
against a Postgres service container
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Rename the project to "scrobbler" with a src/ layout (hatchling)
- ruff + pytest dev tooling and a smoke test
- CI workflow (lint, test) that reports every run to ntfy via a
reusable composite action
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>