+/* vi: set et sw=4 ts=4 si: */
$(function() {
var library = function() {
// For readability:
this.initialized = false;
+
this.fetchCount = 100;
this.fetchOffset = 0;
this.mediaItems = [];
items.forEach(function(item, index, items) {
self.mediaItems.push(item);
- console.log("Item added to the library: " + item.title);
+ window.MusicBrainz.getArtist(item.name).done(function(data) {
+ console.log(data);
+ });
});
if (items.length == this.fetchCount) {
--- /dev/null
+/* vi: set et sw=4 ts=4 si: */
+$(function() {
+ var musicbrainz = function() {
+ this.baseUrl = 'http://musicbrainz.org/ws/2/';
+ this.fmtArg = 'fmt=json';
+
+ this.getArtist = function(q) {
+ var self = this,
+ lookup_url = self.baseUrl + 'artist/?query=' + q + '&' + self.fmtArg;
+ deferred = new $.Deferred();
+
+ $.getJSON(lookup_url).done(function(data) {
+ artist_url = self.baseUrl + 'artist/' + data.artist[0].id + '?' + self.fmtArg;
+ $.getJSON(artist_url).done(function(data) {
+ deferred.resolve(data);
+ });
+ });
+ return deferred.promise();
+ };
+ }
+
+ window.MusicBrainz = new musicbrainz();
+});
<!-- source -->
<script src="../javascripts/library.js"></script>
+ <script src="../javascripts/musicbrainz.js"></script>
<!-- unit tests -->
<script src="unit/library.js"></script>
+ <script src="unit/musicbrainz.js"></script>
</head>
<body>
<div>
--- /dev/null
+/* vi: set et sw=4 ts=4 si: */
+$(function() {
+ module("hoofbeats-musicbrainz", {
+ setup: function() {
+ },
+ teardown: function() {
+ }
+ });
+
+ test("get artist data",
+ function() {
+ var name = "Regina Spektor";
+ var promise = MusicBrainz.getArtist(name);
+ stop();
+ promise.done(function(data) {
+ equals(data.name, name, "name matches");
+ start();
+ });
+ });
+});
"devel" : true,
"boss" : true,
"expr" : true,
- "asi" : true
+ "asi" : true,
+ "es5" : true
}
},
less: {