1 /* vi: set et sw=4 ts=4 si: */
3 var library = function() {
5 this.initialized = false;
12 this.initialize = function() {
16 if (win.tizen === undefined) {
17 throw Error("You need the Tizen web API to run Hoofbeats.");
20 this.audioTypeFilter = new tizen.AttributeFilter(
21 "type", "EXACTLY", "AUDIO");
22 this.videoTypeFilter = new tizen.AttributeFilter(
23 "type", "EXACTLY", "VIDEO");
24 this.typeFilter = new tizen.CompositeFilter(
25 "UNION", [this.audioTypeFilter, this.videoTypeFilter]);
28 this.scan = function(count) {
29 this.deferred = new $.Deferred();
35 if (count !== undefined) {
36 this.fetchCount = count;
41 this.findCB.bind(this),
42 this.errorCB.bind(this),
49 return this.deferred.promise();
52 this.errorCB = function(error) {
53 console.log("HoofbeatsLibrary.errorCB: " + error.name);
54 this.deferred.reject();
55 throw new Error(error.name);
58 this.findCB = function(items) {
61 items.forEach(function(item, index, items) {
62 self.mediaItems.push(item);
63 win.MusicBrainz.getArtist(item.artists[0]).done(function(data) {
65 "HoofbeatsLibrary.findCB: " +
66 "item resolved on MusicBrainz: " +
71 if (items.length == this.fetchCount && !this.oneTime) {
72 // There *might* be more items.
73 this.fetchOffset += this.fetchCount;
75 this.findCB.bind(this),
76 this.errorCB.bind(this),
83 self.deferred.resolve();
89 set initialized(value) {this._initialized = value; },
90 get initialized() { return this._initialized; },
91 get items() { return this.mediaItems; },
92 get size() { return this.mediaItems.length; }
95 win.HoofbeatsLibrary = library;