home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / scripts / sbFeedPlaylistHandler.js < prev    next >
Text File  |  2012-06-08  |  4KB  |  159 lines

  1. /**
  2. //
  3. // BEGIN SONGBIRD GPL
  4. // 
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright(c) 2005-2008 POTI, Inc.
  8. // http://songbirdnest.com
  9. // 
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the "GPL").
  12. // 
  13. // Software distributed under the License is distributed 
  14. // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
  15. // express or implied. See the GPL for the specific language 
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this 
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc., 
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. // 
  23. // END SONGBIRD GPL
  24. //
  25.  */
  26.  
  27. /**
  28.  * \file sbFeedPlaylistHandler.js
  29.  */
  30. function sbFeedPlaylistHandler() {
  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.  
  159.