PlanetPress for Life: Getting Song Lyrics Through Web Services

I play bass in a rock band. We cover our own songs but we also do covers of popular songs. When we do, one thing we need is the song’s lyrics, which nowadays is a relatively easy thing to find. We usually search the Internet, find an official or good enough source, then just copy and paste the lyrics on a rich-text editor, apply some styling to fit our needs (bigger fonts for easy reading, etc.) and print it. Since plenty of web sites host a variety of song lyrics, finding lyrics for a given song is not a problem. But even if it only takes about 5 minutes to start with an mp3 and end up with a PDF with corresponding lyrics, it’s still a manual process. Doing this for more than a few songs becomes annoyingly repetitive, long and boring.

In this post, I describe how I resolved this problem with my ideal lyrics generation workflow, one that requires minimal human intervention, one where I simply:

  1. Drag and drop one or several mp3’s in a folder, then
  2. Watch as lyrics for each mp3 are generated and saved as PDF next to each mp3.

In the solution I have implemented, a PlanetPress process reads the mp3 ‘s artist and song name from the mp3’s ID3 tags, then use it to query a lyrics retrieval web service. The returned lyrics are then displayed on a PDF. From a business perspective, a particularly interesting part about this workflow is that it shows how easy it can be to use web services with PlanetPress. From my perspective, it’s just one less boring repetitive task to do.

The Problem

Like I said from the start, getting lyrics is easy because they are widely available on the Internet. This is a great thing, but not for the authors themselves who don’t make any money out of it. To preserve copyrights, actions have been taken to restrict free distribution of lyrics. I totally agree with that, but the consequence is that nowadays, although you can find lyrics on a given web page, those lyrics may not be reliable, just like the web site they are hosted in. Plus, these sites are often plagued with annoying ads, popups and what not. Also, lyrics are not always found in a format that is copy-paste friendly. In the end, retrieving lyrics can be a painful, manual process that, in my case, needs to be repeated over and over again.

1

Just a few more clicks and I get my lyrics! Wait… did I just won something?

The Opportunities

In my search for an automated lyrics-retrieval and formatting workflow, my first idea was to look for a web service that could provide lyrics, hence bypassing all the problems related to the manual acquisition of lyrics with a web browser. In the PlanetPress universe, web services are often used to send documents to archival systems. But there is more than just that. From authorizing a transaction, to creating a barcode, to sending SMS, to finding the weather forecast, to booking flights, applications are almost endless.

PlanetPress can use Web Services

PlanetPress’ SOAP Client plug-in allows a workflow process to use almost any web service. First, we need to make the service’s WSDL file available to the plug-in, by either providing its URL or just a file path if we have a local copy of the WSDL file. The plug-in uses this file to populate the list of possible methods – i.e. tasks that the service can perform –  and parameters for each method. The second step is simply to choose the method, or service we want to obtain. Lastly, we have to populate the input and output parameters for the chosen method.

This web service returns lyrics and an URL for a given artist/song pair.

This web service returns lyrics and an URL for a given artist/song pair.

A Lyrics Web Service

When you want to use a web service, one of the first thing to do is to find it, obviously. While there are standard ways to find them, a lot of reading and browsing may be involved. The terms ‘web’ and ‘service’ are found in so many web pages nowadays that just searching for ‘get lyrics web service’ can lead to a lot of noise in the returned results. So my own trick to find a web service is not to search for ‘web service’, but for a more specific term, ‘WSDL’, that leads me faster to the file that most web service clients need. A WSDL file, which stands for Web Service Description Language, is an XML file describing what the web service can do, and how a web-service client must construct its request so that the server can understand it.

So I googled ‘get lyrics wsdl’ and got what I wanted at the top of search results, from lyrics.wikia.com. The page I got, http://lyrics.wikia.com/server.php?wsdl, describes a free web service to get song lyrics. Plus, they provide plenty of documentation on how to use it. Two methods (that is, actions that the web service can perform on demand) will be useful for my workflow: checkSongExists verifies if a song exists and getSong actually retrieves a song’s lyrics.

DLLs to the Rescue!

In my ideal workflow, no user input should be required except to drop an mp3 into a folder. But the web service I want to use can only retrieve lyrics based on artist and song names, an information that can be read in the mp3’s ID3 tags. So I need PlanetPress to get this information, but there’s no plugin that does this.

3

An mp3’s ID3 can provide several information about a song. I need PlanetPress to get the song’s Title and Album Artist properties.

The ID3 tags of a song can usually be found literally in text format, inside the mp3 file, towards the end of the file. But this information can sometimes be found at the beginning of the file, making an eventual ID3 reading script prone to fail, or else, it would take me too much time to implement. So I’d rather reuse an existing function that does read artist and title information from an mp3 rather than code it myself.  It happens that such a function exists (thank you, Internet), but it is embedded in a DLL that comes with a sound card that I don’t have, so it’s not available on my machine. No problem! The DLL – cddbcontrol.dll – is available online, so I just downloaded and registered it. I could then use the functions in the DLL with the help of some simple VB Script and the PlanetPress Watch scripting object to get access to a process’ job file and set values of local variables.

A VB Script using an external DLL updates 2 Watch local variables and checks if they are empty.

A VB Script using an external DLL updates 2 Watch local variables and checks if they are empty.

The workflow

For each mp3 that I can place in the C:\getlyrics folder, my process first find the artist and song name from the ID3 tags using a script (and the help of an external DLL). The script is also used as a condition, so that if the information is not in the mp3, then a text file is generated indicating that I need to add this information.

Otherwise, the process continues and a first SOAP call to the lyrics web service is made to check whether the song/artist exist in their database. If not, a text file is generated indicating that the song or artist was not found.

Otherwise, a second SOAP Call is made to actually retrieve the lyrics. Again, if no lyrics are found, a text file is generated indicating that the lyrics were not found.

The last part of the process assumes the lyrics were found. It creates a PDF with the same name as the mp3 and saves it in the same folder. A very simple PlanetPress Design document is used to create the PDF.

5

The ‘Generate Lyrics from MP3’ process in action.

The fun

Using the process is easy as pie. Thanks to the input task’s ability to use archive attribute, mp3’s are not moved. They remain in the input folder, but won’t be processed over and over again. If a lyric isn’t found, a text file named after the mp3 indicates the reason why it’s not available. On top of that, finding lyrics for, let’s say, 100 mp3’s, then generating PDFs of each song lyrics now takes a few seconds, a major improvement!

I love PlanetPress.