home *** CD-ROM | disk | FTP | other *** search
/ Freelog 100 / FreelogNo100-NovembreDecembre2010.iso / Multimedia / Songbird / Songbird_1.8.0-1800_windows-i686-msvc8.exe / scripts / sbASXPlaylistHandler.js next >
Text File  |  2010-08-30  |  4KB  |  169 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 sbASXPlaylistHandler.js
  29.  */
  30.  
  31. function sbASXPlaylistHandler() {
  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. }
  169.