Skip to content

Instantly share code, notes, and snippets.

@konecnyna
Created June 24, 2021 23:51
Show Gist options
  • Save konecnyna/f3debc91a39b6e6252442b63689e3c5e to your computer and use it in GitHub Desktop.
Save konecnyna/f3debc91a39b6e6252442b63689e3c5e to your computer and use it in GitHub Desktop.
hdhomerun vlc cli
#!/usr/bin/env node
const { execSync } = require("child_process")
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const read = (question) => {
return new Promise(resolve => {
rl.question(question, function (input) {
resolve(input);
rl.close();
});
})
}
const channelList = [
{ station: "CBS", url: "http://192.168.1.51:5004/auto/v2.1" },
{ station: "NBC", url: "http://192.168.1.51:5004/auto/v4.1" },
{ station: "FOX", url: "http://192.168.1.51:5004/auto/v5.1" },
{ station: "ABC", url: "http://192.168.1.51:5004/auto/v7.1" },
{ station: "PBS", url: "http://192.168.1.51:5004/auto/v21.1" },
]
const openVlcUrl = (url) => { execSync(`open -a VLC ${url} &`) }
(async () => {
const args = process.argv.slice(2)
if (!args.length) {
const choices = channelList.map((channel, index) => `${index}. ${channel.station}`);
const result = await read(`Please Choose:\n${choices.join("\n")}\nChoice: `)
const index = parseInt(result);
const { station, url } = channelList[index]
console.log(`Opening: ${station} (${url})`)
openVlcUrl(url)
process.exit(0)
}
openVlcUrl(`http://192.168.1.51:5004/auto/v${args[0]}`)
process.exit(0)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment