From 13774d5a8dcbaef4696a48a0add1ec9756a0b54b Mon Sep 17 00:00:00 2001 From: He4eT Date: Mon, 25 Dec 2023 17:33:25 +0100 Subject: [PATCH] index.js: cleanup --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1ead813..e35bbcc 100755 --- a/index.js +++ b/index.js @@ -4,9 +4,7 @@ const inquirer = require('inquirer') const xml2js = require('xml2js') const { exec } = require('child_process'); -inquirer.registerPrompt('search-list', require('inquirer-search-list')) - -const channelsUrl = 'https://somafm.com/channels.xml' +const CHANNELS_XML_URL = 'https://somafm.com/channels.xml' const downloadChannelsXML = (url) => fetch(url) @@ -21,13 +19,15 @@ const downloadChannelsXML = (url) => const extractChannels = (json) => json.channels.channel -const fuzzySelect = (choices) => - inquirer.prompt([{ +const fuzzySelect = (choices) => { + inquirer.registerPrompt('search-list', require('inquirer-search-list')) + return inquirer.prompt([{ type: "search-list", message: "SomaFM channel", name: "channel", choices, }]) +} const sortChannels = (channels) => channels.sort((a, b) => @@ -43,7 +43,7 @@ const shapeChannels = (channels) => const playChannel = ({channel}) => exec(`cvlc ${channel}`) -downloadChannelsXML(channelsUrl) +downloadChannelsXML(CHANNELS_XML_URL) .then(xml2js.parseStringPromise) .then(extractChannels) .then(sortChannels)