fixed fallback handling
This commit is contained in:
parent
4b8b3dde44
commit
e28ad54c6b
File diff suppressed because one or more lines are too long
12
index.js
12
index.js
|
@ -66,8 +66,16 @@ async function track(id, format, tagging) {
|
|||
|
||||
encrypted = !['320', 'flac'].includes(format)
|
||||
if (!encrypted) { // server-side stream url
|
||||
// TODO: handle alternatives
|
||||
result = json['url_' + format]
|
||||
// needed if track has fallback, like https://www.deezer.com/track/11835714
|
||||
let urls
|
||||
if (!json.alternative) {
|
||||
urls = json
|
||||
} else {
|
||||
const temp = await fetch(`https://api.deezer.com/streaming_url.php?access_token=${ACCESS_TOKEN}&track_id=${json.alternative.id}`)
|
||||
urls = await temp.json()
|
||||
}
|
||||
|
||||
result = urls['url_' + format]
|
||||
|
||||
if (result === undefined) {
|
||||
return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } })
|
||||
|
|
|
@ -2,5 +2,4 @@ name = "dz"
|
|||
type = "webpack"
|
||||
webpack_config = "webpack.config.js"
|
||||
account_id = "03479b0523a52b140e0dabac40cb0fc8"
|
||||
workers_dev = true
|
||||
vars = { ACCESS_TOKEN = "haha nope" }
|
||||
workers_dev = true
|
Loading…
Reference in New Issue