The Challenge
Here was the challenge: I recently started at a new company that lives in the Office365 ecosystem. I’m part of a fairly small internal team, but we’re growing. Part of our growth is creating culture and setting processes. To that end, I endeavored on what is a seemingly pointless journey to display my currently playing track as my Teams status. Necessary? No. Tone-setting, inviting and culture-building? Yes.
The Landscape
There are good resources for setting your Slack status from Spotify, or even your Teams status from Spotify. In fact, I relied heavily on Loryan Strant’s work, as well as work from DamoBird, Luise Freese, and That API Guy.
The shortcoming, however, lies with Apple Music. While Apple Music has an API, access costs $99/annually through their developer program.
Enter Last.FM
A blast from the past, I recalled my ages-old Last.FM account, which used to provide analytics on user listening data long before Spotify was a twinkle in a coder’s eye. Luckily, Last.FM is alive and well, and has an open and free-to-use API program. Apple Music > Last.FM > Power Apps Custom Connector > Power Automate Flow.
It took me a few days, but I stumbled blindly through the process, and figured out how to make it work. I will not document the entire process, because Loryan and Luise did so masterfully on their aforementioned posts, but I will document what differs for your viewing here…
The Schema/JSON
Setting up the custom connector was easy enough after creating a Last.FM API account. Specifically, I used the user.getRecentTracks request, limiting the response to 1 (the most recently played/currently playing), and formatting that response in JSON.
Here is the raw output of that request, for your reference:
{
"recenttracks": {
"track": [
{
"artist": {
"mbid": "",
"#text": "Jess Bays"
},
"streamable": "0",
"image": [
{
"size": "small",
"#text": "https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png"
},
{
"size": "medium",
"#text": "https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png"
},
{
"size": "large",
"#text": "https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png"
},
{
"size": "extralarge",
"#text": "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png"
}
],
"mbid": "",
"album": {
"mbid": "",
"#text": "Temptation (feat. Poppy Baskcomb) - Single"
},
"name": "Temptation (feat. Poppy Baskcomb)",
"@attr": {
"nowplaying": "true"
},
"url": "https://www.last.fm/music/Jess+Bays/_/Temptation+(feat.+Poppy+Baskcomb)"
},
{
"artist": {
"mbid": "82e454e2-38ee-4e69-89a6-cc65167753d1",
"#text": "Chase & Status"
},
"streamable": "0",
"image": [
{
"size": "small",
"#text": "https://lastfm.freetls.fastly.net/i/u/34s/a4bd5cb7c9b497d912c43802a40ad380.jpg"
},
{
"size": "medium",
"#text": "https://lastfm.freetls.fastly.net/i/u/64s/a4bd5cb7c9b497d912c43802a40ad380.jpg"
},
{
"size": "large",
"#text": "https://lastfm.freetls.fastly.net/i/u/174s/a4bd5cb7c9b497d912c43802a40ad380.jpg"
},
{
"size": "extralarge",
"#text": "https://lastfm.freetls.fastly.net/i/u/300x300/a4bd5cb7c9b497d912c43802a40ad380.jpg"
}
],
"mbid": "",
"album": {
"mbid": "",
"#text": "What Came Before"
},
"name": "Mixed Emotions",
"url": "https://www.last.fm/music/Chase+&+Status/_/Mixed+Emotions",
"date": {
"uts": "1650469597",
"#text": "20 Apr 2022, 15:46"
}
}
],
"@attr": {
"user": "psprague",
"totalPages": "32759",
"page": "1",
"perPage": "1",
"total": "32759"
}
}
}
Power Automate Flow
My power automate flow is generally the same as Loryan and Luise, with a few exceptions I’ll outline below.
As with the examples I started with, my flow runs every five minutes during business hours, M-F. “Get Tracks 2” pulls the response from Last.FM via my custom connection. Then, I parse the JSON.
Next, I’ve asked the flow to get the time 6 minutes in the future. Because Last.FM doesn’t provide time remaining in the track, I needed a general way to tell the flow to reset my status if I was NOT listening currently. Since the flow runs every 5 minutes, if I have gone 6 minutes without a new track, it will reset to a blank status. More on that in a minute.
Next, the flow grabs the parsed JSON body, and does some conditional rules. Last.FM does provide a “nowplaying” tag. However, I struggled to get the flow to properly apply the conditions that Loryan and Luise used (if “nowplaying” is equal to “true”, do this, etc.) This was largely a limitation from my lack of knowledge and skill. So, I’m leaning on the time expiration instead. As long as a new song is playing every 5 minutes, the flow will continue to update my status. If not, my status expires after 6 minutes.
It’s simple, inelegant, and I’m sure largely inefficient. But it was fun, and I’m glad I did it! Let me know if you have questions!