index.js: sort channels

This commit is contained in:
He4eT 2023-12-25 16:13:44 +01:00
commit b6f3c4c048

View file

@ -25,13 +25,20 @@ const fuzzySelect = (choices) =>
pageSize: 10,
}])
const playChannel = (channel) => {
console.log(channel)
}
download(channelsUrl)
.then(xml2js.parseStringPromise)
.then((json) => json.channels.channel)
.then((channels) => channels.sort((a, b) =>
b.listeners[0] - a.listeners[0]))
.then((channels) => channels.map((channel) => ({
name: `${channel.title[0]}${channel.description[0]}`,
value: channel.highestpls[0]['_'],
})))
.then(fuzzySelect)
.then((x) => console.log(x))
.then(({channel}) => channel)
.then(playChannel)
.catch((error) => console.error('Error:', error.message))