Initial commit: LastRecc discovery feed and weekly engine

This commit is contained in:
Joren committed 2026-11-23 12:40:14 +01:00
commit 70287e6310
40 files changed
+6972

No files matched your search

+154
View File
@@ -0,0 +1,154 @@
# LastRecc
A personal, Last.fm-powered discovery feed for [Navidrome](https://www.navidrome.org/).
LastRecc reads your Navidrome scrobble history, finds the artists and tracks you actually played recently, asks Last.fm for similar music, filters out what you've already heard, matches the rest against your library, and serves a card feed you can play from the browser.
```
Navidrome scrobbles ──► top artists + tracks ──► Last.fm similarity
│
filter + rank + diversify
│
match to library ──► playable cards
```
A separate **Go weekly engine** in [`lastrecc-go/`](lastrecc-go/) turns the same
kind of recommendations into a rolling Navidrome playlist, downloading missing
albums through `streamrip-go`/Qobuz and adding only the most popular tracks from
each album. See [lastrecc-go/README.md](lastrecc-go/README.md).
## Features
- Rolling 7 / 14 / 30 day window, configurable
- Recency-weighted seeds so this week matters more than last month
- Similar artists **and** similar tracks from Last.fm
- Filters out anything already in your Navidrome scrobble history
- Adds **unplayed albums** from artists you already listen to
- Caps repeats per artist and album for a more varied feed
- Best-effort matching back to your Navidrome library
- Cover art and audio streamed through the local server (credentials never reach the browser)
- Zero third-party dependencies — Python standard library only
## Quick start
```bash
cp .env.example .env
# edit .env with your Navidrome and Last.fm credentials
python -m lastrecc build # build the feed
python -m lastrecc serve # http://127.0.0.1:8787
```
With `make`:
```bash
make build
make serve
make test
make weekly-plan # dry-run: what the weekly engine would fetch / playlist
make weekly # fetch missing albums + replace the rolling playlist
```
Or warm the cache and serve in one step:
```bash
python -m lastrecc serve --warm
```
## Configuration
| Variable | Required | Description |
|---|---|---|
| `NAVIDROME_URL` | yes | Base URL, e.g. `https://music.example.com` |
| `NAVIDROME_USER` | yes | Navidrome username |
| `NAVIDROME_PASSWORD` | yes | Navidrome password |
| `NAVIDROME_BASIC_USER` | no | HTTP basic auth user, if a reverse proxy adds one |
| `NAVIDROME_BASIC_PASSWORD` | no | HTTP basic auth password |
| `LASTFM_API_KEY` | yes | Last.fm API key |
| `DAYS` | no | Rolling window, default `7` |
| `FEED_SIZE` | no | Number of cards, default `36` |
| `SEED_ARTISTS` | no | Artist seeds, default `10` |
| `SEED_TRACKS` | no | Track seeds, default `10` |
| `CACHE_DIR` | no | Cache directory, default `.cache` |
| `LASTFM_RATE` | no | Last.fm requests/second, default `4` |
| `NAVIDROME_RATE` | no | Navidrome requests/second, default `8` |
The app uses two Navidrome APIs:
- **native API** for login and `/api/scrobble` history
- **Subsonic API** for `search3`, cover art, and streaming
## CLI
```bash
python -m lastrecc build [--days 7] [--refresh] [--json]
python -m lastrecc serve [--days 7] [--host 127.0.0.1] [--port 8787] [--warm]
python -m lastrecc stats
```
`build --refresh` ignores the scrobble, Last.fm, and feed caches. `serve` rebuilds lazily when the feed cache is older than 15 minutes.
## How ranking works
1. Each play gets an exponential recency weight (default half-life: 14 days).
2. Top artists and tracks become seeds.
3. `artist.getSimilar` → top tracks, and `track.getSimilar` → similar tracks.
4. Candidates are dropped if their normalized artist/title already appears in your scrobble history.
5. Score = similarity × seed weight × popularity × novelty.
6. The shortlist is diversified (max 2 per artist, 1 per album).
7. Each candidate is enriched with `track.getInfo`, then matched to your library with `search3`.
## Caching
Caches live in `.cache/`:
| Cache | TTL |
|---|---|
| Feed | 15 minutes |
| Navidrome scrobbles | 10 minutes |
| Last.fm responses | 14 days |
| Navidrome song metadata | persistent |
| Cover art | 7 days |
Last.fm asks applications to cache and be reasonable with request rates. This project uses a 4 req/s limiter.
## Project layout
```
lastrecc/
config.py .env loading and settings
navidrome.py native + Subsonic API client
lastfm.py Last.fm client with disk cache
recommend.py seeds, candidates, ranking, enrichment
server.py stdlib HTTP server, API, cover/stream proxy
text.py Unicode-safe normalization and fuzzy matching
web/
index.html feed UI
app.js rendering, filters, player
style.css styling
tests/
```
## Notes and limitations
- Last.fm's API is free for **non-commercial** use. For commercial use, contact `partners@last.fm`.
- Last.fm does not expose its own homepage recommendation feed; this project builds an approximation from public similarity endpoints.
- Navidrome's native scrobble history is per user. The credentials in `.env` determine whose feed is built.
- The app binds to `127.0.0.1` by default. If you expose it, put it behind auth — it proxies your music library.
- Cover art rights belong to the respective owners.
## Troubleshooting
- **Login fails** — check `NAVIDROME_USER` / `NAVIDROME_PASSWORD`, and `NAVIDROME_BASIC_*` if your reverse proxy adds basic auth.
- **No covers or playback** — covers and streams go through the app's proxy; make sure the Navidrome credentials can access the library.
- **Stale recommendations** — click **Refresh**, or delete `.cache/feed.json` and `.cache/scrobbles.json`. Delete `.cache/lastfm` to bypass the 14-day Last.fm cache after changing seed settings.
- **Last.fm rate limit** — lower `LASTFM_RATE` or wait a minute. The app already limits itself to 4 requests/second.
- **Port in use** — `python -m lastrecc serve --port 8788`.
## Tests
```bash
python -m unittest discover -s tests -v
```