-
Notifications
You must be signed in to change notification settings - Fork 0
/
getArtistInfo.php
executable file
·69 lines (64 loc) · 2.29 KB
/
getArtistInfo.php
1
<!-- BACHELOR PROJECT Summer semester 2013 Martin Hellwagner (0956048)--><html><head><title>Bachelor project</title><meta charset="utf-8"><script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script><script type="text/javascript">// preparing datafunction getArtistInfo(artist) { var key = "d24f248c65bb443e1dbe4b8178350f9d"; var artistCorrected = artist.replace(new RegExp("&", "g"), "and"); artistCorrected = artistCorrected.replace(new RegExp(" ", "g"), "+"); var url = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" + artistCorrected + "&api_key=" + key + "&autocorrect=1&format=json"; fetchArtistInfo(url);}// fetching artist information from last.fm APIfunction fetchArtistInfo(url) { $.ajax({ url: url, async: false, dataType: "json", success: function(data) { if (data.error != null || data.artist.name == "" || data.artist.mbid == "") { artistInfo[0] = new Array(-1, null, null, null); } else if (data.artist.name != "" && data.artist.mbid != "") { var name = data.artist.name; var id = data.artist.mbid; if (id == "24b930c0-5f27-4723-a5aa-3b8b830fb914") { id = "c85cfd6b-b1e9-4a50-bd55-eb725f04f7d5"; } var onTour = data.artist.ontour; var genre = data.artist.tags.tag[0].name.split(" "); if (genre == "german" || genre == "swedish") { genre = data.artist.tags.tag[1].name.split(" "); } var genreCorrected = ""; for (var i = 0; i < genre.length; i++) { if (genre[i] != "and") { genre[i] = genre[i].charAt(0).toUpperCase() + genre[i].slice(1); var chars = new Array("-", "/"); for (var j = 0; j < chars.length; j++) { var index = genre[i].indexOf(chars[j]); genre[i] = genre[i].slice(0, index + 1) + genre[i].charAt(index + 1).toUpperCase() + genre[i].slice(index + 2); } } genreCorrected += (genre[i] + " "); } genreCorrected = genreCorrected.substring(0, genreCorrected.length - 1); artistInfo[0] = new Array(name, id, genreCorrected, onTour); } checkInput(artistInfo, 1); } });}</script></head></html>