Last active
March 26, 2018 16:47
-
-
Save tedchoward/85ba4b7af9c8770c1d4a118aa5462498 to your computer and use it in GitHub Desktop.
AppleScript (JXA) that fetches a list of channels from SomaFM and plays the selected channel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomaFM { | |
constructor(app) { | |
const jsonStr = app.doShellScript('curl https://somafm.com/channels.json'); | |
const { channels } = JSON.parse(jsonStr); | |
this._opts = channels.map(c => ({ name: c.title, url: c.playlists[0].url})); | |
this._names = this._opts.map(opt => opt.name); | |
} | |
get names() { return [ ...this._names]; } | |
getURL(name) { | |
const idx = this._names.indexOf(selection); | |
return this._opts[idx].url; | |
} | |
} | |
const app = Application.currentApplication(); | |
app.includeStandardAdditions = true; | |
const somaFM = new SomaFM(app); | |
const selection = app.chooseFromList(somaFM.names, { withTitle: 'SomaFM', withPrompt: 'Choose a Station' })[0]; | |
if (selection != null) { | |
const url = somaFM.getURL(selection); | |
const qt = Application('QuickTime Player'); | |
qt.openURL(url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment