sbASXPlaylistHandler.js
Go to the documentation of this file.
1 
32  this._originalURI = null;
33 }
34 
35 // sbIPlaylistReader
36 sbASXPlaylistHandler.prototype.__defineGetter__("originalURI",
37 function()
38 {
39  return this._originalURI;
40 });
41 
42 sbASXPlaylistHandler.prototype.__defineSetter__("originalURI",
43 function(value)
44 {
45  this._originalURI = value;
46 });
47 
48 sbASXPlaylistHandler.prototype.read =
49 function(aFile, aMediaList, aReplace)
50 {
51  var domParser = Cc["@mozilla.org/xmlextras/domparser;1"]
52  .createInstance(Ci.nsIDOMParser);
53  var fileStream = Cc["@mozilla.org/network/file-input-stream;1"]
54  .createInstance(Ci.nsIFileInputStream);
55  var scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"]
56  .createInstance(Ci.nsIScriptableInputStream);
57  fileStream.init(aFile, PR_RDONLY, PR_FLAGS_DEFAULT, 0);
58  scriptableStream.init(fileStream);
59  var str = scriptableStream.read(-1);
60  scriptableStream.close();
61  fileStream.close();
62 
63  // ASX pretends to be XML but it isn't. Ampersands are NOT encoded correctly,
64  // so unless we fix them our dom parser chokes. Yay.
65  str = str.replace("&", '&', 'g');
66 
67  var doc = domParser.parseFromString(str, "text/xml");
68 
69  doc = doc.documentElement;
70 
71  // This will get all entries at this level (root)
72  // Asx is suppose to have <entry> tags at the first level.
73  var itemList = [];
74  var entries = doc.getElementsByTagName("*");
75 
76  for(var i = 0; i < entries.length; ++i) {
77 
78  var item = {};
79  item.uri = [];
80 
81  var children = entries.item(i).childNodes;
82 
83  for(var j = 0; j < children.length; ++j) {
84 
85  var child = children.item(j);
86 
87  var cNodeName = child.nodeName.toUpperCase();
88  switch(cNodeName) {
89 
90  case "TITLE":
91  var title = child.firstChild.nodeValue;
92 
93  if (title) {
94  item.title = title;
95  }
96  break;
97 
98  case "REF":
99  var href = child.getAttribute("href");
100  var uri = SB_ResolveURI(href, this._originalURI);
101 
102  if (uri) {
103  item.uri.push(uri);
104  }
105  break;
106 
107  }
108 
109  }
110 
111  itemList.push(item);
112  }
113 
114  var toAdd = [];
115  itemList.forEach(function(e) {
116  for(var i = 0; i < e.uri.length; ++i) {
117  var item = { uri: e.uri[i], properties: {} };
118  toAdd.push(item);
119  if (e.title)
120  item.properties[SBProperties.trackName] = e.title;
121  }
122  });
123 
124  SB_AddItems(toAdd, aMediaList, aReplace);
125 }
126 
127 sbASXPlaylistHandler.prototype.vote =
128 function(aURL)
129 {
130  return 10000;
131 }
132 
133 sbASXPlaylistHandler.prototype.name =
134 function()
135 {
136  return "Songbird ASX Reader";
137 }
138 
139 sbASXPlaylistHandler.prototype.description =
140 function()
141 {
142  return "Loads ASX playlists from remote and local locations.";
143 }
144 
145 sbASXPlaylistHandler.prototype.supportedMIMETypes =
146 function(aMIMECount, aMIMETypes)
147 {
148  var mimeTypes = ["video/x-ms-asf"];
149  aMIMECount.value = mimeTypes.length;
150  return mimeTypes;
151 }
152 
153 sbASXPlaylistHandler.prototype.supportedFileExtensions =
154 function(aExtCount, aExts)
155 {
156  var exts = ["asx"];
157  aExtCount.value = exts.length;
158  return exts;
159 }
160 
161 sbASXPlaylistHandler.prototype.QueryInterface =
162 function(iid)
163 {
164  if (!iid.equals(Ci.sbIPlaylistReader) &&
165  !iid.equals(Ci.nsISupports))
166  throw Cr.NS_ERROR_NO_INTERFACE;
167  return this;
168 }
const Cc
const PR_RDONLY
function doc() browser.contentDocument
const PR_FLAGS_DEFAULT
Element Properties href
return null
Definition: FeedWriter.js:1143
var uri
Definition: FeedWriter.js:1135
function SB_AddItems(aItems, aMediaList, aAddDistinctOnly)
countRef value
Definition: FeedWriter.js:1423
const Cr
const Ci
function sbASXPlaylistHandler()
function SB_ResolveURI(aStringURL, aBaseURI)
_getSelectedPageStyle s i