Using the Last.fm and MusicBrainz APIs

I am quite pleased with my app that uses the Spotify Web API for creating data visualizations using the popularity data of artists, albums, and tracks. That popularity score, however, is a relative number so I can’t truly compare much in a useful way, however pretty my UX is.

Now is the time on Sprockets where we start a new project using the Last.fm API to get real, quantifiable data — the number of listeners for each entity (artist, album, track) and playcount for each. I’m very interested to find how those numbers differ.

Spotify and the Spotify Web API make it very easy to get ID numbers for each artist, album IDs for each artist and track IDs for each album. In fact, the documentation shows they might even be making an effort to be stupid. The example URL in their documentation for getting info about an artist is:

/2.0/?method=artist.getinfo&artist=Cher&api_key=YOUR_API_KEY&format=json

So any spelling errors or similar names will make your life miserable. Fortunately, their database uses (for the most part–I’ll get to that in a moment) the mbid or MusicBrainz ID for everything so you can, instead, write the above like this:

/2.0/?method=artist.getinfo&mbid=bfcc6d75-a6a5-4bc6-8282-47aec8531818&api_key=YOUR_API_KEY&format=json

Unfortunately, there’s no Last.fm equivalent to Spotify‘s utterly delightful endpoint for getting all albums by an artist:

/artists/{id}/albums

Fortunately, the MusicBrainz API has such an animal but it’s a little more complicated and it took me a bit of trial and error to figure out quite how it works. I’d like to share it with you. Here are the steps I’ll need to complete to get all of the information about an artist, their albums, and the tracks from those albums with an extra curveball just to make it fun.

Step #1 – Search MusicBrainz.org for the desired artist

In this case, I chose Alice Cooper.

aliceCooperSearchResults.png

For the uninititated, not only would using the search term “alice cooper” bring up tribute bands but the fans (I count myself among them) who insist on differentiating between the group and the solo artist mean I have to use not one but two MBID numbers for this single artist.

Step #2 – Get the Artist’s MBID from MusicBrainz

Click the artist name in the search results then click the Details tab on the artist page.

aliceCooperDetailsTab.png

Step #3 – Get the Artist’s release-groups from MusicBrainz

Copy the artist MBID and paste it into a MusicBrainz web service URL using the artist entity and a ?inc=release-groups parameter like so:

/ws/2/artist/ee58c59f-8e7f-4430-b8ca-236c4d3745ae?inc=release-groups&fmt=json

to get a list of “release groups.”

AC_MB_info_browser.png

I broke up with Dreamweaver a while back, dumping it for the far smarter, cuter, cooler VS Code but ol’ DW will always have a special place in my heart because of cool commands like Edit > Code > Apply Source Formatting which does this:

beforeAfter.png

Remember, you have to do that twice for Alice Cooper. Because we, his fans, are pricks like that.

Step #4 – Get the Artist’s Releases from MusicBrainz

A release is an album — like Zipper Catches Skin or Billion Dollar Babies. A release group is all editions and versions of that album. To see exactly what that means, we copy the id for the Constrictor release-group from line 26 in the above image and construct the URL below using the release-group entity and inc=releases parameter.

/ws/2/release-group/24c4fdde-4494-3837-a288-5b4fdbe966eb?inc=releases&fmt=json

That gets us all six releases in the Constrictor release-group:

  • United States with “packaging”: “Cardboard/Paper Sleeve” (a vinyl record)
  • United States with “packaging”: “Jewel Case” (a CD)
  • Japan CD
  • United States with “packaging”: “” (digital?)
  • Germany with “packaging”: null
  • United Kingdom with “packaging”: null

I don’t know what null packaging means.

The first time I get data from Last.fm, I’ll try all of these and hypothesize “Cardboard/Paper Sleeve” will have a zero playcount.

Step #5 – Get a Release’s Recordings from MusicBrainz

A recording is a “track.”

Construct a URL using the individual release entity and inc=recordings parameter.

/ws/2/release/1189de93-7e9f-3b47-a9df-e2599e62f75d?inc=recordings&fmt=json

The UK release of Constrictor has 10 tracks. There will probably never be a deluxe or remastered edition. Which is a damn shame.

Step #6 – Get an Artist’s data from Last.fm

Using the artist MBID, method=artist.getinfo, and an API Key as parameters, assemble a Last.fm URL like so:

/2.0/?method=artist.getinfo&mbid=ee58c59f-8e7f-4430-b8ca-236c4d3745ae&api_key=YOURAPIKEY&format=json

The resulting JSON for Alice Cooper the man includes a bio, birthday, similar artists, genres, and–for me–the important bit:

"stats": {
"listeners": "1362113",
"playcount": "31011489"
}

You’re dying to know how that compares to Alice Cooper the group, amiright?

"stats": {
"listeners": "1362113",
"playcount": "31011489"
}

Well, check that shizzle out! We only need to run what will be this query once for Alice Cooper! Both MBIDs get the exact same data. Wanna know something nerdy and cool?

The artist entity URLs I used earlier to get the release groups differ …

  • Alice Cooper the person has a gender of “male.” Alice Cooper the band has a gender of “null.”
  • The person has a “begin_area” of Detroit, MI while the band has Pheonix, AZ
  • The band has a life-span of 1964-1975 with “ended”: true while the person’s life-span begins with “1948-02-04” and ends with “null” and “ended” is false.
  • Type properties are “group” and “person”

Step #7 – Get Album Info from Last.fm

We’ll go with Constrictor again. Using album.getinfo this time.

/2.0/?method=album.getinfo&mbid=1189de93-7e9f-3b47-a9df-e2599e62f75d&api_key=YOURAPIKEY&format=json

  • listeners: 64,771
  • playcount: 545,070

For comparison (the entire purpose of this whole exercise), let’s also get Billion Dollar Babies:

Well, I’ll be horn-swaggled! There were three Billion Dollar Babies release-groups in my JSON file but none of their IDs worked so I searched at MusicBrainz and got the actual mbid for the release-group which had 13 releases in it! How do you pick? Eventually, I’ll get all of them but …

First choice didn’t work … this is going to get tedious …

Okay, second try gets me some stats

  • listeners: 169,768
  • playcount: 1,222,112

Yeah, see that’s a significant difference.

Step #8 – Get Track Info from Last.fm

I went for “The World Needs Guts” from Constrictor using the track.getInfo method as a parameter.

/2.0/?method=track.getInfo&mbid=70bd458f-c62d-4014-99e7-233c3c0b8f96&api_key=YOURAPIKEY&format=json

  • listeners: 11,332
  • playcount: 38,656

Which I’m sure is tiny crumbs compared to even one instance of “School’s Out” let alone adding all of the recordings of “School’s Out” together.

Conclusion

It will take me a lot longer to get the data from Last.fm that I need than it does to get data from Spotify but it will also be data I can use!

Advertisements

Lost My iShizzle

The iMac has been freezing lots again. So I updated El Capitan — not to Sierra, just updated the Capitan. Googling Sierra tells me there’s lots of freezing for that, too. Perhaps I should have stayed with Mavericks. Man … I used to be such an early adopter. All through the first several “cat” years of OSX.

Updating from .11 to .12 didn’t seem to work. Perhaps because the machine is so glitchy.

So I referred back to my Adobe CC and El Capitan post hoping those steps would help as much as they did almost a year ago. If memory serves, this nonsense also happened last time I was about to start some contract work.

Not only did it not work, but now the iMac dies during every attempt at rebooting. The progress bar hangs at about 50% for a bit, then the machine completely dies.

Trying First Aid in Recovery Mode

There are two “things” on the left (the second thing is an “image”) and each has a sub-thing. Three of them pass First Aid just fine but the first “sub-thing” (Macintosh HD) fails.

I tried using the Terminal in Recovery Mode to Repair Permissions but Ye Olde Terminal tells me there’s no such command as “sudo.” This worked like a charm last time. Is it because I updated? Or is the machine broken? As an experiment, I tried another command (I can’t remember now) which it also didn’t recognize. It did recognize “ls.”

One post I read said one could Reinstall OSX in recovery mode and it wouldn’t delete your files and such (I should really start using the external HD I have that sits next to the iMac) but when I tried that, it told me the disk was locked.

I found a couple great, in-depth posts somewhere and tried many of the suggestions with no luck.

No Genius Bar Love

Setting an appointment online is impossible. Remember when apple.com was considered one of the best-designed sites on the web? The most (but definitely not the only) infuriating thing about trying to set an appointment using their website is, upon clicking the desired time, I receive an error alert stating, “You haven’t entered a valid email address.” There is NO form or field for entering an email address.

Setting an appointment via phone is impossible. I call the store. Of course the voice recognition system doesn’t recognize anything I say. Eventually, it transfers me to Apple Care and starts asking me more questions about unrelated crap and doesn’t understand my answers.

Setting an appointment in person is stupid. You can’t drop off your computer and have them diagnose and/or repair it. You have to make an appointment to drop it off. You have to drive to the mall, make the appointment and then, later, go back to your car or back home, and get your computer.

It’s the Economy, Stupid

All these people who are unemployed. But businesses like Apple can’t afford to hire any humans to answer the phone in their stores? Walmart can’t find anyone qualified to operate more than three cash registers at a time?

Buy Local

Which brings me to the new computer repair shop on the corner … which brings me to my next post …

Gratitude

Fortunately, my “stupid day job” that I constantly complain about provides me with a laptop loaded with Adobe CC, etc. so I can still do my side job … every day I find another reason I should really be grateful for my “stupid day job” but I just can’t. Something’s wrong with me.

Is WordPress Trying to Suck?

I’m not one to complain, say, whenever something about Facebook changes. It’s free and we, the users, are not their customers — we’re the vendors who pay them with our data so we can use their free service and they can then sell our data.

On the other hand, I do feel like I’m a WordPress customer although I couldn’t really justify why I think that. Regardless, WordPress has become continually crappier over time. One frustrating, sometimes infuriating, change at a time I’ve grown to hate using it for blogging almost as much as dealing with it when potential clients ask me to help them with web design/dev and then, AFTER I agree, reveal they use WordPress instead of having an actual website.

Tabs vs Spaces Personal Preferences

I’ve always preferred tabs. While binge-watching Silicon Valley, I was totally on Richard’s side … at first.

Then I thought, “But wait, if I used spaces, I might not have that problem of my code getting all ugly and confusing when I switch editors (because I work on three different machines). Just as I finished that thought–while Richard and Winnie were breaking up over it–Winnie says, “because it could look different on other people’s computers.”

So, Facebook … I’m totally smart enough to work there. Call me.

Oh my gosh … of course, someone posted just that scene on YouTube.

winnie.png

I do hope Hubert Applebaum‘s profile pic is actually him:

comments.png

Anyway, I finally took a look at the Preferences in my various apps and learned a couple things. If, like me, this is fairly new to you, here’s how to changes the relevant prefs in your editor(s).

AtomPrefsLaptop.png

I was giddy with glee that I also found the settings for Soft Wrap in Atom and Word Wrap in Sublime Text.

SublimeText_Mac.png

Another pleasant surprise was discovering SublimeText’s “use tab stops” setting. It’s been a source of frustration to press tab to insert tabs only to have backspace move one space at a time.

Dreamweaver 2015‘s prefs confused me, however.

DW2015_home.png

Indent and Tab Size appear to be two different things. Are they different in those other editors? If so, can I control them there as well? Because, dude, that would ruin all this new joy if the tabs didn’t match up with wherever the cursor/indenting landed whenever I press Enter/Return. Why would you ever want them to be different?

For the curious, Dreamweaver 2017 has some additional settings:

DW2017_work.png

Speaking of differences between Adobe CC 2015 and 2017 … BEWARE! Prepare yourself by backing up all your prefs and such.

I use 2017 at work. Because when IT installed the updates (this is the strictest organization I’ve ever worked with when it comes to how locked down the computers are), it didn’t just update the apps, it “upgraded” them from 2015 to the all new 2017 … which completely wiped out all my custom settings and preferences in Photoshop. I was not happy. I’m now resetting all my shortcuts, workspaces, etc. as I need them. Dreamweaver remembered all of my custom shizzle but, for the first time in fifteen years, Dreamweaver got some significant changes and those changes make using it a drag so I definitely won’t be updating/upgrading at home.

I think it’s worth mentioning that if Atom would get it’s freezing & crashing under control, I’d never use another editor and none of this would even matter.

On another related note, Google just announced you can no longer email JavaScript files as attachments and suggest we use Google Drive or DropBox. So, these tab/spaces preference settings I’ve just learned may be moot. I may just start working on my laptop even when home or on lunch at work (where we are forbidden to access Google Drive or DropBox).

I find this decision quite irritating. Because of every idiot who ever invited a virus or bit of malware onto their computer or their employer’s network, I have to suffer. This isn’t the first time some browser people have made decisions for me that cause me pain and suffering the likes of which refugees never have to endure.

Chrome has always automatically updated Flash which caused problems at two separate employers. Meanwhile, Firefox makes you approve every flash-based thing … except, of course, any advertising. Ads get through just fine.

I’d love if I could wirelessly connect my laptop to my Mac and work laptop. I’m fairly sure I can do the (Linux) laptop and Mac but, of course, there’s no way for me to get past whatever security nightmare is on my work computer.

Another thing I hate about Adobe CC 2017 apps is a Articulame Stupidline feature they’ve adopted. When I launch an app, I click the icon/shortcut and then go back to whatever app I was using while I wait for the new app to finish launching. Storyline has always refused to stay in the background, however, jumping in front of whatever you’re using, forcing you to stop and send it to the background a time or two. This is in addition to the fact that you never know which monitor it will open on so it’s not like you can prepare. Regardless of the monitor you had it in last time you used it, it’s either random or decides to open where you don’t want it just to be a dick. Oh, and let’s not forget that after you move it, you then have to click the minimize/maximize button (it won’t minimize or maximize the window, it just changes the button to a maximize button), maximize it (which doesn’t maximize it but puts it in full-screen mode), minimize it (which doesn’t minimize it but puts the window back the way it already was, floating above the desktop), and maximize it (this time it actually means maximize) before you can use it. Have I ever mentioned what a piece of junk Storyline is?

Historically, Adobe products stay patiently and obediently in the background while launching. Now, they’re even more persistently obnoxious than Storyline. After a click or two, Storyline stays in the background. Thus far, Photoshop, Illustrator, and Dreamweaver and like self-aware … cats! They’re like cats pacing across the keyboard and in front of the monitor no matter how many times you (gently and lovingly, at first) set them aside.

Aptara Makes Me Feel Good Inside

Aptara is the only software company I’ve ever received a Christmas card from.

card.png

When I clicked it to download it (so I could put it in this post), it opened this …

animated.png

It plays music while snowing (animated) and when you move your pointer, it changes the direction of the “breeze.”

Does this qualify as a good “user experience”?

UXUI Hall of Fame Welcomes Instagram

Their login form tells you into which field you typed incorrect info:

user-name.png

pw.png

As someone who uses multiple usernames and passwords, this makes my life so much easier and happier.

Just as with my gratitude for the IE feature mentioned in the linked post below, good UXUI is all about the little things that make the experience just a little bit better. Crimes against UXUI, however, seem to disproportionately make users much, much more miserable.

See Also:

UX/UI Upvotes #2: IE in Windows

Yes, you read that correctly. Nope, it’s not trolling click-bait. There is one Internet Explorer feature in Windows that I love and my default browser for Mac and Ubuntu does not.

In those latter operating systems, I have to click each tab (if it’s not the active tab) to reveal the close button and then click each close button. That’s two clicks per tab. Ew.

closeButt.png

In Internet Explorer (shudder), I need only hover my pointer over the unwanted tab and click the close button that appears. Yay. Shame on Firefox! Shame! Nothing in IE should ever be better than Firefox.

There used to be another feature in Windows that I was always surprised reigned supreme over Mac … ooh, I should put that in another post …