home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / scripts / sbHTMLPlaylistHandler.js < prev    next >
Text File  |  2012-06-08  |  3KB  |  134 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 sbHTMLPlaylistHandler.js
  29.  */
  30. function sbHTMLPlaylistHandler() {
  31.   this._originalURI = null;
  32. }
  33.  
  34. // sbIPlaylistReader
  35. sbHTMLPlaylistHandler.prototype.__defineGetter__("originalURI",
  36. function()
  37. {
  38.   return this._originalURI;
  39. });
  40.  
  41. sbHTMLPlaylistHandler.prototype.__defineSetter__("originalURI",
  42. function(value)
  43. {
  44.   this._originalURI = value;
  45. });
  46.  
  47. sbHTMLPlaylistHandler.prototype.read =
  48. function(aFile, aMediaList, aReplace)
  49. {
  50.   var toAdd = [];
  51.  
  52.   var typeSniffer = Cc["@songbirdnest.com/Songbird/Mediacore/TypeSniffer;1"]
  53.                       .createInstance(Ci.sbIMediacoreTypeSniffer);
  54.  
  55.   // A fairly permissive regular expression to match href attributes.  It will
  56.   // match href values that are surrounded by single or double quotes, or no
  57.   // quotes at all.  It is also permissive about whitespace around the equals
  58.   // sign.
  59.   //
  60.   // The regular expression explained:
  61.   //   match "href" then 0 or more characters of whitespace
  62.   //   match "=" then 0 or more characters of whitespace
  63.   //   capture an optional single or double quote
  64.   //   non-greedy capture of everything up to...
  65.   //   something that matches the first capture or a close angle bracket
  66.   //
  67.   // Note that the match we want shows up in the second capture
  68.   var re = new RegExp("href\\s*=\\s*(['\"])?(.*?)(?:\\1|>)", "ig");
  69.  
  70.   var self = this;
  71.   SB_ProcessFile(aFile, function(aLine) {
  72.  
  73.     var a = re.exec(aLine);
  74.     while (a && a.length == 3) {
  75.       var href = a[2];
  76.       var newUri = SB_ResolveURI(href, this._originalURI);
  77.       if (newUri && typeSniffer.isValidMediaURL(newUri)) {
  78.         var item = { uri: newUri, properties: {}};
  79.         toAdd.push(item);
  80.       }
  81.  
  82.       a = re.exec(aLine);
  83.     }
  84.  
  85.   }, this);
  86.  
  87.   SB_AddItems(toAdd, aMediaList, aReplace);
  88.  
  89. }
  90.  
  91. sbHTMLPlaylistHandler.prototype.vote =
  92. function(aURL)
  93. {
  94.   return 10000;
  95. }
  96.  
  97. sbHTMLPlaylistHandler.prototype.name =
  98. function()
  99. {
  100.   return "Songbird HTML Reader";
  101. }
  102.  
  103. sbHTMLPlaylistHandler.prototype.description =
  104. function()
  105. {
  106.   return "Scrape HREFs from HTML files.";
  107. }
  108.  
  109. sbHTMLPlaylistHandler.prototype.supportedMIMETypes =
  110. function(aMIMECount)
  111. {
  112.   var mimeTypes = ["text/html"];
  113.   aMIMECount.value = mimeTypes.length;
  114.   return mimeTypes;
  115. }
  116.  
  117. sbHTMLPlaylistHandler.prototype.supportedFileExtensions =
  118. function(aExtCount)
  119. {
  120.   var exts = ["html", "htm", "php", "php3", ""];
  121.   aExtCount.value = exts.length;
  122.   return exts;
  123. }
  124.  
  125. sbHTMLPlaylistHandler.prototype.QueryInterface =
  126. function(iid)
  127. {
  128.   if (!iid.equals(Ci.sbIPlaylistReader) &&
  129.       !iid.equals(Ci.nsISupports))
  130.     throw Cr.NS_ERROR_NO_INTERFACE;
  131.   return this;
  132. }
  133.  
  134.