feat: add Deezer as the default download source
CI / chart (push) Successful in 3s
CI / test (push) Successful in 2m23s
CI / chart-push (push) Successful in 5s
CI / image (push) Successful in 3m50s

- V9 adds source/external_id to songs, moods, recommendations and jobs
- Deezer public catalog for search, related album covers and metadata
- streamrip downloader configured with DEEZER_ARL, 128/320 MP3
- per-mood source selector; switching clears and refills recommendations
- keep YouTube Music as a full second catalog and downloader
- media layout <source>-<externalId>, legacy YouTube folders still read
- Docker/streamrip install, chart ARL secret, docs and dual-source smoke test
This commit is contained in:
TapTap committed 2026-11-17 07:32:34 +00:00
1 parent 81a47f4cd2
commit 141698282d
43 files changed
+2072 -605

No files matched your search

+126 -11
View File
@@ -2,9 +2,9 @@
#
# End-to-end smoke test for the mood-first API.
#
# Seeds a tiny media store, starts the server with a fake `yt-dlp` on PATH, and
# exercises auth, search, moods, downloads, recommendations, radio sessions,
# streaming and covers.
# Seeds a tiny media store, starts the server with fake `yt-dlp`/`rip` binaries
# and a fake Deezer API, and exercises both sources: auth, search, moods,
# downloads, recommendations, radio sessions, streaming and covers.
#
# Requirements: ffmpeg, sqlite3, curl, python3, java, bash.
# Usage: scripts/smoke.sh [work-dir]
@@ -15,6 +15,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
GRADLE="${GRADLE:-./gradlew}"
WORK="${1:-$(mktemp -d "${TMPDIR:-/tmp}/audiomanager-smoke.XXXXXX")}"
PORT="${SMOKE_PORT:-18099}"
DZ_API_PORT="${SMOKE_DEEZER_PORT:-18098}"
USER="smoke"
PASS="smoke-pass"
BASE="http://127.0.0.1:${PORT}"
@@ -92,6 +93,83 @@ printf '%s\n' "$dir/$id.mp3"
FAKE
chmod +x "$WORK/bin/yt-dlp"
# Deterministic stand-in for the Deezer public API.
cat > "$WORK/deezer_api.py" <<'PY'
import json
import sys
import urllib.parse
from http.server import BaseHTTPRequestHandler, HTTPServer
TRACKS = {
"67238732": {"id": 67238732, "title": "Instant Crush", "duration": 337,
"readable": True, "artist": {"name": "Daft Punk"},
"album": {"title": "Random Access Memories"}},
"66609426": {"id": 66609426, "title": "Get Lucky", "duration": 248,
"readable": True, "artist": {"name": "Daft Punk"},
"album": {"title": "Get Lucky"}},
"77777777": {"id": 77777777, "title": "Around the World", "duration": 430,
"readable": True, "artist": {"name": "Daft Punk"},
"album": {"title": "Homework"}},
"1": {"id": 1, "title": "Too Long", "duration": 900, "readable": True,
"artist": {"name": "DJ"}, "album": {"title": "Long"}},
}
class Handler(BaseHTTPRequestHandler):
def log_message(self, *args):
pass
def reply(self, body, status=200):
data = json.dumps(body).encode()
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(data)))
self.end_headers()
self.wfile.write(data)
def do_GET(self):
parsed = urllib.parse.urlparse(self.path)
if parsed.path == "/search/track":
self.reply({"data": list(TRACKS.values())})
elif parsed.path.startswith("/track/"):
track = TRACKS.get(parsed.path.rsplit("/", 1)[-1])
if track is None:
self.reply({"error": {"type": "DataException", "message": "no track"}}, 404)
else:
self.reply(track)
else:
self.reply({"error": {"type": "DataException", "message": "not found"}}, 404)
HTTPServer(("127.0.0.1", int(sys.argv[1])), Handler).serve_forever()
PY
# Deterministic stand-in for streamrip. It ignores the ARL and writes one MP3
# per track, exactly like the real downloader from the server's perspective.
cat > "$WORK/bin/rip" <<'FAKE'
#!/usr/bin/env bash
set -euo pipefail
outdir=""
prev=""
for arg in "$@"; do
if [[ "$prev" == "-f" ]]; then outdir="$arg"; fi
prev="$arg"
done
url="${*: -1}"
id="${url##*/}"
mkdir -p "$outdir"
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" ;;
*) title="Deezer Track $id"; artist="Deezer Artist"; album="Deezer Album" ;;
esac
ffmpeg -hide_banner -loglevel error -y \
-f lavfi -i "sine=frequency=800:duration=1" \
-c:a libmp3lame -b:a 128k -id3v2_version 3 \
-metadata title="$title" -metadata artist="$artist" -metadata album="$album" \
"$outdir/$title.mp3"
FAKE
chmod +x "$WORK/bin/rip"
cat > "$WORK/users.yaml" <<EOF
users:
- name: $USER
@@ -108,10 +186,19 @@ if [[ -z "$JAR" ]]; then
exit 1
fi
python3 "$WORK/deezer_api.py" "$DZ_API_PORT" > "$WORK/deezer_api.log" 2>&1 &
DZ_API_PID=$!
for _ in $(seq 1 30); do
curl -sf "http://127.0.0.1:${DZ_API_PORT}/track/67238732" >/dev/null 2>&1 && break
sleep 1
done
PATH="$WORK/bin:$PATH" DATA_DIR="$WORK/data" USERS_FILE="$WORK/users.yaml" PORT="$PORT" \
DEEZER_API_BASE="http://127.0.0.1:${DZ_API_PORT}" DEEZER_ARL="fake-arl" \
STREAMRIP_PATH="$WORK/bin/rip" DEFAULT_SOURCE="deezer" \
java -jar "$JAR" > "$WORK/server.log" 2>&1 &
SERVER_PID=$!
trap 'kill $SERVER_PID 2>/dev/null || true' EXIT
trap 'kill $SERVER_PID $DZ_API_PID 2>/dev/null || true' EXIT
log "Waiting for the server and the startup scan..."
SONGS=0
@@ -129,8 +216,8 @@ if [[ "${SONGS:-0}" -lt 2 ]]; then
exit 1
fi
SEED_ONE="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where video_id='vid-seed-1'")"
SEED_TWO="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where video_id='vid-seed-2'")"
SEED_ONE="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where source='youtube' and external_id='vid-seed-1'")"
SEED_TWO="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where source='youtube' and external_id='vid-seed-2'")"
log "Indexed: seed1=$SEED_ONE seed2=$SEED_TWO"
# api <method> <path> [json-body] [token-override]
@@ -203,14 +290,19 @@ expect_eq "me name" "$USER" "$(printf '%s' "$HTTP_BODY" | json_field '["name"]')
log ""
log "Search"
expect "youtube search" "200" "GET" "/search?q=anything"
expect "youtube search" "200" "GET" "/search?q=anything&source=youtube"
expect_eq "search hides long and short tracks" "3" "$(printf '%s' "$HTTP_BODY" | json_field '["results"].__len__()')"
expect_eq "search marks the seeded video" "true" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print(str(any(r["videoId"]=="vid-seed-1" and r["downloaded"] for r in json.load(sys.stdin)["results"])).lower())')"
expect_eq "search marks the seeded video" "true" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print(str(any(r["externalId"]=="vid-seed-1" and r["downloaded"] for r in json.load(sys.stdin)["results"])).lower())')"
expect "deezer search" "200" "GET" "/search?q=daft&source=deezer"
expect_eq "deezer search hides long tracks" "3" "$(printf '%s' "$HTTP_BODY" | json_field '["results"].__len__()')"
expect_eq "deezer search source" "deezer" "$(printf '%s' "$HTTP_BODY" | json_field '["results"][0]["source"]')"
expect "default search uses deezer" "200" "GET" "/search?q=daft"
expect_eq "default search source" "deezer" "$(printf '%s' "$HTTP_BODY" | json_field '["results"][0]["source"]')"
log ""
log "Moods"
expect "create mood" "201" "POST" "/moods" \
'{"name":"Smoke Mood","genres":["Rock"],"collectionPercent":50,"recommendationCount":2}'
'{"name":"Smoke Mood","source":"youtube","genres":["Rock"],"collectionPercent":50,"recommendationCount":2}'
MOOD_ID="$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["id"]' 2>/dev/null || true)"
if [[ -n "$MOOD_ID" ]]; then pass "mood id"; else fail "mood id" "${HTTP_BODY:0:200}"; fi
expect "empty mood cannot start a session" "400" "POST" "/moods/$MOOD_ID/sessions" '{"limit":5}'
@@ -229,13 +321,36 @@ expect "mood preview" "200" "GET" "/moods/$MOOD_ID/preview?limit=10"
expect_eq "preview is not empty" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if json.load(sys.stdin)["songs"] else "no")')"
expect "remove a song" "204" "DELETE" "/moods/$MOOD_ID/songs/$SEED_TWO"
log ""
log "Deezer source"
expect "create Deezer mood" "201" "POST" "/moods" \
'{"name":"Deezer Mood","source":"deezer","query":"daft punk","recommendationCount":2}'
DZ_MOOD="$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["id"]' 2>/dev/null || true)"
if [[ -n "$DZ_MOOD" ]]; then pass "Deezer mood id"; else fail "Deezer mood id" "${HTTP_BODY:0:200}"; fi
expect_eq "Deezer mood source" "deezer" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["source"]')"
expect "add a Deezer track" "202" "POST" "/moods/$DZ_MOOD/songs" \
'{"source":"deezer","externalId":"67238732"}'
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"}'
wait_for 90 "Deezer URL attaches to the mood" 'd["mood"]["songCount"] >= 2' "/moods/$DZ_MOOD"
if [[ -f "$MEDIA/deezer-67238732/Instant Crush.mp3" ]]; then
pass "Deezer media path"
else
fail "Deezer media path" "missing $MEDIA/deezer-67238732/Instant Crush.mp3"
fi
expect "Deezer session" "201" "POST" "/moods/$DZ_MOOD/sessions" '{"limit":5}'
DZ_SESSION="$(printf '%s' "$HTTP_BODY" | json_field '["id"]' 2>/dev/null || true)"
if [[ -n "$DZ_SESSION" ]]; then pass "Deezer session id"; else fail "Deezer session id" "${HTTP_BODY:0:200}"; fi
log ""
log "Recommendations"
expect "refresh recommendations" "200" "POST" "/moods/$MOOD_ID/recommendations/refresh"
REC_VIDEO="$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;r=json.load(sys.stdin)["recommendations"];print(r[0]["videoId"] if r else "")')"
REC_VIDEO="$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;r=json.load(sys.stdin)["recommendations"];print(r[0]["externalId"] if r else "")')"
wait_for 90 "recommendations download" 'd["mood"]["recommendationReady"] >= 1' "/moods/$MOOD_ID"
expect "add a recommendation" "200" "POST" "/moods/$MOOD_ID/recommendations/$REC_VIDEO/add"
SECOND_REC="$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;r=json.load(sys.stdin)["detail"]["recommendations"];print(r[0]["videoId"] if r else "")')"
SECOND_REC="$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;r=json.load(sys.stdin)["detail"]["recommendations"];print(r[0]["externalId"] if r else "")')"
if [[ -n "$SECOND_REC" ]]; then
expect "reject a recommendation" "200" "POST" "/moods/$MOOD_ID/recommendations/$SECOND_REC/reject"
expect_eq "rejected state" "rejected" "$(printf '%s' "$HTTP_BODY" | json_field '["recommendation"]["state"]')"