28 const Cc = Components.classes;
29 const CC = Components.Constructor;
30 const Ci = Components.interfaces;
31 const Cr = Components.results;
32 const Cu = Components.utils;
35 const API_KEY =
'ad68d3b69dee88a912b193a35d235a5b';
37 const API_URL =
'http://ws.audioscrobbler.com/2.0/';
40 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
41 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
44 const CONTRACTID =
"@songbirdnest.com/Songbird/webservices/last-fm;1";
45 const CLASSNAME =
"Songbird Last.FM WebService Interface";
46 const CID = Components.ID(
"{6582d596-95dd-4449-be8b-7793a15bdfa2}");
47 const IID =
Ci.sbILastFmWebServices;
51 while(enumerator.hasMoreElements()) {
53 func(enumerator.getNext());
62 var
converter =
Cc[
"@mozilla.org/intl/scriptableunicodeconverter"]
63 .createInstance(
Ci.nsIScriptableUnicodeConverter);
65 converter.charset =
"UTF-8";
70 var
data = converter.convertToByteArray(
str, result);
71 var ch =
Cc[
"@mozilla.org/security/hash;1"].createInstance(
Ci.nsICryptoHash);
73 ch.update(data, data.length);
74 var
hash = ch.finish(
false);
77 function toHexString(charCode) {
78 return (
"0" + charCode.toString(16)).slice(-2);
82 var s = [toHexString(hash.charCodeAt(
i))
for (
i in hash)].join(
"");
91 if (s.length) { s +=
'&'; }
102 xhr =
Cc[
"@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
104 xhr.mozBackgroundRequest =
true;
106 xhr.open(
'POST',
url,
true);
109 xhr.onerror =
function(
event) { onerror(xhr); }
111 xhr.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded');
129 this.wrappedJSObject =
this;
132 this._console =
Cc[
"@mozilla.org/consoleservice;1"]
133 .getService(
Ci.nsIConsoleService);
143 category:
"app-startup",
144 entry:
"webservices-lastfm",
149 log:
function sbLastFmWebServices_log(
message) {
150 this._console.logStringMessage(
'[last-fm] '+
message);
156 apiCall:
function sbLastFmWebServices_apiCall(aMethod,
163 function callback(success, response) {
164 if (typeof(aCallback) ==
'function') {
165 aCallback(success, response);
167 aCallback.responseReceived(success, response);
172 var post_params =
new Object();
175 if (aArguments instanceof
Ci.nsIPropertyBag) {
176 enumerate(aArguments.enumerator,
function(item) {
177 item.QueryInterface(
Ci.nsIProperty);
178 post_params[item.name] = item.value;
182 for (var k in aArguments) { post_params[k] = aArguments[k]; }
186 post_params.method = aMethod;
191 var sorted_params =
new Array();
192 for (var k in post_params) {
193 sorted_params.push(k+post_params[k])
196 sorted_params.sort();
198 sorted_params = sorted_params.join(
'');
205 if (!
xhr.responseXML) {
207 self.log(
'Last.fm WebServices Error: No valid XML response.');
213 var nsResolver =
xhr.responseXML.createNSResolver(
214 xhr.responseXML.ownerDocument ==
null ?
215 xhr.responseXML.documentElement :
216 xhr.responseXML.ownerDocument.documentElement);
217 var result =
xhr.responseXML.evaluate(
"/lfm/@status",
222 if (result.stringValue && result.stringValue ==
'failed') {
223 result =
xhr.responseXML.evaluate(
"/lfm/error",
228 var error =
"Unknown Error";
229 if (result.stringValue) {
230 error = result.stringValue;
232 self.log(
'Last.fm WebServices Error: ' + error);
240 self.log(
'Last.fm WebServices Error: Bad response from server.');
nsString encodeURIComponent(const nsString &c)
function sbLastFmWebServices()
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
function enumerate(enumerator, func)
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function POST(url, params, onload, onerror)
DataRemote prototype constructor
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
_getSelectedPageStyle s i