29 const Cc = Components.classes;
30 const CC = Components.Constructor;
31 const Ci = Components.interfaces;
32 const Cr = Components.results;
33 const Cu = Components.utils;
39 Cu.import(
'resource://app/jsmodules/sbProperties.jsm');
40 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
41 Cu.import(
"resource://app/jsmodules/ArrayConverter.jsm");
42 Cu.import(
"resource://app/jsmodules/sbCoverHelper.jsm");
43 Cu.import(
'resource://gre/modules/XPCOMUtils.jsm');
51 return this.
Application =
Cc[
"@mozilla.org/fuel/application;1"]
52 .getService(
Ci.fuelIApplication);
57 function sbLastFMAlbumArtFetcher() {
59 this._lastFMWebApi =
Cc[
'@songbirdnest.com/Songbird/webservices/last-fm;1']
60 .getService(
Ci.sbILastFmWebServices);
61 this._strings =
Cc[
"@mozilla.org/intl/stringbundle;1"]
62 .getService(
Ci.nsIStringBundleService)
63 .createBundle(
"chrome://albumartlastfm/locale/albumartlastfm.properties");
65 sbLastFMAlbumArtFetcher.prototype = {
69 classID: Components.ID(
'{8569316f-13a0-44d8-9d08-800999ed1f1c}'),
70 contractID:
'@songbirdnest.com/album-art/lastfm-fetcher;1',
72 category:
"songbird-album-art-fetcher"
77 _albumArtSourceList:
null,
81 _findImageForItem:
function(aMediaItem, aCallback) {
83 var albumName = aMediaItem.getProperty(SBProperties.albumName);
84 var artistName = aMediaItem.getProperty(SBProperties.artistName);
85 var albumArtistName = aMediaItem.getProperty(SBProperties.albumArtistName);
86 if (albumArtistName) {
87 artistName = albumArtistName;
90 var
arguments =
Cc[
"@mozilla.org/hash-property-bag;1"]
91 .createInstance(
Ci.nsIWritablePropertyBag2);
92 arguments.setPropertyAsAString(
"album", albumName);
93 arguments.setPropertyAsAString(
"artist", artistName);
96 var apiResponse =
function response(success, xml) {
98 self._isFetching =
false;
101 if (
self._shutdown) {
111 var foundCover =
null;
112 var imageSizes = [
'large',
'medium',
'small'];
115 var nsResolver = xml.createNSResolver(xml.ownerDocument ==
null ?
116 xml.documentElement :
117 xml.ownerDocument.documentElement);
118 for (var iSize = 0; iSize < imageSizes.length; iSize++) {
119 var result = xml.evaluate(
"//image[@size='" + imageSizes[iSize] +
"']",
124 if (result.snapshotLength > 0) {
125 foundCover = result.snapshotItem(0).textContent;
130 aCallback(foundCover);
134 this._isFetching =
true;
136 this._lastFMWebApi.apiCall(
"album.getInfo",
166 set priority(aNewVal) {
173 set isEnabled(aNewVal) {
177 get albumArtSourceList() {
178 return this._albumArtSourceList;
180 set albumArtSourceList(aNewVal) {
181 this._albumArtSourceList = aNewVal;
185 return this._isFetching;
188 fetchAlbumArtForAlbum:
function (aMediaItems, aListener) {
189 if (aMediaItems.length <= 0) {
191 Cu.reportError(
"No media items passed to fetchAlbumArtForAlbum.");
193 aListener.onAlbumResult(
null, aMediaItems);
194 aListener.onSearchComplete(aMediaItems,
null);
200 var firstMediaItem =
null;
202 firstMediaItem = aMediaItems.queryElementAt(0,
Ci.sbIMediaItem);
205 aListener.onAlbumResult(
null, aMediaItems);
206 aListener.onAlbumComplete(aMediaItems);
210 var returnResult =
function (aImageLocation) {
211 if (aImageLocation) {
213 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
214 .getService(
Ci.nsIIOService);
217 uri = ioService.newURI(aImageLocation,
null,
null);
219 Cu.reportError(
"lastFM: Unable to convert to URI: [" + aImageLocation +
223 aImageLocation =
uri;
225 aListener.onAlbumResult(aImageLocation, aMediaItems);
226 aListener.onSearchComplete(aMediaItems);
228 var downloadCover =
function (aFoundCover) {
230 sbCoverHelper.downloadFile(aFoundCover, returnResult);
235 this._findImageForItem(firstMediaItem, downloadCover);
238 fetchAlbumArtForTrack:
function (aMediaItem, aListener) {
239 var returnResult =
function (aImageLocation) {
240 if (aImageLocation) {
242 var ioService =
Cc[
"@mozilla.org/network/io-service;1"]
243 .getService(
Ci.nsIIOService);
246 uri = ioService.newURI(aImageLocation,
null,
null);
248 Cu.reportError(
"lastFM: Unable to convert to URI: [" + aImageLocation +
252 aImageLocation =
uri;
254 aListener.onTrackResult(aImageLocation, aMediaItem);
256 var items =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
257 .createInstance(
Ci.nsIMutableArray);
258 items.appendElement(aMediaItem,
false);
259 aListener.onSearchComplete(items);
261 var downloadCover =
function (aFoundCover) {
263 sbCoverHelper.downloadFile(aFoundCover, returnResult);
268 this._findImageForItem(aMediaItem, downloadCover);
273 if (this._isFetching)
276 this._shutdown =
true;
287 return XPCOMUtils.generateModule([sbLastFMAlbumArtFetcher]);
sbOSDControlService prototype className
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
sbDownloadDeviceServicePaneModule prototype shutdown
function SBString(aKey, aDefault, aStringBundle)
return!aWindow arguments!aWindow arguments[0]
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
__defineGetter__("Application", function(){delete this.Application;return this.Application=Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication);})