Track songs from the radio with Apple Shortcuts and Notion
The quest for making melodic discoveries from almost any source
Have you ever thought it'd be great to track songs you've heard on your favorite radio stations? Those radio stations might have apps, but there isn't a central place across apps to capture this information.
Find the Radio Endpoint
I live in Philadelphia, so I listen to WXPN most days. To grab the currently playing song, we'll need an endpoint. I looked through the xpn.org network requests when I loaded the page and found the following request URL and associated JSON response:
https://origin.xpn.org/utils/playlist/json/{YYYY-MM-DD}.json
[
{
"artist": "Chuck Prophet",
"song": "Summertime Thing",
"album": "No Other Love",
"timeslice": "2023-07-08 14:10:48",
"image": "https:\/\/i.scdn.co\/image\/ab67616d00001e024377eca4373904f3568c86a6",
"streamPreview": "https:\/\/p.scdn.co\/mp3-preview\/b13357b3791c822c33538cc94d32b45b8def97cb?cid=50356117fdab41979e6d5089fcf2dce4"
},
{
"artist": "Hozier",
"song": "Eat Your Young",
"album": "Unreal Unearth",
"timeslice": "2023-07-08 14:06:50",
"image": "https:\/\/i.scdn.co\/image\/ab67616d00001e024ca68d59a4a29c856a4a39c2",
"streamPreview": "https:\/\/p.scdn.co\/mp3-preview\/d6170162e349338277c97d2fab42c386701a4089?cid=50356117fdab41979e6d5089fcf2dce4"
},
...
]
Setup the Notion Table
Now that we have the source configured to identify the song, let's set up the storage method. I use Notion for most life info tracking so I'll be using a Notion table page (you can apply this same process to any similar app that has an API!)
In the screenshot below, I have a Name text field, Station select dropdown (since I set this up for multiple radio stations), created time (auto-generated) and a formula to create a Spotify search URL for the song:
concat("https://open.spotify.com/search/",replaceAll(replaceAll(prop("Name"), "[,]", ""), " ", "+"), "")
Setup the Apple Shortcut
We have our source and our destination setup; let's configure the Apple shortcut to send the data! I'll link my templated WXPN shortcut here but a quick summary of the steps below:
Import your Notion API key (docs here) and Notion database ID (article here).
Create the URL string via concatenation of the URL, today's formatted date formatted (YYYY-MM-DD), and ".json" to create something like this:
https://origin.xpn.org/utils/playlist/json/2023-07-08.json
URL encode the concatenated string and make the GET request via the "Get Contents of URL" step in Shortcuts (docs here)
Retrieve the "First Item" of the response. This will turn the first JSON object into a native Shortcuts list. Then request two values from the list: "song" and "artist".
Combine the song and artist into a text string like this: "Don't Be Afraid by Honey Dijon" and speak the combined string aloud so you know what the song is!
Create a POST request to the Notion API as we did with the GET request earlier. This time, there will be three special key/value pairs for the header:
Authorization - Bearer {NOTION_API_KEY}
Notion-Version - {2021-05-13 or latest version}
Content-Type - application/json
The request body should be set to File. This will be a JSON object containing the data we want to send to Notion!
{ "parent":{ "database_id":"NOTION_DB_ID" }, "properties":{ "Name":{ "title":[ { "text":{ "content":"Combined Text" } } ] }, "Station":{ "select":{ "name":"WXPN" } } } }
You're Done!
That's it! Now you can activate this shortcut via iPhone, Siri, Apple Watch or any other device that can run Apple Shortcuts. I've replicated this for a simple Shazam storage shortcut (template here).
Improvements? You might want to add in some error handling if you think you'll need it. And if you're replicating this for other stations, you might need to parse the response data in different ways. Happy listening!