This Week's Sponsor:

Kolide

Ensure that if a device isn’t secure it can’t access your apps.  It’s Device Trust for Okta.


Apple Music Wrapped: A Shortcut to Visualize Your Most Listened Songs, Artists, and Genres of the Year

When Spotify was my music streaming service of choice, one of the features I really liked was its personalized Wrapped report generated at the end of the year. I’ve always been a fan of geeky annual reports and stats about the usage of any given web service – be it Spotify, Pocket, or Toggl. I appreciate a detailed look at 12 months of collected data to gain some insight into my habits and patterns.

I’ve always been annoyed by the lack of a similar feature in Apple Music; I’m surprised that Apple still hasn’t added a native “Year in Review” option – a baffling omission given how the company is already collecting all of the necessary data points in the cloud. Official “Apple Music Wrapped” functionality would bolster the service’s catalog of personalized features, providing users with a “reward” at the end of the year in the form of reports and playlists to help them rediscover what they listened to over the past year.

But Apple doesn’t seem interested in adding this feature to Apple Music, so I decided to build my own using Shortcuts. The result is the most complex shortcut I’ve ever created comprising over 540 actions. It’s not perfect due to the limitations of iOS and Shortcuts, but it’s the closest I was able to come to replicating Spotify’s excellent Wrapped feature.

Apple Music Wrapped

As always, let’s take a look at the final result before examining some of the underlying details and limitations of the shortcut.

Apple Music Wrapped generates a personalized music report that, by default, collects your 100 most-played songs added to your library in any given year since Apple Music was launched in 2015, sorting them from largest to smallest play count. The shortcut takes less than 30 seconds1 to run and the final report is opened in Safari as a custom webpage.

Replay

Using data natively exposed from Apple Music to Shortcuts on-device, Apple Music Wrapped creates personalized reports featuring the following items:

  • Most listened song of the year
  • Top 10 songs2
  • Most listened artist of the year
  • Top 5 artists
  • Favorite genres
  • A “top nine” image based on the artwork for your most listened-to songs
  • Stats for play counts, listening time, and total duration of top songs
  • Full list of your top 100 songs

Thanks to Shortcuts’ ability to create offline webpages with custom HTML, CSS, and JavaScript, I was able to style the resulting webpage using elements from Apple Music’s website; there’s even an embedded Apple Music widget that lets you preview your top song of the year in the browser.3

Furthermore, Apple Music Wrapped can:

  • Analyze an arbitrary number of songs (50, 200, 500, etc.)
  • Generate reports for any year from 2015 onward
  • Create a PDF version of the report
  • Create a new playlist in Apple Music with your top 25 songs of the year

There is essentially no configuration needed to run Apple Music Wrapped on an iPhone or iPad. Upon installing the shortcut, you’ll be presented with two Import Questions to change the number of songs to analyze and the year for which you want to generate a report. By default, the shortcut evaluates your 100 most-played songs added to your library in 2018. If you use Apple Music but never add songs to your library, this shortcut won’t generate a report. Also, for the best experience, I recommend running this shortcut toward the end of the year (for reasons I’ll detail later).

If you want to change the song and year values, you’ll find two variables near the top of the shortcut that you can modify.

You can modify the main two variables upon installing the shortcut...

You can modify the main two variables upon installing the shortcut…

...or later inside the shortcut itself.

…or later inside the shortcut itself.

You don’t need to change anything else. For the shortcut to work, however, you’ll have to grant Shortcuts access to your Apple Music library and notifications, which will be used to communicate progress while the shortcut is running.

Local notifications are used to display progress while the shortcut is running.

Local notifications are used to display progress while the shortcut is running.

You’ll be asked two questions while your Apple Music Wrapped report is being built. First, you’ll be able to choose whether or not you want to create a playlist containing your Top 25 songs of the year; if you accept, the shortcut will create a new playlist in the Music app. To skip the playlist, tap ‘Nope’ and continue.

The Top 25 playlist created by Apple Music Wrapped.

The Top 25 playlist created by Apple Music Wrapped.

Second, toward the end of the shortcut you’ll be given the option to save a PDF version of the report either in the Files app or Dropbox. Again, tapping ‘Nope’ will continue the shortcut without consequences. Because Shortcuts is creating a webpage and sending it to Safari with an extremely long URL scheme (more on this below), you’re going to have to wait a few seconds after Shortcuts launches Safari for the full report to be displayed.

I don’t want to get into all the technical details and challenges I faced when building Apple Music Wrapped, but it is, by far, the most advanced and complex shortcut I’ve ever shared here on MacStories. I had to come up with JavaScript-based hacks for sorting numbers and string de-duplication (without actually showing Safari inside the shortcut!), and I figured out a way to load artist profile pictures from the Apple Music CDN (which is not natively supported by Shortcuts). The shortcut tries to “fail gracefully” as much as possible, and there are dozens of instances where I had to rely on regular expressions or embedded CSS to prepare the final report.

I’ve been working on this shortcut every day for the past couple of months, and I tried to comment every sequence of actions for clarity and future-proofing. While I’m sure I forgot about some weird edge cases (and if you run into issues, please let me know), I’m happy about the fact that this shortcut runs fast, has no external dependencies, and doesn’t save any additional configuration/cache files in the user’s iCloud Drive account.

With this in mind, allow me to clarify a few important points about issues and limitations that are unfortunately outside of my control.

Limitations and Other Details Worth Knowing

Apple Music Wrapped pushes the limits of what is possible to achieve with the ‘Find Music Where…’ and ‘Open URLs’ actions of the Shortcuts app. In the past few weeks, I (and other testers) have run into limitations and inconsistencies worth pointing out both for MacStories readers and Shortcuts engineers at Apple.

First and foremost, you’ll find that running the shortcut for the same number of songs and the same year multiple times may result in slightly different counts for top artists and songs. This is due to the fact that the ‘Find Music Where’ action doesn’t always return the same set of items when filtering your music library. This problem also applies to play counts: it appears that Shortcuts’ Music actions only count a song as played if it’s been played in full without skipping, but in my experience, these counts may also be different across devices or inconsistent across different runs of the shortcut. I brought all of these issues to the attention of the Shortcuts team at Apple, and I hope they’ll be able to ship more flexible and reliable Apple Music filtering actions in the future.

Everything revolves around this initial filtering action.

Everything revolves around this initial filtering action.

The other big limitation of Apple Music Wrapped is that it relies on a memory-intensive workaround to open a custom webpage in Safari – that is, it loads a webpage using a data: URL that contains a long base64-encoded representation of the HTML page. This text string includes image assets and JavaScript code as well. For this reason, two things may happen:

  • You may receive a “Couldn’t communicate with a helper application” error message at the end of the shortcut. My understanding is that this is a memory-related issue. Usually, you can “fix” it by force-quitting Safari, the Shortcuts app, or both, and trying to run the shortcut again.
  • After running the shortcut a few times and generating multiple reports, you may notice slowdowns when typing search queries in the Safari address bar. My guess is that this is happening because Safari keeps the long URLs used to assemble custom webpages in its history. Once you’re done with the Apple Music Wrapped reports you want to see, I highly recommend clearing your Safari history and website data on all your devices. Everything would be so much easier if only Safari for iOS could open plain .html files like it can on macOS.

In my tests over the past few weeks, these were the issues that often came up when running the shortcut, which I’m afraid I can’t fix myself for now. There are also other smaller annoyances beyond my control worth noting:

  • Apple Music Wrapped filters songs based on the year they were added to your music library. If you just search and stream songs without saving them to your library, the shortcut won’t find them. Because the shortcut looks for songs that were added between January 1 and December 31 of a specific year, it’s primarily designed to give you an overview of new songs that you listened to in the past 12 months.
  • Play counts are not specific by year. To my knowledge, there is no way in Shortcuts to say “give me the number of times this song was played in this time period” (if I missed this, please let me know). This shouldn’t be a problem for the 2018 report and future reports if you run them toward the end of each year, but may result in inflated play counts for songs in older reports (2015-2017).
  • If the shortcut finds a song in your library that isn’t available on the iTunes Store because you uploaded it from your computer, it will not be linked in the Top 10 Songs list (as there’s no iTunes link for it to begin with). In theory, this shortcut should work for locally-uploaded tracks if you never add anything from the Apple Music service, but I haven’t been able to test it under such conditions.
  • The “duration is longer than 30 seconds” song filter just doesn’t work. I wanted to exclude interludes and other short non-song tracks that are often present in albums, but the ‘Find Music Where’ action returns them anyway. Oh well.
  • The Top 25 playlist can’t be automatically shared by Shortcuts with a link. If you want to share it with others, you’ll have to do so manually.

Apple Music Wrapped is the shortcut I’m most proud of, but it’s also one I hope Apple sherlocks as soon as possible. There’s only so much data I can parse with Shortcuts’ (buggy) Apple Music actions; ideally, Apple should copy Spotify’s approach and build their own report with more precise stats for songs and genres, details about devices you listened on, days of the week when you’re the most active, and so forth. I look forward to the day when, at the end of the year, Apple Music will send me a personalized report with a detailed, in-depth look at my listening habits for the past year.

Until that happens, Apple Music Wrapped should be a pretty good workaround to quickly visualize songs, artists, and genres that defined your past 12 months in Apple Music. I had fun analyzing my music habits with this shortcut, and I hope MacStories readers can find it useful too. You can download it below.

Apple Music Wrapped

Create a detailed report for the music you’ve listened to in the past year. The shortcut can optionally create a Top 25 playlist for your most played songs and generate a PDF report. The shortcut is primarily designed for Apple Music subscribers.

Get the shortcut here.


  1. When activated from the main Library view of Shortcuts. ↩︎
  2. By default, the shortcut searches for songs in your Top 10 using the United States iTunes Search API. If you want results for a different country, change the ‘Search iTunes Store’ actions accordingly. ↩︎
  3. You can actually log into your Apple Music account from the report webpage and listen to the song in full from the widget. ↩︎

Unlock More with Club MacStories

Founded in 2015, Club MacStories has delivered exclusive content every week for over six years.

In that time, members have enjoyed nearly 400 weekly and monthly newsletters packed with more of your favorite MacStories writing as well as Club-only podcasts, eBooks, discounts on apps, icons, and services. Join today, and you’ll get everything new that we publish every week, plus access to our entire archive of back issues and downloadable perks.

The Club expanded in 2021 with Club MacStories+ and Club Premier. Club MacStories+ members enjoy even more exclusive stories, a vibrant Discord community, a rotating roster of app discounts, and more. And, with Club Premier, you get everything we offer at every Club level plus an extended, ad-free version of our podcast AppStories that is delivered early each week in high-bitrate audio.

Choose the Club plan that’s right for you:

  • Club MacStories: Weekly and monthly newsletters via email and the web that are brimming with app collections, tips, automation workflows, longform writing, a Club-only podcast, periodic giveaways, and more;
  • Club MacStories+: Everything that Club MacStories offers, plus exclusive content like Federico’s Automation Academy and John’s Macintosh Desktop Experience, a powerful web app for searching and exploring over 6 years of content and creating custom RSS feeds of Club content, an active Discord community, and a rotating collection of discounts, and more;
  • Club Premier: Everything in from our other plans and AppStories+, an extended version of our flagship podcast that’s delivered early, ad-free, and in high-bitrate audio.