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
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:
@@ -245,11 +245,14 @@ export function buildApp(config, deps = {}) {
|
|||||||
try {
|
try {
|
||||||
const url =
|
const url =
|
||||||
`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video` +
|
`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)
|
const res = await (deps.playFetch ?? fetch)(url)
|
||||||
if (!res.ok) return reply.code(502).send({ error: `YouTube svarade ${res.status}` })
|
if (!res.ok) return reply.code(502).send({ error: `YouTube svarade ${res.status}` })
|
||||||
const js = await res.json()
|
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' })
|
if (!hit) return reply.code(404).send({ error: 'ingen video hittades' })
|
||||||
return {
|
return {
|
||||||
videoId: hit.id.videoId,
|
videoId: hit.id.videoId,
|
||||||
|
|||||||
@@ -141,7 +141,10 @@ test('GET /api/play slår upp videoId via YouTube Data API', async () => {
|
|||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
json: async () => ({
|
json: async () => ({
|
||||||
items: [{ id: { videoId: 'abc123' }, snippet: { title: 'Sanctified with Dynamite', channelTitle: 'Powerwolf - Topic' } }],
|
items: [
|
||||||
|
{ id: { videoId: 'video99' }, snippet: { title: 'Official Video', channelTitle: 'Metal Blade Records' } },
|
||||||
|
{ id: { videoId: 'abc123' }, snippet: { title: 'Sanctified with Dynamite', channelTitle: 'Powerwolf - Topic' } },
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user