mirror of
https://github.com/He4eT/fuzzsoma.git
synced 2026-05-04 17:27:23 +00:00
index.js: use fuzzySelect
This commit is contained in:
parent
3d63880235
commit
24d8a8d288
1 changed files with 13 additions and 1 deletions
14
index.js
14
index.js
|
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const xml2js = require('xml2js')
|
||||
const inquirer = require('inquirer')
|
||||
inquirer.registerPrompt('search-list', require('inquirer-search-list'))
|
||||
|
||||
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)
|
||||
.then(xml2js.parseStringPromise)
|
||||
.then((json) => json.channels.channel)
|
||||
.then((channels) => channels.map((channel) => ({
|
||||
title: `${channel.title[0]} — ${channel.description[0]}`,
|
||||
name: `${channel.title[0]} — ${channel.description[0]}`,
|
||||
value: channel.highestpls[0]['_'],
|
||||
})))
|
||||
.then(fuzzySelect)
|
||||
.then((x) => console.log(x))
|
||||
.catch((error) => console.error('Error:', error.message))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue