From b21596d1d78ce159d206d94649360539051928cb Mon Sep 17 00:00:00 2001 From: boyska Date: Sun, 5 Dec 2021 17:40:17 +0100 Subject: [PATCH] fetching streaminfo is more tolerant --- radiomanifest.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/radiomanifest.js b/radiomanifest.js index 2fc20d5..149c910 100644 --- a/radiomanifest.js +++ b/radiomanifest.js @@ -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