FINALLY FUCKING IMPLEMENTED STREAMING
This commit is contained in:
parent
5dddc1a7ab
commit
3e4a929938
File diff suppressed because one or more lines are too long
23
index.js
23
index.js
|
@ -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'}})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue