Skip to content

Commit

Permalink
Added tendency, musicmetric API
Browse files Browse the repository at this point in the history
  • Loading branch information
Amos Wenger committed Jun 17, 2011
1 parent 9c4d834 commit 7a144c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script type="text/javascript" src="https://raw.github.com/officialfm/officialfm-javascript/master/officialfm.js"></script>
<script type="text/javascript" src="mhd.js"></script>

<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<title>JSMAD - 100% JavaScript MPEG Audio Decoder</title>
</head>

Expand Down
32 changes: 30 additions & 2 deletions mhd.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ function usePlayer (player) {

id3string += "</div></div>";
id3string += "<div class='info'>";
id3string += "<h2>" + (ofmTrack ? ofmTrack.title : id3['Title/Songname/Content description']) + "</h2>";
id3string += "<h3>" + (ofmTrack? ofmTrack.artist_string: id3['Lead artist/Lead performer/Soloist/Performing group']) + "</h3>";

var artist = ofmTrack? ofmTrack.artist_string: id3['Lead artist/Lead performer/Soloist/Performing group'];
id3string += "<h2 id='track_span'>" + (ofmTrack ? ofmTrack.title : id3['Title/Songname/Content description']) + "</h2>";
id3string += "<h3 id='artist_span'>" + artist + "</h3>";
id3string += "<div class='meta'>";
if(id3['Album/Movie/Show title']) {
id3string += "<p><strong>Album:</strong> " + id3['Album/Movie/Show title'] + "</p>";
Expand All @@ -80,6 +82,32 @@ function usePlayer (player) {
player.setPlaying(!player.playing);
return false;
};

// musicbrainz + musicmetric queries
$.ajax({
type: "GET",
url: "https://jsmad.org/musicbrainz/" + escape(artist),
dataType: "xml",
success: function(xml) {
var doc = $(xml);
console.log("real artist name = " + doc.find('artist').children('name').text());
var artist_id = doc.find('artist').attr('id');
console.log("musicbrainz artist id = " + artist_id);

$.ajax({
type: "GET",
url: "https://jsmad.org/musicmetric/musicbrainz:" + artist_id,
dataType: "json",
success: function(json) {
console.log("success? " + json.success);
var previousFans = json.response.fans.total.previous;
var currentFans = json.response.fans.total.current;
console.log("previous/current fans? " + previousFans + "/" + currentFans);
$('#ID3').appendTo('<p><strong>Tendency: </strong>' + (currentFans == PreviousFans) ? 'holding up' : (currentFans > previousFans ? 'on the rise' : 'falling down') + '</p>');
}
});
}
});
}

player.onProgress = onProgress;
Expand Down

0 comments on commit 7a144c8

Please sign in to comment.