1 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
2 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
3 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
7 const Cr = Components.results;
8 var
JSON =
Cc[
"@mozilla.org/dom/json;1"].createInstance(
Ci.nsIJSON);
10 const DESCRIPTION =
"mashTape Provider: Wikipedia Artist Info Provider";
11 const CID =
"{a7780910-8c10-11dd-ad8b-0800200c9a66}";
12 const CONTRACTID =
"@songbirdnest.com/mashTape/provider/info/WikipediaLocal;1";
20 this.wrappedJSObject =
this;
21 Components.utils.import(
"resource://mashtape/mtUtils.jsm");
23 if (typeof(language) ==
"undefined") {
25 var prefBranch =
Cc[
"@mozilla.org/preferences-service;1"]
26 .getService(
Ci.nsIPrefService).getBranch(
"general.");
27 var locale = prefBranch.getCharPref(
"useragent.locale");
28 language = locale.split(/-/)[0];
29 mtUtils.log(
"Wikipedia",
"language set to " + language);
31 if (typeof(homepage) ==
"undefined") {
33 homepage =
"Homepage";
34 wikipedia =
"Wikipedia";
38 var gtReq =
Cc[
"@mozilla.org/xmlextras/xmlhttprequest;1"]
39 .createInstance(
Ci.nsIXMLHttpRequest);
40 var
url =
"http://ajax.googleapis.com/ajax/services/language/translate"
41 +
"?v=1.0&q=Wikipedia%7CHomepage&langpair=en%7C" +
language;
42 mtUtils.log(
"Wikipedia",
"translate URL: " + url);
43 gtReq.open(
"GET", url,
true);
44 gtReq.onreadystatechange =
function(ev) {
45 if (this.readyState != 4)
47 if (this.status != 200)
49 var results = JSON.decode(this.responseText);
50 if (results.responseStatus == 200) {
51 var text = results.responseData.translatedText.split(
"|");
52 wikipedia = text[0].replace(/^[\s]*/,
'').replace(/[\s]*$/,
'');
53 homepage = text[1].replace(/^[\s]*/,
'').replace(/[\s]*$/,
'');
54 mtUtils.log(
"Wikipedia",
"Homepage: " + homepage);
55 mtUtils.log(
"Wikipedia",
"Wikipedia: " + wikipedia);
68 Ci.sbIMashTapeProvider]),
70 providerName:
"Wikipedia",
73 providerIconBio :
"chrome://mashtape/content/tabs/wikipedia.png",
74 providerIconDiscography :
"chrome://mashtape/content/tabs/wikipedia.png",
75 providerIconMembers :
"chrome://mashtape/content/tabs/wikipedia.png",
76 providerIconTags :
"chrome://mashtape/content/tabs/wikipedia.png",
77 providerIconLinks :
"chrome://mashtape/content/tabs/wikipedia.png",
81 var dbReq =
Cc[
"@mozilla.org/xmlextras/xmlhttprequest;1"]
82 .createInstance(
Ci.nsIXMLHttpRequest);
89 var
url =
"http://dbpedia.org/data/" +
90 artist.replace(/ /g,
"_") +
".rdf";
91 mtUtils.log(
"Wikipedia",
"DBpedia URL:" + url);
92 var prefBranch =
Cc[
"@mozilla.org/preferences-service;1"]
93 .getService(
Ci.nsIPrefService).getBranch(
"extensions.mashTape.");
94 var autolocalise = prefBranch.getBoolPref(
"info.autolocalise");
97 dbReq.open(
"GET", url,
true);
98 dbReq.onreadystatechange =
function(ev) {
99 return function(updateFn) {
100 if (dbReq.readyState != 4)
102 if (dbReq.status != 200)
104 var xmlText = dbReq.responseText.replace(
105 /<\?xml
version=
"1.0" encoding=
"utf-8" \?>/,
107 var x =
new XML(xmlText);
110 var dbNs =
new Namespace(
"http://dbpedia.org/property/");
111 var foafNs =
new Namespace(
"http://xmlns.com/foaf/0.1/");
112 var rdfNs =
new Namespace(
113 "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
114 var xmlNs =
new Namespace(
115 "http://www.w3.org/XML/1998/namespace");
118 var links =
new Object;
120 links.provider =
"Wikipedia";
121 links.links =
new Array();
122 if (x..foafNs::page.length() >= 1) {
123 wikiUrl = x..foafNs::page[0].@rdfNs::resource.toString();
124 wikiUrl = wikiUrl.replace(
"en.wikipedia.org",
125 language+
".wikipedia.org");
157 var bio =
new Object;
160 var englishBio =
null;
161 for each (var bio
in x..dbNs::abstract) {
162 var thisLang = bio.@xmlNs::lang.toString();
163 mtUtils.log(
"Wikipedia",
"Language scan: " + thisLang);
164 if (thisLang == language)
165 bioText = bio.toString();
166 if (thisLang ==
"en")
167 englishBio = bio.toString();
170 bioText = englishBio;
174 bio.provider =
"Wikipedia";
175 bio.bioText = bioText;
176 bio.bioUrl = wikiUrl;
177 bio.bioEditUrl = wikiUrl;
178 updateFn.wrappedJSObject.update(
CONTRACTID, bio,
"bio");
182 var members =
new Object;
183 members.provider =
"Wikipedia";
184 members.url = wikiUrl;
185 members.members =
new Array();
186 if (x..dbNs::currentMembers.length() == 1 &&
187 x..dbNs::currentMembers.@rdfNs::resource.toString() ==
"")
189 var memberStr = x..dbNs::currentMembers.toString();
190 members.members = memberStr.split(/\n/);
192 for each (var memberName
in x..dbNs::currentMembers) {
193 var
name = memberName.@rdfNs::resource.toString();
194 var
uri = name.split(/\
195 name = unescape(uri[uri.length-1].replace(/
_/g,
" "));
196 members.members.push(name);
201 var image = x..dbNs::img.@rdfNs::resource.toString();
205 updateFn.wrappedJSObject.update(
CONTRACTID, image,
"photo");
208 if (members.members.length > 0)
209 updateFn.wrappedJSObject.update(
CONTRACTID, members,
215 if (links.links.length > 0)
216 updateFn.wrappedJSObject.update(
CONTRACTID, links,
"links");
227 return XPCOMUtils.generateModule([
ArtistInfo]);
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function NSGetModule(compMgr, fileSpec)
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties artist
sbDeviceFirmwareAutoCheckForUpdate prototype classID