Spelaren föredrar låtversionen (Artist - Topic) framför musikvideor, som på YT Music
All checks were successful
build-and-push / build (push) Successful in 12s

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01824ZrvG2mDYYrmwqypLNup
This commit is contained in:
2026-08-01 05:31:04 +02:00
parent 9874d383ea
commit dcd4928813
2 changed files with 9 additions and 3 deletions

View File

@@ -245,11 +245,14 @@ export function buildApp(config, deps = {}) {
try {
const url =
`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video` +
`&videoCategoryId=10&maxResults=1&q=${encodeURIComponent(q)}&key=${encodeURIComponent(key)}`
`&videoCategoryId=10&maxResults=5&q=${encodeURIComponent(q)}&key=${encodeURIComponent(key)}`
const res = await (deps.playFetch ?? fetch)(url)
if (!res.ok) return reply.code(502).send({ error: `YouTube svarade ${res.status}` })
const js = await res.json()
const hit = js.items?.[0]
const items = js.items ?? []
// föredra "Artist - Topic"-kanalens ljudspår (= låten som på YT Music)
// framför officiella musikvideor
const hit = items.find((i) => (i.snippet?.channelTitle ?? '').endsWith(' - Topic')) ?? items[0]
if (!hit) return reply.code(404).send({ error: 'ingen video hittades' })
return {
videoId: hit.id.videoId,