Retrieve Live NPR Program Information with Siri Shortcuts
A modified shortcut to query live program information from your NPR station.
This past month, MacStories hosted a community Siri Shortcuts contest called Automation April. One of its winners – a shortcut called “What's on KUTX?” credited to Jack Wellborn – caught my eye as a lifelong dependent upon National Public Radio. Via John Voorhees' comment:
The solution Wellborn came up with is ingenious. It turns out that KUTX uses a web API that can return information about the currently playing track. The API is used to drive an ‘On Now’ widget on the station’s website, but Wellborn discovered that they could query the API and get the track information back as JSON. So, they built a shortcut that queries the API when run, returning the info about the currently-playing song.
I began playing around with the NPR API Jack used and discovered quite accidentally that their shortcut could be modified to display current program information for those NPR stations that are not music-oriented, like mine. For the vast majority of the 24-hour cycle, KBIA – “Mid-Missouri's NPR station” – plays news programs, mostly from NPR, itself, supplanted by BBC news late at night.
hey locals! I made a Siri Shortcut that displays live program information for @KBIA. https://t.co/QVsr0jb85y
— ⓓⓐⓥⓘⓓ ⓑⓛⓤⓔ (@NeoYokel) June 5, 2022
After some trimming and the addition of the URL for KBIA's Apple Music Stream, I came up with What's on KBIA?, which displays upon run the current program's title as well as a hyperlink to open its distinct webpage. By way of a simple Choose from Menu action, it then prompts one with three options:
- Open the program's webpage (again.)
- Open KBIA's stream in Apple Music.
- Open KOPN's stream in Apple Music. (KOPN is Columbia's community radio station.)
Creating a Shortcut for Your NPR Station
All I really needed to customize Jack Wellborn's original shortcut was my NPR station's “UCSID,“which, for reference, is 5387648fe1c8335046a1d4b4
. Upon installation of my What's on NPR? shortcut, you'll be prompted to specify this. Unfortunately, retrieving it via NPR's API requires special authorization, for some reason, but – since we're retrieving data from an NPR station's playback widget already configured to use the API – it's actually as easy as opening your browser's “Dev Tools” or showing on your given station's homepage. If you're unfamiliar, here's a handy guide to doing so on some popular desktop web browsers.
Honestly, though, if you're already on your iOS/iPadOS device and you're willing to install a single, free Safari Extension, I believe you'll find Web Inspector to be the single, simplest method of retrieving your station's UCSID.
Finding your station's UCSID with Web Inspector
- Navigate to your station's homepage (ex.
kbia.org
.) - Start playback of the live stream you'd like to query (may or may not be necessary, depending.)
- Open Web Inspector via the Safari Extensions Menu.
- In the
DOM
tab, use the search icon to filter forucsid
. - Your station's UCSID is the value for the
data-stream-ucsid
field.
Depending on how modern your station's website is (I think – I'm supposing, here,) you may or may not find this field. For reference, here is the HTML source of KBIA's webpage from which I drew in its entirety. If you're having trouble, please feel free to contact me however you wish, ideally with your preferred station's identifier/web url.
“Integration” with the Broadcasts app
Broadcasts is a very popular and highly-praised universal Apple application for internet radio streaming. By default, my What's on NPR? shortcut includes an action to begin streaming a station in Broadcasts, but it requires further configuration.
In all likelihood, a search of the Broadcasts Directory for your station's four-letter identifier should yield results. Once you've added your station to your library in Broadcasts, hold its icon (or ^ Tap
) to present the context menu (shown in the screenshots embedded above) and select Edit
. The exact value for the Name
field in configuration menu that results must be supplied as the answer to the second configuration step of my What's on NPR? shortcut. If you do not wish to use Broadcasts, you need only delete or replace its single action in the shortcut's default configuration.
If you've followed along this far, you now have both values you're prompted for at installation of said shortcut, by default: your station's ucsid
and its name in the Broadcasts app. You need only continue if you'd prefer to add options for Apple Music and/or VLC.
“Integration” with Apple Music
If you'd like to have a menu option to begin streaming your NPR station in Apple Music, begin by searching within the app for your station's identifier (as shown in the screenshot embedded above.) Use the triple-dot menu's Share Station
option to copy its Apple Music URL. (WBEZ's, for example, is https://music.apple.com/us/station/npr-news-wbez-chicago/ra.872998937
.) Replace or append to the Broadcasts option with a menu option pointing to an Open URLs action containing the resulting URL. (Refer to my What's on KBIA? shortcut to see this implemented.)
“Integration” with VLC media player
The VLC media player iOS app does not yet have its own Siri Shortcuts actions, but it does have a handy URL scheme which allows one to stream or download the contents of any raw media URL. Using Web Inspector as described above, I was able to find the raw stream URL for KBIA (https://playerservices.streamtheworld.com/api/livestream-redirect/KBIAFM.mp3
) quite quickly in the Resources
tab whilst streaming live.
To add an option to my shortcut to open the stream in VLC, I would add the following value in an Open URLs action:
vlc-x-callback://x-callback-url/stream?url=https://playerservices.streamtheworld.com/api/livestream-redirect/KBIAFM.mp3
Once again, if you have any trouble configuring What's on NPR? – whether that be with finding your station's UCSID and/or “integrating” playback with another app, please do reach out.
Links
- What's on NPR? on RoutineHub
- What's on NPR?'s Issue on my iOS-specific GitHub Repository
- Source-HTML
- Source-JSON
- Source-PLIST