feat: base discovery on the whole mood collection
CI / chart (push) Successful in 3s
CI / test (push) Successful in 1m56s
CI / chart-push (push) Successful in 5s
CI / image (push) Successful in 3m34s

- seed from every artist (weighted by song count) and every album, not one track
- walk Deezer's graph: artist top tracks, related artists, album deep cuts
- score by artist frequency, collection album, catalog affinity and hint text
- penalise repeated artists so a 30-slot mood spans artists, not one
- refresh the pool when a song is added instead of waiting for refreshHours
- skip discovery for a mood with no hint, genres or songs
- extend tests and the smoke test with the artist graph
This commit is contained in:
TapTap committed 2026-11-17 10:37:47 +00:00
1 parent a78d359d0c
commit 62bcefad20
13 files changed
+911 -72

No files matched your search

+70 -2
View File
@@ -114,6 +114,37 @@ TRACKS = {
"artist": {"name": "DJ"}, "album": {"title": "Long"}},
}
# Only resolvable by URL, so adding it cannot race a recommendation download.
EXTRA_TRACKS = {
"55555555": {"id": 55555555, "title": "One More Time", "duration": 320,
"readable": True, "artist": {"name": "Daft Punk"},
"album": {"title": "Discovery"}},
}
# Artist graph: the mood holds Daft Punk, so discovery walks to a related act
# and to a deep cut of an album already in the collection.
ARTISTS = {
"27": {"id": 27, "name": "Daft Punk"},
"99": {"id": 99, "name": "Daft Punk Tribute"},
}
TOP_TRACKS = {
"27": [TRACKS["77777777"]],
"99": [{"id": 88888888, "title": "Robot Rock", "duration": 305,
"readable": True, "artist": {"name": "Daft Punk Tribute"},
"album": {"title": "Tribute"}}],
}
RELATED = {"27": [ARTISTS["99"]]}
ALBUMS = {"5": {"id": 5, "title": "Random Access Memories",
"artist": {"name": "Daft Punk"}}}
ALBUM_TRACKS = {
"5": [{"id": 99999999, "title": "Contact", "duration": 382,
"readable": True, "artist": {"name": "Daft Punk"},
"album": {"title": "Random Access Memories"}}],
}
STATS = {"artist_search": 0, "artist_top": 0, "artist_related": 0,
"album_search": 0, "album_tracks": 0}
class Handler(BaseHTTPRequestHandler):
def log_message(self, *args):
pass
@@ -128,10 +159,28 @@ class Handler(BaseHTTPRequestHandler):
def do_GET(self):
parsed = urllib.parse.urlparse(self.path)
parts = [p for p in parsed.path.split("/") if p]
if parsed.path == "/search/track":
self.reply({"data": list(TRACKS.values())})
elif parsed.path == "/search/artist":
STATS["artist_search"] += 1
self.reply({"data": list(ARTISTS.values())})
elif parsed.path == "/search/album":
STATS["album_search"] += 1
self.reply({"data": list(ALBUMS.values())})
elif parsed.path == "/stats":
self.reply(STATS)
elif len(parts) == 3 and parts[0] == "artist" and parts[2] == "top":
STATS["artist_top"] += 1
self.reply({"data": TOP_TRACKS.get(parts[1], [])})
elif len(parts) == 3 and parts[0] == "artist" and parts[2] == "related":
STATS["artist_related"] += 1
self.reply({"data": RELATED.get(parts[1], [])})
elif len(parts) == 3 and parts[0] == "album" and parts[2] == "tracks":
STATS["album_tracks"] += 1
self.reply({"data": ALBUM_TRACKS.get(parts[1], [])})
elif parsed.path.startswith("/track/"):
track = TRACKS.get(parsed.path.rsplit("/", 1)[-1])
track = TRACKS.get(parts[-1]) or EXTRA_TRACKS.get(parts[-1])
if track is None:
self.reply({"error": {"type": "DataException", "message": "no track"}}, 404)
else:
@@ -160,6 +209,7 @@ case "$id" in
67238732) title="Instant Crush"; artist="Daft Punk"; album="Random Access Memories" ;;
66609426) title="Get Lucky"; artist="Daft Punk"; album="Get Lucky" ;;
77777777) title="Around the World"; artist="Daft Punk"; album="Homework" ;;
55555555) title="One More Time"; artist="Daft Punk"; album="Discovery" ;;
*) title="Deezer Track $id"; artist="Deezer Artist"; album="Deezer Album" ;;
esac
ffmpeg -hide_banner -loglevel error -y \
@@ -333,8 +383,26 @@ expect "add a Deezer track" "202" "POST" "/moods/$DZ_MOOD/songs" \
wait_for 90 "Deezer download attaches to the mood" 'd["mood"]["songCount"] >= 1' "/moods/$DZ_MOOD"
wait_for 90 "Deezer recommendations download" 'd["mood"]["recommendationReady"] >= 1' "/moods/$DZ_MOOD"
expect "add a Deezer URL" "202" "POST" "/moods/$DZ_MOOD/songs" \
'{"url":"https://www.deezer.com/track/66609426"}'
'{"url":"https://www.deezer.com/track/55555555"}'
wait_for 90 "Deezer URL attaches to the mood" 'd["mood"]["songCount"] >= 2' "/moods/$DZ_MOOD"
# The collection changed, so the next top-up re-runs discovery against the
# artist graph instead of waiting for the refresh window.
DZ_STATS=""
for _ in $(seq 1 90); do
DZ_STATS="$(curl -sf "http://127.0.0.1:${DZ_API_PORT}/stats" || true)"
if [[ -n "$DZ_STATS" ]] && printf '%s' "$DZ_STATS" | python3 -c '
import json, sys
d = json.load(sys.stdin)
sys.exit(0 if d["artist_related"] > 0 and d["album_tracks"] > 0 else 1)
'; then
break
fi
sleep 1
done
expect_eq "Deezer discovery walks the artist graph" "true" \
"$(printf '%s' "$DZ_STATS" | python3 -c 'import json,sys;d=json.load(sys.stdin);print(str(d["artist_related"] > 0 and d["artist_top"] > 0).lower())')"
expect_eq "Deezer discovery reads album deep cuts" "true" \
"$(printf '%s' "$DZ_STATS" | python3 -c 'import json,sys;d=json.load(sys.stdin);print(str(d["album_tracks"] > 0).lower())')"
if [[ -f "$MEDIA/deezer-67238732/Instant Crush.mp3" ]]; then
pass "Deezer media path"
else