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)
|
encrypted = !['320', 'flac'].includes(format)
|
||||||
if (!encrypted) { // server-side stream url
|
if (!encrypted) { // server-side stream url
|
||||||
// TODO: handle alternatives
|
// needed if track has fallback, like https://www.deezer.com/track/11835714
|
||||||
result = json['url_' + format]
|
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) {
|
if (result === undefined) {
|
||||||
return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } })
|
return new Response('Format unavailable', { status: 403, headers: { 'content-type': 'text/plain' } })
|
||||||
|
|
|
@ -3,4 +3,3 @@ type = "webpack"
|
||||||
webpack_config = "webpack.config.js"
|
webpack_config = "webpack.config.js"
|
||||||
account_id = "03479b0523a52b140e0dabac40cb0fc8"
|
account_id = "03479b0523a52b140e0dabac40cb0fc8"
|
||||||
workers_dev = true
|
workers_dev = true
|
||||||
vars = { ACCESS_TOKEN = "haha nope" }
|
|
Loading…
Reference in New Issue