Skip to content

Instantly share code, notes, and snippets.

@marco79cgn
Created September 16, 2020 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marco79cgn/97a570b44ae9fe9692887dc0b02a17da to your computer and use it in GitHub Desktop.
Save marco79cgn/97a570b44ae9fe9692887dc0b02a17da to your computer and use it in GitHub Desktop.
Scriptable widget that plays BBC1 radio on Sonos
let param = args.widgetParameter
let widget = new ListWidget()
widget.setPadding(0,0,0,0)
// the node sonos http api base url
let sonosBaseUrl = "http://192.168.178.10:5005"
widget.backgroundColor = new Color("#FFFFFF")
await loadImage("https://mytuner.global.ssl.fastly.net/media/tvos_radios/BFcU2vjUXh.png")
await playOnSonos()
Script.setWidget(widget)
Script.complete()
async function playOnSonos() {
if(config.runsInApp) {
let sonosUrl = sonosBaseUrl + "/Arbeitszimmer/tunein/play/24939"
let request = new Request(sonosUrl)
request.allowInsecureRequest = true
let json = await request.loadJSON()
if(param === "sonos") {
// open the Sonos app
Safari.open("sonos://")
} else {
// return to homescreen
Safari.open("shortcuts://run-shortcut?name=SpringBoard")
}
}
}
// download and display the cover
async function loadImage(imageUrl) {
let req = new Request(imageUrl)
let image = await req.loadImage()
let widgetImage = widget.addImage(image)
widgetImage.imageSize = new Size(180,180)
widgetImage.centerAlignImage()
}
@marco79cgn
Copy link
Author

The shortcut to return to the homescreen (springboard) can be downloaded here:
https://www.icloud.com/shortcuts/7d195aa67ab543cd9daa85bf280274ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment