sbMetadataLookupTestProvider.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the "GPL").
11  *
12  * Software distributed under the License is distributed
13  * on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 const Cc = Components.classes;
26 const CC = Components.Constructor;
27 const Ci = Components.interfaces;
28 const Cr = Components.results;
29 const Cu = Components.utils;
30 
31 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
32 Cu.import("resource://app/jsmodules/SBJobUtils.jsm");
33 Cu.import("resource://app/jsmodules/ArrayConverter.jsm");
34 Cu.import("resource://app/jsmodules/sbProperties.jsm");
35 
36 function sbTestProvider() {
37 }
38 
39 var midnightRock = [
40  {artist: "Hootie & The Blowfish", title: "Let Her Cry"},
41  {artist: "Genesis", title: "Throwing It All Away"},
42  {artist: "Pretenders", title: "I'll Stand By You"},
43  {artist: "Jesus Jones", title: "Right Here, Right Now"},
44  {artist: "Bad Company", title: "Feel Like Makin' Love"},
45  {artist: "Alannah Myles", title: "Black Velvet"},
46  {artist: "Foreigner", title: "I Want To Know What Love Is"},
47  {artist: "Boston", title: "Amanda"},
48  {artist: "Meat Loaf", title: "I'd Do Anything For Love (But I Won't Do That"},
49  {artist: "Pat Benatar", title: "We Belong"},
50  {artist: "April Wine", title: "Just Between You And Me"},
51  {artist: "INXS", title: "Never Tear Us Apart"},
52  {artist: "Lita Ford", title: "Shot Of Poison"},
53  {artist: "Nazareth", title: "Love Hurts"},
54  {artist: "Skid Row", title: "I Remember You"}
55  ];
56 
57 var incredibad = [
58  {artist: "The Lonely Island", title: "Who Said We're Wack?"},
59  {artist: "The Lonely Island", title: "Santana DVX (feat. E-40)"},
60  {artist: "The Lonely Island", title: "Jizz In My Pants"},
61  {artist: "The Lonely Island", title: "I'm On A Boat (feat. T-Pain)"},
62  {artist: "The Lonely Island", title: "Sax Man (feat. Jack Black)"},
63  {artist: "The Lonely Island", title: "Lazy Sunday (feat. Chris Parnell)"},
64  {artist: "The Lonely Island", title: "Normal Guy - Interlude"},
65  {artist: "The Lonely Island", title: "Boombox (feat. Julian Casablancas)"},
66  {artist: "The Lonely Island", title: "Shrooms - Interlude"},
67  {artist: "The Lonely Island", title: "Like A Boss"},
68  {artist: "The Lonely Island", title: "We Like Sports"},
69  {artist: "The Lonely Island", title: "Dreamgirl (feat. Norah Jones)"},
70  {artist: "The Lonely Island", title: "Ras Trent"},
71  {artist: "The Lonely Island", title: "Dick In A Box (feat. Justin Timberlake)"},
72  {artist: "The Lonely Island", title: "The Old Saloon - Interlude"},
73  {artist: "The Lonely Island", title: "Punch You In The Jeans"},
74  {artist: "The Lonely Island", title: "Space Olympics"},
75  {artist: "The Lonely Island", title: "Natalie's Rap (feat. Natalie Portman & Chris Parnell)"},
76  {artist: "The Lonely Island", title: "Incredibad"},
77  ];
78 
80  {artist: "Not The Lonely Island", title: "Fake Track 1"},
81  {artist: "Not The Lonely Island", title: "Fake Track 2"},
82  {artist: "Not The Lonely Island", title: "Fake Track 3"},
83  {artist: "Not The Lonely Island", title: "Fake Track 4"},
84  {artist: "Not The Lonely Island", title: "Fake Track 5"},
85  {artist: "Not The Lonely Island", title: "Fake Track 6"},
86  {artist: "Not The Lonely Island", title: "Fake Track 7"},
87  {artist: "Not The Lonely Island", title: "Fake Track 8"},
88  {artist: "Not The Lonely Island", title: "Fake Track 9"},
89  {artist: "Not The Lonely Island", title: "Fake Track 10"},
90  {artist: "Not The Lonely Island", title: "Fake Track 11"},
91  {artist: "Not The Lonely Island", title: "Fake Track 12"},
92  {artist: "Not The Lonely Island", title: "Fake Track 13"},
93  {artist: "Not The Lonely Island", title: "Fake Track 14"},
94  {artist: "Not The Lonely Island", title: "Fake Track 15"},
95  {artist: "Not The Lonely Island", title: "Fake Track 16"},
96  {artist: "Not The Lonely Island", title: "Fake Track 17"},
97  {artist: "Not The Lonely Island", title: "Fake Track 18"},
98  {artist: "Not The Lonely Island", title: "Fake Track 19"},
99  ];
100 
101 var instantJunk = [
102  {artist: "Songbird", title: "No Data"},
103  ];
104 
105 sbTestProvider.prototype = {
106  classDescription : 'Songbird Test Metadata Lookup Service',
107  classID : Components.ID('9e599632-1dd1-11b2-ab82-e0952e7285ce'),
108  contractID : '@songbirdnest.com/Songbird/MetadataLookup/testProvider;1',
109  QueryInterface : XPCOMUtils.generateQI([Ci.sbIMetadataLookupProvider,
110  Ci.nsITimerCallback]),
111 
112  name : "TestProvider",
113  weight : 9999, // set weight to 1 so it can be overridden by Gracenote
114  description : "Test provider. Unless you like Britney, U2, or Midnight Rock, you probably don't want this.",
115  infoURL : "http://getsongbird.com",
116 
117  identifyTOC : function sbTestProvider_identifyTOC(aTOC) {
118  if (aTOC.firstTrackIndex == 1 && aTOC.lastTrackIndex == 15 &&
119  aTOC.leadOutTrackOffset == 285675)
120  return Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_MIDNIGHT_ROCK;
121  else if (aTOC.firstTrackIndex == 1 && aTOC.lastTrackIndex == 12 &&
122  aTOC.leadOutTrackOffset == 260335)
123  return Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_BABY_ONE_MORE_TIME;
124  else if (aTOC.firstTrackIndex == 1 && aTOC.lastTrackIndex == 11 &&
125  aTOC.leadOutTrackOffset == 225562)
126  return Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_U2;
127  else if (aTOC.firstTrackIndex == 1 && aTOC.lastTrackIndex == 19 &&
128  aTOC.leadOutTrackOffset == 190565)
129  return Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_INCREDIBAD;
130  else if (aTOC.firstTrackIndex == 1 && aTOC.lastTrackIndex == 1 &&
131  aTOC.leadOutTrackOffset == 131072)
132  return Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_INSTANT_JUNK;
133  else
134  throw Components.results.NS_ERROR_UNEXPECTED;
135  },
136 
137 
138  queryDisc : function sbTestProvider_queryDisc(aTOC) {
139  var id = this.identifyTOC(aTOC);
140  this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
141 
142  var job = Cc["@songbirdnest.com/Songbird/MetadataLookup/job;1"]
143  .createInstance(Ci.sbIMetadataLookupJob);
144  job.init(Ci.sbIMetadataLookupJob.JOB_DISC_LOOKUP,
145  Ci.sbIJobProgress.STATUS_RUNNING);
146  this.job = job;
147 
148  this.whichAlbum = id;
149 
150  switch (id) {
151  case Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_MIDNIGHT_ROCK:
152  // Test case 1: Midnight Rock
153  // Return a TOC after 5 seconds
154  this._timer.initWithCallback(this, 5000,
155  Ci.nsITimerCallback.TYPE_ONE_SHOT);
156  break;
157  case Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_BABY_ONE_MORE_TIME:
158  // Test case 2: Hit Me Baby One More Time
159  // Return no TOC found after 5 seconds
160  this._timer.initWithCallback(this, 5000,
161  Ci.nsITimerCallback.TYPE_ONE_SHOT);
162  break;
163  case Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_U2:
164  // Test case 3: U2
165  // Timeout after 3 minutes
166  this._timer.initWithCallback(this, 180000,
167  Ci.nsITimerCallback.TYPE_ONE_SHOT);
168  break;
169  case Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_INCREDIBAD:
170  // Test case 4: Incredibad
171  // Return multiple TOCs found after 5 seconds
172  this._timer.initWithCallback(this, 5000,
173  Ci.nsITimerCallback.TYPE_ONE_SHOT);
174  break;
175  case Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_INSTANT_JUNK:
176  // Test case 5: Instant Junk
177  // Return multiple TOCs found immediately
178  this.notify(this._timer);
179  break;
180  default:
181  dump("This is not a recognised disc.\n");
182  break;
183  }
184 
185  return job;
186  },
187 
188  getAlbumDetail: function(album) {
189  var job = Cc["@songbirdnest.com/Songbird/MetadataLookup/job;1"]
190  .createInstance(Ci.sbIMetadataLookupJob);
191  job.init(Ci.sbIMetadataLookupJob.JOB_ALBUM_DETAIL_LOOKUP,
192  Ci.sbIJobProgress.STATUS_RUNNING);
193 
194  job.appendResult(album);
195  job.changeStatus(Ci.sbIJobProgress.STATUS_SUCCEEDED);
196 
197  return job;
198  },
199 
200  makeAlbum: function(albumToc, artistName, albumName, genre) {
201  // create the skeleton sbIMetadataAlbumDetail object
202  var a = new Object;
203  a.QueryInterface = XPCOMUtils.generateQI([Ci.sbIMetadataAlbumDetail]);
204  a.tracks = null;
205  a.properties =
206  Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
207  .createInstance(Ci.sbIMutablePropertyArray);
208 
209  a.properties.appendProperty(SBProperties.genre, genre);
210  a.properties.appendProperty(SBProperties.artistName, artistName);
211  a.properties.appendProperty(SBProperties.albumName, albumName);
212 
213  a.tracks = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
214  for (var i = 0; i < albumToc.length; i++) {
215  var track = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
216  .createInstance(Ci.sbIMutablePropertyArray);
217  var trackInfo = albumToc[i];
218  track.appendProperty(SBProperties.albumArtistName, artistName);
219  track.appendProperty(SBProperties.artistName, trackInfo.artist);
220  track.appendProperty(SBProperties.trackName, trackInfo.title);
221  track.appendProperty(SBProperties.albumName, albumName);
222  track.appendProperty(SBProperties.genre, genre);
223  track.appendProperty(SBProperties.trackNumber, (i+1).toString());
224  a.tracks.appendElement(track, false);
225  }
226 
227  return a;
228  },
229 
230  notify: function (aTimer) {
231  if (aTimer != this._timer)
232  return;
233 
234  this._timer = null;
235  var id = this.whichAlbum;
236  if (id == Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_BABY_ONE_MORE_TIME)
237  {
238  // do nothing, return empty results
239  this.job.changeStatus(Ci.sbIJobProgress.STATUS_SUCCEEDED);
240  } else if (id == Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_MIDNIGHT_ROCK)
241  {
242  var a = this.makeAlbum(midnightRock, "Various", "Midnight Rock Disc 1",
243  "Rock");
244 
245  // append this result & declare success
246  this.job.appendResult(a);
247  this.job.changeStatus(Ci.sbIJobProgress.STATUS_SUCCEEDED);
248  } else if (id == Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_INCREDIBAD)
249  {
250  var a = this.makeAlbum(incredibad, "The Lonely Island", "Incredibad",
251  "Comedy");
252  var b = this.makeAlbum(notIncredibad, "Not The Lonely Island",
253  "Fake Incredibad", "Gospel");
254  this.job.appendResult(a);
255  this.job.appendResult(b);
256  this.job.changeStatus(Ci.sbIJobProgress.STATUS_SUCCEEDED);
257  } else if (id == Ci.sbIMockCDDeviceController.MOCK_MEDIA_DISC_INSTANT_JUNK)
258  {
259  // return a dummy disc immediately
260  var a = this.makeAlbum(instantJunk, "Songbird", "Instant Junk",
261  "Soundtrack");
262 
263  // append this result & declare success
264  this.job.appendResult(a);
265  this.job.changeStatus(Ci.sbIJobProgress.STATUS_SUCCEEDED);
266  } else {
267  this.job.changeStatus(Ci.sbIJobProgress.STATUS_FAILED);
268  }
269  this.job = null;
270  },
271 }
272 
273 function NSGetModule(compMgr, fileSpec) {
274  return XPCOMUtils.generateModule([sbTestProvider],
275  // our post-register function to register ourselves with
276  // the category manager
277  function(aCompMgr, aFileSpec, aLocation) {
278  XPCOMUtils.categoryManager.addCategoryEntry(
279  "metadata-lookup",
280  sbTestProvider.name,
281  sbTestProvider.prototype.contractID,
282  true,
283  true);
284  }
285  );
286 }
menuItem id
Definition: FeedWriter.js:971
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function sbTestProvider()
sbDeviceFirmwareAutoCheckForUpdate prototype _timer
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties artist
Definition: tuner2.js:40
TimerLoop prototype notify
return null
Definition: FeedWriter.js:1143
sbDeviceFirmwareAutoCheckForUpdate prototype classID
_getSelectedPageStyle s i