index.js: init

This commit is contained in:
He4eT 2023-12-25 14:55:18 +01:00
commit 987c0e4814

View file

@ -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))