Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scriptable Radio Paradise Widget
let stationName = "flac"
let stationId = getConfiguredStationId()
let nowPlaying = await loadNowPlaying(stationId)
let widget = await createWidget(nowPlaying)
Script.setWidget(widget)
Script.complete()
widget.presentSmall()
async function createWidget(nowPlaying) {
let widget = new ListWidget()
widget.setPadding(8, 10, 12, 10)
widget.addSpacer()
// set gradient background with transparency
let gradient = new LinearGradient()
gradient.colors = [new Color("#1c1c1c00"), new Color("#1c1c1c92")]
gradient.locations = [0.0, 1]
widget.backgroundGradient = gradient
widget.backgroundColor = new Color("#1c1c1c")
// load image
let coverArt = await loadImage(nowPlaying.cover)
widget.backgroundImage = coverArt
// add title and artist
let titleTxt = widget.addText(nowPlaying.title)
titleTxt.font = Font.boldSystemFont(12)
titleTxt.textColor = Color.white()
widget.addSpacer(2)
let artistTxt = widget.addText(nowPlaying.artist)
artistTxt.font = Font.boldSystemFont(11)
artistTxt.textColor = Color.yellow()
widget.url = "vlc-x-callback://x-callback-url/stream?url=https://stream.radioparadise.com/" + stationName
return widget
}
// verify the configured flac stream
function getConfiguredStationId() {
let param = args.widgetParameter
let stationId = 0
if(param != null) {
switch (param) {
case 'main':
stationId = 0
stationName = "flac"
break
case 'mellow':
stationId = 1
stationName = "mellow-flac"
break
case 'rock':
stationId = 2
stationName = "rock-flac"
break
case 'world':
stationId = 3
stationName = "world-etc-flac"
break
default:
stationId = 0
stationName = "flac"
}
}
return stationId
}
// helper function to load and parse a restful json api
async function loadNowPlaying(stationId) {
const url = "https://api.radioparadise.com/api/now_playing?chan=" + stationId
let req = new Request(url)
let json = await req.loadJSON()
return json
}
// helper function to download an image from a given url
async function loadImage(imgUrl) {
let req = new Request(imgUrl)
let image = await req.loadImage()
return image
}
@marco79cgn
Copy link
Author

marco79cgn commented Sep 29, 2020

Intro

iOS 14 Custom Widget made with the help of the Scriptable app.
It shows the metadata of Radio Paradise and plays the FLAC stream in VLC upon interacting. It‘s possible to configure each of the 4 different FLAC streams by setting the widget parameter to either

  • main
  • mellow
  • rock
  • world

Requirements

  • iOS 14
  • Scriptable version 1.5 (or above)
  • VLC iOS app (if you want to listen to the stream quickly)

Thanks

A big Thank you to @simonbs for making great apps like Scriptable, DataJar or Jayson.

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