FINALLY FUCKING IMPLEMENTED STREAMING

This commit is contained in:
uh wot 2021-05-25 23:42:00 +02:00
parent 5dddc1a7ab
commit 3e4a929938
Signed by: uhwot
GPG Key ID: CB2454984587B781
2 changed files with 26 additions and 10 deletions

13
dist/worker.js vendored

File diff suppressed because one or more lines are too long

View File

@ -111,10 +111,10 @@ async function track(id, format, access_token, tagging) {
return new Response(null, {status: 302, headers: {'location': result}})
} else {
const track = await fetch(result)
const trackBuffer = await track.arrayBuffer()
const writer = new ID3Writer(trackBuffer);
writer.setFrame('TIT2', json.title)
const id3 = new ID3Writer(Buffer.alloc(0));
id3.padding = 0
id3.setFrame('TIT2', json.title)
.setFrame('TALB', json.album.title)
if (json.contributors !== undefined) {
@ -123,27 +123,34 @@ async function track(id, format, access_token, tagging) {
contr_list.push(c.name)
}
writer.setFrame('TPE1', contr_list)
id3.setFrame('TPE1', contr_list)
}
if (json.release_date !== undefined) {
writer.setFrame('TYER', json.release_date.split('-')[0])
id3.setFrame('TYER', json.release_date.split('-')[0])
}
if (json.album.cover_xl !== undefined) {
const cover = await fetch(json.album.cover_xl)
const coverBuffer = await cover.arrayBuffer()
writer.setFrame('APIC', {
id3.setFrame('APIC', {
type: 3,
data: coverBuffer,
description: 'cover'
});
}
writer.addTag();
id3.addTag();
return new Response(writer.arrayBuffer, {status: 200, headers: {'content-type': 'audio/mpeg'}})
let { readable, writable } = new TransformStream()
const writer = writable.getWriter()
writer.write(id3.arrayBuffer)
writer.releaseLock()
track.body.pipeTo(writable)
return new Response(readable, {status: 200, headers: {'content-type': 'audio/mpeg'}})
}
}