- Deezer: /artist/{id}/radio for collection artists, affinity 2.0
- YouTube Music: RDAMVM watch playlist via yt-dlp, affinity 2.0
- seed radios from the 2 newest songs of the mood's own catalog
- dedupe candidates by recording, not only by external id
- clean raw YouTube titles and Topic suffixes when indexing
- tests, smoke marker for the RDAMVM path, docs
515 lines
22 KiB
Bash
Executable File
515 lines
22 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# End-to-end smoke test for the mood-first API.
|
|
#
|
|
# 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]
|
|
#
|
|
set -euo pipefail
|
|
|
|
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}"
|
|
TOKEN=""
|
|
HTTP_STATUS=""
|
|
HTTP_BODY=""
|
|
|
|
PASSED=0
|
|
FAILED=0
|
|
|
|
log() { printf '%s\n' "$*"; }
|
|
pass() { PASSED=$((PASSED + 1)); log "PASS $1"; }
|
|
fail() { FAILED=$((FAILED + 1)); log "FAIL $1: $2"; }
|
|
|
|
json_field() { python3 -c 'import json,sys;d=json.load(sys.stdin);print(eval("d"+sys.argv[1]))' "$1"; }
|
|
|
|
MEDIA="$WORK/data/media"
|
|
mkdir -p "$MEDIA/vid-seed-1" "$MEDIA/vid-seed-2" "$WORK/bin" "$WORK/data"
|
|
|
|
log "Seeding the media store in $MEDIA"
|
|
ffmpeg -hide_banner -loglevel error -y -f lavfi -i "color=c=red:s=64x64" -frames:v 1 "$WORK/cover.jpg"
|
|
ffmpeg -hide_banner -loglevel error -y \
|
|
-f lavfi -i "sine=frequency=440:duration=2" -i "$WORK/cover.jpg" \
|
|
-map 0:a -map 1:v -c:v copy -c:a libmp3lame -b:a 192k -id3v2_version 3 \
|
|
-metadata title="Seed One" -metadata artist="Seed Artist" -metadata album="Seed Album" \
|
|
-metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" \
|
|
"$MEDIA/vid-seed-1/Seed One.mp3"
|
|
ffmpeg -hide_banner -loglevel error -y \
|
|
-f lavfi -i "sine=frequency=550:duration=2" \
|
|
-c:a libmp3lame -b:a 192k -id3v2_version 3 \
|
|
-metadata title="Seed Two" -metadata artist="Second Artist" -metadata album="Second Album" \
|
|
"$MEDIA/vid-seed-2/Seed Two.mp3"
|
|
|
|
# Deterministic stand-in for yt-dlp: search, URL resolve and download.
|
|
cat > "$WORK/bin/yt-dlp" <<'FAKE'
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
out=""
|
|
prev=""
|
|
for arg in "$@"; do
|
|
if [[ "$prev" == "-o" ]]; then out="$arg"; fi
|
|
prev="$arg"
|
|
done
|
|
|
|
if [[ " $* " == *"RDAMVM"* ]]; then
|
|
# YouTube Music's watch-playlist radio: record that it was requested.
|
|
printf '%s\n' "$*" >> "$(dirname "$0")/../yt-radio.log"
|
|
cat <<'JSON'
|
|
{"entries":[
|
|
{"id":"vid-radio","title":"Radio Artist - Radio Track","duration":210,"channel":"Radio Artist"},
|
|
{"id":"vid-rec-a","title":"Downloaded Track","artist":"New Artist","album":"New Album","duration":180,"channel":"New Artist"}
|
|
]}
|
|
JSON
|
|
exit 0
|
|
fi
|
|
|
|
if [[ " $* " == *" music.youtube.com/search "* || " $* " == *" --flat-playlist "* ]]; then
|
|
cat <<'JSON'
|
|
{"entries":[
|
|
{"id":"vid-seed-1","title":"Seed One","artist":"Seed Artist","album":"Seed Album","duration":180,"channel":"Seed Artist"},
|
|
{"id":"vid-rec-a","title":"Downloaded Track","artist":"New Artist","album":"New Album","duration":180,"channel":"New Artist","thumbnail":"https://example/a.jpg"},
|
|
{"id":"vid-rec-b","title":"Another Track","artist":"Other Artist","album":"Other Album","duration":200,"channel":"Other Artist"},
|
|
{"id":"vid-long","title":"Long Set","artist":"DJ","duration":900,"channel":"DJ"},
|
|
{"id":"vid-short","title":"Interlude","artist":"DJ","duration":10,"channel":"DJ"}
|
|
]}
|
|
JSON
|
|
exit 0
|
|
fi
|
|
|
|
if [[ " $* " == *" --dump-single-json "* ]]; then
|
|
url="${*: -1}"
|
|
id="${url##*=}"; id="${id##*/}"
|
|
printf '{"id":"%s","title":"URL Artist - URL Track","channel":"URL Artist","duration":200}' "$id"
|
|
exit 0
|
|
fi
|
|
|
|
url="${*: -1}"
|
|
id="${url##*=}"
|
|
dir="$(dirname "$out")"
|
|
mkdir -p "$dir"
|
|
ffmpeg -hide_banner -loglevel error -y \
|
|
-f lavfi -i "sine=frequency=700:duration=1" \
|
|
-c:a libmp3lame -b:a 128k -id3v2_version 3 \
|
|
-metadata title="Downloaded Track" -metadata artist="New Artist" \
|
|
"$dir/$id.mp3"
|
|
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"}},
|
|
}
|
|
|
|
# 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
|
|
|
|
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)
|
|
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(parts[-1]) or EXTRA_TRACKS.get(parts[-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" ;;
|
|
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 \
|
|
-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
|
|
password: "$PASS"
|
|
admin: true
|
|
EOF
|
|
|
|
log "Building fat JAR..."
|
|
(cd "$ROOT" && "$GRADLE" -q shadowJar)
|
|
|
|
JAR="$(find "$ROOT/build/libs" -name 'musicmanager-*-all.jar' | head -1)"
|
|
if [[ -z "$JAR" ]]; then
|
|
log "Could not find the fat JAR under build/libs"
|
|
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 $DZ_API_PID 2>/dev/null || true' EXIT
|
|
|
|
log "Waiting for the server and the startup scan..."
|
|
SONGS=0
|
|
for _ in $(seq 1 120); do
|
|
if curl -sf "$BASE/health" >/dev/null 2>&1; then
|
|
SONGS="$(sqlite3 "$WORK/data/musicmanager.db" 'select count(*) from songs' 2>/dev/null || echo 0)"
|
|
[[ "$SONGS" -ge 2 ]] && break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [[ "${SONGS:-0}" -lt 2 ]]; then
|
|
log "Server did not index the media store; see $WORK/server.log"
|
|
tail -20 "$WORK/server.log" || true
|
|
exit 1
|
|
fi
|
|
|
|
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]
|
|
api() {
|
|
local method="$1" path="$2" body="${3:-}" auth="${4:-$TOKEN}"
|
|
local args=(-s -w '\n%{http_code}' -X "$method" "$BASE/api/v1$path")
|
|
[[ -n "$auth" ]] && args+=(-H "Authorization: Bearer $auth")
|
|
if [[ -n "$body" ]]; then
|
|
args+=(-H 'Content-Type: application/json' -d "$body")
|
|
fi
|
|
local out
|
|
out="$(curl "${args[@]}")"
|
|
HTTP_STATUS="$(printf '%s' "$out" | tail -1)"
|
|
HTTP_BODY="$(printf '%s' "$out" | sed '$d')"
|
|
}
|
|
|
|
expect() {
|
|
local name="$1" expected="$2" method="$3" path="$4" body="${5:-}"
|
|
api "$method" "$path" "$body"
|
|
if [[ "$HTTP_STATUS" == "$expected" ]]; then
|
|
pass "$name"
|
|
else
|
|
fail "$name" "HTTP $HTTP_STATUS (expected $expected): ${HTTP_BODY:0:240}"
|
|
fi
|
|
}
|
|
|
|
expect_eq() {
|
|
local name="$1" expected="$2" actual="$3"
|
|
if [[ "$actual" == "$expected" ]]; then
|
|
pass "$name"
|
|
else
|
|
fail "$name" "expected '$expected', got '$actual'"
|
|
fi
|
|
}
|
|
|
|
# wait_for <seconds> <name> <python-condition> <path>
|
|
wait_for() {
|
|
local seconds="$1" name="$2" condition="$3" path="$4" body=""
|
|
for _ in $(seq 1 "$seconds"); do
|
|
api GET "$path"
|
|
if [[ "$HTTP_STATUS" == "200" ]] \
|
|
&& printf '%s' "$HTTP_BODY" | python3 -c "import json,sys;d=json.load(sys.stdin);sys.exit(0 if ($condition) else 1)" 2>/dev/null; then
|
|
pass "$name"
|
|
return 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
fail "$name" "timed out; last body: ${HTTP_BODY:0:240}"
|
|
}
|
|
|
|
log ""
|
|
log "Authentication"
|
|
LOGIN_STATUS="$(curl -s -o "$WORK/login.json" -w '%{http_code}' -X POST \
|
|
-H 'Content-Type: application/json' \
|
|
-d "{\"username\":\"$USER\",\"password\":\"$PASS\",\"deviceName\":\"smoke\",\"platform\":\"cli\"}" \
|
|
"$BASE/api/v1/auth/login")"
|
|
expect_eq "login status" "200" "$LOGIN_STATUS"
|
|
TOKEN="$(json_field '["token"]' < "$WORK/login.json" 2>/dev/null || true)"
|
|
if [[ -n "$TOKEN" ]]; then pass "login token"; else fail "login token" "$(head -c 200 "$WORK/login.json")"; fi
|
|
expect_eq "login user" "$USER" "$(json_field '["user"]["name"]' < "$WORK/login.json" 2>/dev/null || true)"
|
|
|
|
BAD_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -X POST \
|
|
-H 'Content-Type: application/json' -d '{"username":"smoke","password":"wrong"}' \
|
|
"$BASE/api/v1/auth/login")"
|
|
expect_eq "login rejects bad password" "401" "$BAD_STATUS"
|
|
UNAUTH_STATUS="$(curl -s -o /dev/null -w '%{http_code}' "$BASE/api/v1/moods")"
|
|
expect_eq "unauthenticated request rejected" "401" "$UNAUTH_STATUS"
|
|
expect "me" "200" "GET" "/me"
|
|
expect_eq "me name" "$USER" "$(printf '%s' "$HTTP_BODY" | json_field '["name"]')"
|
|
|
|
log ""
|
|
log "Search"
|
|
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["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","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}'
|
|
expect_eq "empty mood error code" "empty_mood" "$(printf '%s' "$HTTP_BODY" | json_field '["error"]["code"]')"
|
|
|
|
expect "add an existing song" "200" "POST" "/moods/$MOOD_ID/songs" "{\"songId\":\"$SEED_ONE\"}"
|
|
expect_eq "song count" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["detail"]["mood"]["songCount"]')"
|
|
expect "add a second song" "200" "POST" "/moods/$MOOD_ID/songs" "{\"songId\":\"$SEED_TWO\"}"
|
|
expect_eq "song count after second add" "2" "$(printf '%s' "$HTTP_BODY" | json_field '["detail"]["mood"]["songCount"]')"
|
|
expect "add by URL" "202" "POST" "/moods/$MOOD_ID/songs" '{"url":"https://youtu.be/vid-url"}'
|
|
wait_for 60 "URL download attaches to the mood" 'd["mood"]["songCount"] >= 3' "/moods/$MOOD_ID"
|
|
|
|
expect "list moods" "200" "GET" "/moods"
|
|
expect_eq "list contains mood" "1" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print(sum(1 for m in json.load(sys.stdin)["moods"] if m["id"]=="'"$MOOD_ID"'"))')"
|
|
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/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
|
|
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]["externalId"] if r else "")')"
|
|
wait_for 90 "recommendations download" 'd["mood"]["recommendationReady"] >= 1' "/moods/$MOOD_ID"
|
|
if [[ -f "$WORK/yt-radio.log" ]]; then
|
|
pass "YouTube Music radio discovery"
|
|
else
|
|
fail "YouTube Music radio discovery" "no RDAMVM playlist was requested"
|
|
fi
|
|
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]["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"]')"
|
|
else
|
|
fail "reject a recommendation" "no second recommendation was available"
|
|
fi
|
|
|
|
log ""
|
|
log "Radio sessions"
|
|
expect "start session" "201" "POST" "/moods/$MOOD_ID/sessions" '{"limit":10}'
|
|
SESSION_ID="$(printf '%s' "$HTTP_BODY" | json_field '["id"]' 2>/dev/null || true)"
|
|
if [[ -n "$SESSION_ID" ]]; then pass "session id"; else fail "session id" "${HTTP_BODY:0:200}"; fi
|
|
expect_eq "queue contains a collection song" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if json.load(sys.stdin)["queue"] else "no")')"
|
|
expect "next tracks" "200" "POST" "/sessions/$SESSION_ID/next" '{"limit":10}'
|
|
expect "playback event" "200" "POST" "/sessions/$SESSION_ID/events" \
|
|
"{\"events\":[{\"songId\":\"$SEED_ONE\",\"type\":\"completed\",\"positionSeconds\":2}]}"
|
|
expect_eq "accepted events" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["accepted"]')"
|
|
expect "resume session" "200" "GET" "/sessions/$SESSION_ID"
|
|
expect "close session" "204" "DELETE" "/sessions/$SESSION_ID"
|
|
|
|
log ""
|
|
log "Media"
|
|
STREAM_STATUS="$(curl -s -o "$WORK/stream.mp3" -w '%{http_code}' \
|
|
"$BASE/api/v1/songs/$SEED_ONE/stream?token=$TOKEN")"
|
|
if [[ "$STREAM_STATUS" == "200" && -s "$WORK/stream.mp3" ]]; then
|
|
pass "stream with query token"
|
|
else
|
|
fail "stream with query token" "HTTP $STREAM_STATUS"
|
|
fi
|
|
|
|
RANGE_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -H 'Range: bytes=0-9' \
|
|
"$BASE/api/v1/songs/$SEED_ONE/stream?token=$TOKEN")"
|
|
expect_eq "stream range" "206" "$RANGE_STATUS"
|
|
|
|
TRANSCODE_STATUS="$(curl -s -D "$WORK/transcode.headers" -o "$WORK/transcoded.mp3" -w '%{http_code}' \
|
|
"$BASE/api/v1/songs/$SEED_ONE/stream?token=$TOKEN&maxBitRate=64")"
|
|
if [[ "$TRANSCODE_STATUS" == "200" && -s "$WORK/transcoded.mp3" ]] \
|
|
&& grep -qi '^content-type: audio/mpeg' "$WORK/transcode.headers"; then
|
|
pass "stream transcode"
|
|
else
|
|
fail "stream transcode" "HTTP $TRANSCODE_STATUS"
|
|
fi
|
|
|
|
DOWNLOAD_STATUS="$(curl -s -o "$WORK/download.mp3" -w '%{http_code}' \
|
|
"$BASE/api/v1/songs/$SEED_ONE/stream?token=$TOKEN&download=true")"
|
|
if [[ "$DOWNLOAD_STATUS" == "200" && -s "$WORK/download.mp3" ]]; then
|
|
pass "download original"
|
|
else
|
|
fail "download original" "HTTP $DOWNLOAD_STATUS"
|
|
fi
|
|
|
|
COVER_STATUS="$(curl -s -o "$WORK/cover-out.jpg" -w '%{http_code}' \
|
|
"$BASE/api/v1/songs/$SEED_ONE/cover?size=32&token=$TOKEN")"
|
|
if [[ "$COVER_STATUS" == "200" && -s "$WORK/cover-out.jpg" ]]; then
|
|
pass "cover art"
|
|
else
|
|
fail "cover art" "HTTP $COVER_STATUS"
|
|
fi
|
|
|
|
expect "scan status" "200" "GET" "/scan"
|
|
expect "start scan" "202" "POST" "/scan"
|
|
|
|
log ""
|
|
log "Cleanup"
|
|
expect "delete mood" "204" "DELETE" "/moods/$MOOD_ID"
|
|
expect "logout" "204" "POST" "/auth/logout"
|
|
api "GET" "/me" "" "$TOKEN"
|
|
expect_eq "token revoked after logout" "401" "$HTTP_STATUS"
|
|
|
|
log ""
|
|
log "Smoke test finished: $PASSED passed, $FAILED failed"
|
|
log "Server log: $WORK/server.log"
|
|
|
|
if [[ "$FAILED" -gt 0 ]]; then
|
|
exit 1
|
|
fi
|