Created
September 16, 2020 17:56
-
-
Save marco79cgn/97a570b44ae9fe9692887dc0b02a17da to your computer and use it in GitHub Desktop.
Scriptable widget that plays BBC1 radio on Sonos
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
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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The shortcut to return to the homescreen (springboard) can be downloaded here:
https://www.icloud.com/shortcuts/7d195aa67ab543cd9daa85bf280274ad