Permalink
Browse files

Now handles artist names containing & properly

  • Loading branch information...
IsakUlstrup committed Jun 8, 2011
1 parent f026b6e commit 63c7c662b33687661b387b56cd8f5a903c86c843
Showing with 7 additions and 3 deletions.
  1. +1 −0 css/style.css
  2. +6 −3 js/script.js
View
@@ -28,6 +28,7 @@
.face img {
-webkit-box-shadow: 0px 1px 5px #000;
+ /*border: 1px solid rgba(255, 255, 255, 20);*/
-webkit-border-radius: 6px;
}
View
@@ -11,6 +11,10 @@ apiKey = "35b4dede2f4807b7ec1c4698bad28897";
/* Get a random image of the artist from last.fm */
function getImage(artist, obj) {
// TODO: encode artist name correctly %26 %20 etc.
+ // Encode artist name
+ artist = artist.replace('&', '&');
+ artist = encodeURIComponent(artist);
+ Bowtie.log("Fetching image of: "+artist);
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=artist.getimages&artist="+artist+"&api_key="+apiKey+"&format=json&callback=?", function(data) {
// If there is an error with the request
if (data.error) {
@@ -57,7 +61,7 @@ function toggleHUD(prop){
*/
function trackChanged(theTrack) {
// Display track meta data
- if (theTrack) {
+ if (theTrack && theTrack.title) {
$('#trackName').html( (theTrack.title) ? theTrack.title : 'No title' );
$('#artistName').html( (theTrack.artist) ? theTrack.artist : 'No artist' );
$('#albumName').html( (theTrack.album) ? theTrack.album : 'No album' );
@@ -66,10 +70,9 @@ function trackChanged(theTrack) {
$('#artistImg').attr('src', 'img/loading.png');
getImage(theTrack.artist, $('#artistImg'));
- Bowtie.log("Fetching image of: "+encodeURI(theTrack.artist));
} else {
- $('#artistImg').attr('src', 'img/nothing.png');
$('#albumArtwork').attr('src', 'img/nothing.png');
+ $('#artistImg').attr('src', 'img/nothing.png');
}
}

0 comments on commit 63c7c66

Please sign in to comment.