index.js: cleanup

This commit is contained in:
He4eT 2023-12-25 17:33:25 +01:00
commit 13774d5a8d

View file

@ -4,9 +4,7 @@ const inquirer = require('inquirer')
const xml2js = require('xml2js') const xml2js = require('xml2js')
const { exec } = require('child_process'); const { exec } = require('child_process');
inquirer.registerPrompt('search-list', require('inquirer-search-list')) const CHANNELS_XML_URL = 'https://somafm.com/channels.xml'
const channelsUrl = 'https://somafm.com/channels.xml'
const downloadChannelsXML = (url) => const downloadChannelsXML = (url) =>
fetch(url) fetch(url)
@ -21,13 +19,15 @@ const downloadChannelsXML = (url) =>
const extractChannels = (json) => const extractChannels = (json) =>
json.channels.channel json.channels.channel
const fuzzySelect = (choices) => const fuzzySelect = (choices) => {
inquirer.prompt([{ inquirer.registerPrompt('search-list', require('inquirer-search-list'))
return inquirer.prompt([{
type: "search-list", type: "search-list",
message: "SomaFM channel", message: "SomaFM channel",
name: "channel", name: "channel",
choices, choices,
}]) }])
}
const sortChannels = (channels) => const sortChannels = (channels) =>
channels.sort((a, b) => channels.sort((a, b) =>
@ -43,7 +43,7 @@ const shapeChannels = (channels) =>
const playChannel = ({channel}) => const playChannel = ({channel}) =>
exec(`cvlc ${channel}`) exec(`cvlc ${channel}`)
downloadChannelsXML(channelsUrl) downloadChannelsXML(CHANNELS_XML_URL)
.then(xml2js.parseStringPromise) .then(xml2js.parseStringPromise)
.then(extractChannels) .then(extractChannels)
.then(sortChannels) .then(sortChannels)