teaching machines

Homework 3 – What are the Lyrics?

November 6, 2011 by . Filed under cs491 mobile, fall 2011, postmortems.

My app goes and gets lyrics from an API based on what the use specifies for an artist and a song title.  For this I used the API from LyricsWiki.  I used RESTful  service like we did in class but used more of a post to search than a get like we did in class.  I used a receiver that got a JSON from the service then parsed that JSON object in the the usable fields.

The GUI is pretty simple.  The user enters a name of an artist and a song and clicks the submit button.  These are sent as parameters to the API site which returns the lyrics information.  If the fields are left empty or non existent song is entered, I have it defaulted to ignore the case and display an error page.  You are also sent here if you do not have a data connection.

After a successful search, a url is built that has the initial url for the site and the fields from the user are edited and placed into the url.  This returns the artist, song title, lyrics and url to full list in the form of a JSON object that is parsed to grab the information.  This took some playing in the web browser to  determine exactly how things needed to be returned and pulled from the JSON object.  This information is then displayed to the user with a link to the main site so the user can view the entire contents of the lyrics.

Below is how I had to edit the user input and add it to the url so that it could properly be passed.

		final String url = "http://lyricwiki.org/api.php?func=getSong&artist=";
		final String song = "&song=";
		final String format = "&fmt=json";
		
		final String iArtist = intent.getStringExtra("artist").trim().replaceAll(" ", "_");
		final String iSong = intent.getStringExtra("song").trim().replaceAll(" ", "_");
                Bundle bundle = search(url + iArtist + song + iSong + format);