28 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
30 const Cc = Components.classes;
31 const Ci = Components.interfaces;
32 const Cr = Components.results;
36 var catMan =
Cc[
"@mozilla.org/categorymanager;1"]
37 .getService(
Ci.nsICategoryManager);
39 var readers = catMan.enumerateCategory(
"playlist-reader");
40 while (readers.hasMoreElements()) {
41 var
entry = readers.getNext();
42 entry = entry.QueryInterface(
Ci.nsISupportsCString);
43 var contractid = catMan.getCategoryEntry(
"playlist-reader", entry);
46 var aReader =
Cc[contractid].createInstance(
Ci.sbIPlaylistReader);
47 this.m_Readers.push(aReader);
54 for(var
i in this.m_Readers)
56 var nExtensionsCount = {};
57 var aExts = this.m_Readers[
i].supportedFileExtensions(nExtensionsCount);
58 this.m_Extensions = this.m_Extensions.concat(aExts);
59 var nMIMETypesCount = {};
60 var aMIMETypes = this.m_Readers[
i].supportedMIMETypes(nMIMETypesCount);
61 this.m_MIMETypes = this.m_MIMETypes.concat(aMIMETypes);
64 var obs =
Cc[
"@mozilla.org/observer-service;1"]
65 .getService(
Ci.nsIObserverService);
66 obs.addObserver(
this,
"quit-application",
false);
74 classID: Components.ID(
"{ced5902c-bd90-4099-acee-77487a5b1d13}"),
75 contractID:
"@songbirdnest.com/Songbird/PlaylistReaderManager;1",
79 m_rootContractID:
"@songbirdnest.com/Songbird/Playlist/Reader/",
80 m_interfaceID: Components.interfaces.sbIPlaylistReader,
81 m_Readers:
new Array(),
82 m_Extensions:
new Array(),
83 m_MIMETypes:
new Array(),
89 extension = aExtension;
92 var
file = Components.classes[
"@mozilla.org/file/directory_service;1"]
93 .getService(Components.interfaces.nsIProperties)
94 .get(
"TmpD", Components.interfaces.nsIFile);
95 file.append(
"songbird." + extension);
96 file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0664);
101 getFileExtension:
function(aThing)
104 if (aThing instanceof
Ci.nsIURL) {
105 if (
"" != aThing.fileExtension) {
106 return aThing.fileExtension;
109 if (aThing instanceof
Ci.nsIURI) {
112 if (aThing instanceof
Ci.nsIFile) {
113 name = aThing.leafName;
116 var m = /\.([^\.\/]+)$/(name);
125 loadPlaylist:
function(aURI, aMediaList, aContentType, aAddDistinctOnly, aPlaylistReaderListener)
127 const PlaylistReaderListener =
new Components.Constructor(
"@songbirdnest.com/Songbird/PlaylistReaderListener;1",
"sbIPlaylistReaderListener");
129 var theExtension = this.getFileExtension(aURI);
131 if (aURI instanceof
Ci.nsIFileURL)
133 var
file = aURI.QueryInterface(
Ci.nsIFileURL).file;
136 if (!file.exists() || file.fileSize == 0) {
142 if (aContentType ==
null ||
143 aContentType ==
"" ||
144 aContentType ==
"text/html" ||
145 aContentType ==
"text/xml" ||
146 aContentType ==
"text/plain" ||
147 aContentType ==
"application/xhtml" ||
148 aContentType ==
"application/xhtml+xml" ||
149 aContentType ==
"application/xml") {
150 aContentType = this.guessMimeType(file);
156 if (!this.originalURI) {
157 this.originalURI = aURI;
161 this.read(file, aMediaList, aContentType, aAddDistinctOnly);
162 if (aPlaylistReaderListener && aPlaylistReaderListener.observer) {
163 aPlaylistReaderListener.observer.observe(aMediaList,
"success",
"");
168 if (e.result ==
Cr.NS_ERROR_NOT_AVAILABLE) {
174 this.originalURI =
null;
181 this.originalURI = aURI;
183 var
browser =
Cc[
"@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
184 .createInstance(
Ci.nsIWebBrowserPersist);
186 if(!browser)
return -1;
190 var localFile =
Cc[
"@mozilla.org/file/local;1"]
191 .createInstance(
Ci.nsILocalFile);
192 localFile.initWithPath(destFile);
194 var
ios =
Cc[
"@mozilla.org/network/io-service;1"]
195 .getService(
Ci.nsIIOService);
196 var localFileUri = ios.newFileURI(localFile);
198 var registerFileForDelete =
Cc[
"@mozilla.org/uriloader/external-helper-app-service;1"]
199 .getService(
Ci.nsPIExternalAppLauncher);
200 registerFileForDelete.deleteTemporaryFileOnExit(localFile);
202 var prListener =
null;
203 if(aPlaylistReaderListener)
205 prListener = aPlaylistReaderListener;
209 prListener = (
new PlaylistReaderListener()).
QueryInterface(
Ci.sbIPlaylistReaderListener);
212 prListener.originalURI = this.originalURI;
213 prListener.mediaList = aMediaList;
214 prListener.destinationURI = localFileUri;
215 prListener.addDistinctOnly = aAddDistinctOnly;
218 browser.persistFlags &=
219 ~(
Ci.nsIWebBrowserPersist.PERSIST_FLAGS_NO_CONVERSION);
221 browser.progressListener = prListener;
223 browser.saveURI(aURI,
null,
null,
null,
"", localFileUri);
231 read:
function(aFile, aMediaList, aContentType, aAddDistinctOnly, aPlaylistFormatType)
233 if (!this.originalURI) {
234 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
235 .getService(
Ci.nsIIOService);
236 this.originalURI = ioService.newFileURI(aFile);
239 var theExtension = this.getFileExtension(aFile);
240 for (var r in this.m_Readers)
242 var aReader = this.m_Readers[r];
245 var nExtensionsCount = {};
246 var theExtensions = aReader.supportedFileExtensions(nExtensionsCount);
251 aReader.originalURI = this.originalURI;
252 this.originalURI =
null;
254 aReader.read(aFile, aMediaList, aAddDistinctOnly, aPlaylistFormatType);
260 var nMIMTypeCount = {};
261 var theMIMETypes = aReader.supportedMIMETypes(nMIMTypeCount);
266 aReader.originalURI = this.originalURI;
267 this.originalURI =
null;
269 aReader.read(aFile, aMediaList, aAddDistinctOnly, aPlaylistFormatType);
276 throw Cr.NS_ERROR_NOT_AVAILABLE;
279 supportedFileExtensions:
function(nExtCount)
281 nExtCount.value = this.m_Extensions.length;
282 return this.m_Extensions;
285 supportedMIMETypes:
function(nMIMECount)
287 nMIMECount.value = this.m_MIMETypes.length;
288 return this.m_MIMETypes;
291 guessMimeType:
function(
file)
294 var fstream = Components.classes[
"@mozilla.org/network/file-input-stream;1"]
295 .createInstance(Components.interfaces.nsIFileInputStream);
296 var sstream = Components.classes[
"@mozilla.org/scriptableinputstream;1"]
297 .createInstance(Components.interfaces.nsIScriptableInputStream);
298 fstream.init(
file, -1, 0, 0);
299 sstream.init(fstream);
300 var
str = sstream.read(4096);
310 regexp: /<\?xml[\s\S]*<rss/,
311 mimeType:
"application/rss+xml"
314 regexp: /<\?xml[\s\S]*xmlns=
"http:\/\/www\.w3\.org\/2005\/Atom"/,
315 mimeType:
"application/atom+xml"
318 regexp: /^\[playlist\]/
i,
319 mimeType:
"audio/x-scpls"
323 mimeType:
"audio/mpegurl"
327 mimeType:
"text/html"
330 regexp: /^(http|mms|rtsp)/im,
331 mimeType:
"audio/mpegurl"
334 regexp: /.*(mp3|ogg|flac|wav|m4a|wma|wmv|asx|asf|avi|mov|mpg|mp4)$/im,
335 mimeType:
"audio/mpegurl"
339 mimeType:
"video/x-ms-asf"
343 for(var
i = 0;
i < regexps.length;
i++) {
344 var re = regexps[
i].regexp;
346 return regexps[
i].mimeType;
355 var obs =
Cc[
"@mozilla.org/observer-service;1"]
356 .getService(
Ci.nsIObserverService);
357 obs.removeObserver(
this,
"quit-application");
359 for (let
i in this.m_Readers) {
360 this.m_Readers[
i] =
null;
368 return a.some(
function(e) {
return e == v; } );
function getTempFilename()
Get a temporary file name.
function NSGetModule(compMgr, fileSpec)
function SB_ArrayContains(a, v)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
sbDeviceFirmwareAutoCheckForUpdate prototype classID
_getSelectedPageStyle s i
function CPlaylistReaderManager()
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe