home *** CD-ROM | disk | FTP | other *** search
/ Chip 2008 June / CHIP-2008-06.iso / software / Songbird / Songbird_0.5_windows-i686-msvc8.exe / scripts / sbHTMLPlaylistHandler.js < prev    next >
Encoding:
JavaScript  |  2008-03-10  |  3.2 KB  |  136 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 pps = Cc["@songbirdnest.com/Songbird/PlaylistPlayback;1"]
  53.               .getService(Ci.sbIPlaylistPlayback);
  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.       if (href && pps.isMediaURL(href)) {
  77.         var newUri = SB_ResolveURI(href, this._originalURI);
  78.         if (newUri) {
  79.           var item = { uri: newUri, properties: {}};
  80.           toAdd.push(item);
  81.         }
  82.       }
  83.  
  84.       a = re.exec(aLine);
  85.     }
  86.  
  87.   }, this);
  88.  
  89.   SB_AddItems(toAdd, aMediaList, aReplace);
  90.  
  91. }
  92.  
  93. sbHTMLPlaylistHandler.prototype.vote =
  94. function(aURL)
  95. {
  96.   return 10000;
  97. }
  98.  
  99. sbHTMLPlaylistHandler.prototype.name =
  100. function()
  101. {
  102.   return "Songbird HTML Reader";
  103. }
  104.  
  105. sbHTMLPlaylistHandler.prototype.description =
  106. function()
  107. {
  108.   return "Scrape HREFs from HTML files.";
  109. }
  110.  
  111. sbHTMLPlaylistHandler.prototype.supportedMIMETypes =
  112. function(aMIMECount)
  113. {
  114.   var mimeTypes = ["text/html"];
  115.   aMIMECount.value = mimeTypes.length;
  116.   return mimeTypes;
  117. }
  118.  
  119. sbHTMLPlaylistHandler.prototype.supportedFileExtensions =
  120. function(aExtCount)
  121. {
  122.   var exts = ["html", "htm", "php", "php3", ""];
  123.   aExtCount.value = exts.length;
  124.   return exts;
  125. }
  126.  
  127. sbHTMLPlaylistHandler.prototype.QueryInterface =
  128. function(iid)
  129. {
  130.   if (!iid.equals(Ci.sbIPlaylistReader) &&
  131.       !iid.equals(Ci.nsISupports))
  132.     throw Cr.NS_ERROR_NO_INTERFACE;
  133.   return this;
  134. }
  135.  
  136.