diff --git a/index.js b/index.js index 20aac4a..89108ec 100755 --- a/index.js +++ b/index.js @@ -1,3 +1,25 @@ #!/usr/bin/env node -console.log(1234) +const xml2js = require('xml2js') + +const channelsUrl = 'https://somafm.com/channels.xml' + +const download = (url) => + fetch(url) + .then((response) => { + if (response.ok) { + return response.text() + } else { + throw new Error(`Failed to download XML. Status: ${response.status} ${response.statusText}`) + } + }) + +download(channelsUrl) + .then(xml2js.parseStringPromise) + .then((json) => json.channels.channel) + .then((channels) => channels.map((channel) => ({ + title: `${channel.title[0]} — ${channel.description[0]}`, + value: channel.highestpls[0]['_'], + }))) + .then((x) => console.log(x)) + .catch((error) => console.error('Error:', error.message))