forked from boyska/radiomanifest.js
fetching streaminfo is more tolerant
This commit is contained in:
parent
6544f023e5
commit
b21596d1d7
1 changed files with 19 additions and 16 deletions
|
@ -108,24 +108,27 @@ async function get (siteurl, options) {
|
|||
resp = null
|
||||
try {
|
||||
resp = await fetch(getStreaminfoUrl(siteurl))
|
||||
text = await resp.text()
|
||||
|
||||
const data = JSON.parse(text)
|
||||
const name = data['icy-name']
|
||||
if (name !== undefined) {
|
||||
manifest.setName(name)
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError && e.message.startsWith('NetworkError')) {
|
||||
// the fetch has failed
|
||||
true
|
||||
} else if (e instanceof SyntaxError && e.message.startsWith('JSON.parse')) {
|
||||
true
|
||||
} else {
|
||||
console.error('Error', e)
|
||||
throw e
|
||||
}
|
||||
true
|
||||
}
|
||||
if(resp !== null) {
|
||||
try {
|
||||
text = await resp.text()
|
||||
|
||||
const data = JSON.parse(text)
|
||||
const name = data['icy-name']
|
||||
if (name !== undefined) {
|
||||
manifest.setName(name)
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
true
|
||||
} else {
|
||||
console.error('Error', e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: in base alle options fai fetch anche di altra roba
|
||||
return manifest
|
||||
|
|
Loading…
Reference in a new issue