index.js: use fuzzySelect

This commit is contained in:
He4eT 2023-12-25 15:53:42 +01:00
commit 24d8a8d288

View file

@ -1,6 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
const xml2js = require('xml2js') const xml2js = require('xml2js')
const inquirer = require('inquirer')
inquirer.registerPrompt('search-list', require('inquirer-search-list'))
const channelsUrl = 'https://somafm.com/channels.xml' const channelsUrl = 'https://somafm.com/channels.xml'
@ -14,12 +16,22 @@ const download = (url) =>
} }
}) })
const fuzzySelect = (choices) =>
inquirer.prompt([{
type: "search-list",
message: "Select SomaFM channel",
name: "channel",
choices,
pageSize: 10,
}])
download(channelsUrl) download(channelsUrl)
.then(xml2js.parseStringPromise) .then(xml2js.parseStringPromise)
.then((json) => json.channels.channel) .then((json) => json.channels.channel)
.then((channels) => channels.map((channel) => ({ .then((channels) => channels.map((channel) => ({
title: `${channel.title[0]}${channel.description[0]}`, name: `${channel.title[0]}${channel.description[0]}`,
value: channel.highestpls[0]['_'], value: channel.highestpls[0]['_'],
}))) })))
.then(fuzzySelect)
.then((x) => console.log(x)) .then((x) => console.log(x))
.catch((error) => console.error('Error:', error.message)) .catch((error) => console.error('Error:', error.message))