sbFeedPlaylistHandler.js
Go to the documentation of this file.
1 
31  this._originalURI = null;
32 }
33 
34 // sbIPlaylistReader
35 sbFeedPlaylistHandler.prototype.__defineGetter__("originalURI",
36 function()
37 {
38  return this._originalURI;
39 });
40 
41 sbFeedPlaylistHandler.prototype.__defineSetter__("originalURI",
42 function(value)
43 {
44  this._originalURI = value;
45 });
46 
47 sbFeedPlaylistHandler.prototype.read =
48 function(aFile, aMediaList, aReplace)
49 {
50  var istream = Cc["@mozilla.org/network/file-input-stream;1"]
51  .createInstance(Ci.nsIFileInputStream);
52  istream.init(aFile, PR_RDONLY, PR_FLAGS_DEFAULT, 0);
53 
54  var parser = Cc["@mozilla.org/feed-processor;1"]
55  .createInstance(Ci.nsIFeedProcessor);
56 
57  var typeSniffer = Cc["@songbirdnest.com/Songbird/Mediacore/TypeSniffer;1"]
58  .createInstance(Ci.sbIMediacoreTypeSniffer);
59  var toAdd = [];
60  parser.listener = {
61  handleResult: function(result) {
62 
63  var feed = result.doc.QueryInterface(Ci.nsIFeed);
64  for (var i = 0; i < feed.items.length; ++i) {
65  var entry = feed.items.queryElementAt(i, Ci.nsIFeedEntry);
66  var uri = SB_ResolveURI(entry.link.spec);
67  if (typeSniffer.isValidMediaURL(uri)) {
68  var item = { uri: entry.link, properties: {} };
69  /* all items coming in through the feed reader are podcasts */
70  item.properties[SBProperties.contentType] = "podcast";
71  toAdd.push(item);
72  }
73  else {
74  this.addEnclosure(entry);
75  }
76  }
77  },
78 
79  addEnclosure: function(aEntry)
80  {
81  var enclosureList = aEntry.fields.getPropertyAsInterface("enclosure", Ci.nsIArray);
82  if (!enclosureList)
83  return false;
84  var enclosure = enclosureList.queryElementAt(0, Ci.nsIPropertyBag2);
85 
86  var url = enclosure.getPropertyAsAString("url");
87  if (!url)
88  return false;
89 
90  var resolvedURI = SB_ResolveURI(url);
91  if (!resolvedURI)
92  return false;
93 
94  var type = enclosure.getPropertyAsAString("type");
95  if (!type)
96  if (!typeSniffer.isValidMediaURL(resolvedURI))
97  return false;
98 
99  var item = { uri: resolvedURI, properties: {} };
100  /* all items coming in through the feed reader are podcasts */
101  item.properties[SBProperties.contentType] = "podcast";
102  toAdd.push(item);
103 
104  return true;
105  }
106  };
107 
108  parser.parseFromStream(istream, this._originalURI);
109 
110  // Prevent the closure from leaking
111  parser.listener = null;
112 
113  SB_AddItems(toAdd, aMediaList, aReplace);
114 }
115 
116 sbFeedPlaylistHandler.prototype.vote =
117 function(aURL)
118 {
119  return 10000;
120 }
121 
122 sbFeedPlaylistHandler.prototype.name =
123 function()
124 {
125  return "Songbird Atom/RSS Reader";
126 }
127 
128 sbFeedPlaylistHandler.prototype.description =
129 function()
130 {
131  return "Loads Atom/RSS playlists from remote and local locations.";
132 }
133 
134 sbFeedPlaylistHandler.prototype.supportedMIMETypes =
135 function(aMIMECount)
136 {
137  var mimeTypes = ["application/rss+xml", "application/atom+xml"];
138  aMIMECount.value = mimeTypes.length;
139  return mimeTypes;
140 }
141 
142 sbFeedPlaylistHandler.prototype.supportedFileExtensions =
143 function(aExtCount)
144 {
145  var exts = ["atom", "rss"];
146  aExtCount.value = exts.length;
147  return exts;
148 }
149 
150 sbFeedPlaylistHandler.prototype.QueryInterface =
151 function(iid)
152 {
153  if (!iid.equals(Ci.sbIPlaylistReader) &&
154  !iid.equals(Ci.nsISupports))
155  throw Cr.NS_ERROR_NO_INTERFACE;
156  return this;
157 }
158 
classDescription entry
Definition: FeedWriter.js:1427
const Cc
var istream
const PR_RDONLY
const PR_FLAGS_DEFAULT
var resolvedURI
Definition: FeedWriter.js:1136
function sbFeedPlaylistHandler()
return null
Definition: FeedWriter.js:1143
function url(spec)
var uri
Definition: FeedWriter.js:1135
function SB_AddItems(aItems, aMediaList, aAddDistinctOnly)
countRef value
Definition: FeedWriter.js:1423
const Cr
const Ci
function SB_ResolveURI(aStringURL, aBaseURI)
_getSelectedPageStyle s i