added filenames with track title and id
This commit is contained in:
parent
71987c020c
commit
b868166b89
File diff suppressed because one or more lines are too long
38
index.js
38
index.js
|
@ -7,19 +7,19 @@ const client_id = "447462"
|
||||||
const client_secret = "a83bf7f38ad2f137e444727cfc3775cf"
|
const client_secret = "a83bf7f38ad2f137e444727cfc3775cf"
|
||||||
|
|
||||||
const formats = {
|
const formats = {
|
||||||
aac_96: { num: '8', gw: 'AAC_96', mime: 'audio/aac' },
|
aac_96: { num: '8', gw: 'AAC_96', mime: 'audio/aac', ext: '3gp' },
|
||||||
64: { num: '10', gw: 'MP3_64', mime: 'audio/mpeg' },
|
64: { num: '10', gw: 'MP3_64', mime: 'audio/mpeg', ext: 'mp3' },
|
||||||
128: { num: '1', gw: 'MP3_128', mime: 'audio/mpeg' },
|
128: { num: '1', gw: 'MP3_128', mime: 'audio/mpeg', ext: 'mp3' },
|
||||||
320: { num: '3', gw: 'MP3_320', mime: 'audio/mpeg' },
|
320: { num: '3', gw: 'MP3_320', mime: 'audio/mpeg', ext: 'mp3' },
|
||||||
flac: { num: '9', gw: 'FLAC', mime: 'audio/flac' },
|
flac: { num: '9', gw: 'FLAC', mime: 'audio/flac', ext: 'flac' },
|
||||||
mp4_ra1: { num: '13', gw: 'MP4_RA1', mime: 'audio/mp4' },
|
mp4_ra1: { num: '13', gw: 'MP4_RA1', mime: 'audio/mp4', ext: 'mp4' },
|
||||||
mp4_ra2: { num: '14', gw: 'MP4_RA2', mime: 'audio/mp4' },
|
mp4_ra2: { num: '14', gw: 'MP4_RA2', mime: 'audio/mp4', ext: 'mp4' },
|
||||||
mp4_ra3: { num: '15', gw: 'MP4_RA3', mime: 'audio/mp4' },
|
mp4_ra3: { num: '15', gw: 'MP4_RA3', mime: 'audio/mp4', ext: 'mp4' },
|
||||||
mhm1_ra1: { num: '16', gw: 'MHM1_RA1', mime: 'audio/mp4' },
|
mhm1_ra1: { num: '16', gw: 'MHM1_RA1', mime: 'audio/mp4', ext: 'mp4' },
|
||||||
mhm1_ra2: { num: '17', gw: 'MHM1_RA2', mime: 'audio/mp4' },
|
mhm1_ra2: { num: '17', gw: 'MHM1_RA2', mime: 'audio/mp4', ext: 'mp4' },
|
||||||
mhm1_ra3: { num: '18', gw: 'MHM1_RA3', mime: 'audio/mp4' },
|
mhm1_ra3: { num: '18', gw: 'MHM1_RA3', mime: 'audio/mp4', ext: 'mp4' },
|
||||||
sbc_256: { num: '12', gw: 'SBC_256', mime: '' },
|
sbc_256: { num: '12', gw: 'SBC_256', mime: '', ext: 'sbc' },
|
||||||
misc: { num: '0', gw: 'MP3_MISC', mime: 'audio/mpeg' },
|
misc: { num: '0', gw: 'MP3_MISC', mime: 'audio/mpeg', ext: 'mp3' },
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gw_api_call(method, params) {
|
async function gw_api_call(method, params) {
|
||||||
|
@ -235,13 +235,14 @@ async function track(id, format, tagging) {
|
||||||
return new Response("Couldn't get track stream", { status: 403, headers: { 'content-type': 'text/plain' } })
|
return new Response("Couldn't get track stream", { status: 403, headers: { 'content-type': 'text/plain' } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let title = json.SNG_TITLE
|
||||||
|
if (json.VERSION !== undefined) title += ` ${json.VERSION}`
|
||||||
|
|
||||||
let id3
|
let id3
|
||||||
if (tagging) {
|
if (tagging) {
|
||||||
id3 = new ID3Writer(Buffer.alloc(0));
|
id3 = new ID3Writer(Buffer.alloc(0));
|
||||||
id3.padding = 0
|
id3.padding = 0
|
||||||
|
|
||||||
let title = json.SNG_TITLE
|
|
||||||
if (json.VERSION !== undefined) title += ` ${json.VERSION}`
|
|
||||||
id3.setFrame('TIT2', title)
|
id3.setFrame('TIT2', title)
|
||||||
.setFrame('TALB', json.ALB_TITLE)
|
.setFrame('TALB', json.ALB_TITLE)
|
||||||
.setFrame('TPE2', json.ART_NAME)
|
.setFrame('TPE2', json.ART_NAME)
|
||||||
|
@ -306,7 +307,12 @@ async function track(id, format, tagging) {
|
||||||
|
|
||||||
pipeDecryptedStream(writer, track.body, length, cipher)
|
pipeDecryptedStream(writer, track.body, length, cipher)
|
||||||
|
|
||||||
return new Response(readable, { status: 200, headers: { 'content-type': formats[format].mime } })
|
const headers = {
|
||||||
|
'content-type': formats[format].mime,
|
||||||
|
'content-disposition': `inline; filename="${title.replaceAll('"', '_')} [${id}].${formats[format].ext}"`
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(readable, { status: 200, headers })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pipeDecryptedStream(writer, body, length, cipher) {
|
async function pipeDecryptedStream(writer, body, length, cipher) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ workers_dev = true
|
||||||
kv_namespaces = [
|
kv_namespaces = [
|
||||||
{ binding = "KV", id = "974c0967a84e415daa054bbbcc7f80c6", preview_id = "cfcc6491f3484cbca664913836635113" }
|
{ binding = "KV", id = "974c0967a84e415daa054bbbcc7f80c6", preview_id = "cfcc6491f3484cbca664913836635113" }
|
||||||
]
|
]
|
||||||
compatibility_date = "2021-12-04"
|
compatibility_date = "2022-01-04"
|
||||||
|
|
||||||
# [secrets]
|
# [secrets]
|
||||||
# ARL
|
# ARL
|
Loading…
Reference in New Issue