home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Multimedia / Songbird / Songbird_2.0.0-2311_windows-i686-msvc8.exe / scripts / sbPLSPlaylistHandler.js < prev   
Text File  |  2012-06-08  |  4KB  |  164 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 sbPLSPlaylistHandler.js
  29.  */
  30.  
  31. function sbPLSPlaylistHandler() {
  32.   this._originalURI = null;
  33. }
  34.  
  35. // sbIPlaylistReader
  36. sbPLSPlaylistHandler.prototype.__defineGetter__("originalURI",
  37. function()
  38. {
  39.   return this._originalURI;
  40. });
  41.  
  42. sbPLSPlaylistHandler.prototype.__defineSetter__("originalURI",
  43. function(value)
  44. {
  45.   this._originalURI = value;
  46. });
  47.  
  48. sbPLSPlaylistHandler.prototype.read =
  49. function(aFile, aMediaList, aReplace)
  50. {
  51.   var playlistItems = {};
  52.  
  53.   // Match any line that starts with File, Title, or Length and then a number,
  54.   // an equals sign, and the rest of the line.
  55.   var re = new RegExp("^(File|Title|Length)(\\d+)=(.+)$");
  56.  
  57.   var self = this;
  58.   SB_DetectCharsetAndProcessFile(aFile, function(aLine) {
  59.  
  60.     var a = aLine.match(re);
  61.     if (a) {
  62.       var kind = a[1];
  63.       var num = parseInt(a[2], 10);
  64.       var value = a[3];
  65.       if (!isNaN(num) && value != "") {
  66.  
  67.         var item = playlistItems[num];
  68.         if (!item) {
  69.           item = {};
  70.           playlistItems[num] = item;
  71.         }
  72.  
  73.         switch(kind) {
  74.           case "File":
  75.             var uri = SB_ResolveURI(value, this._originalURI);
  76.             if (uri)
  77.               item.uri = uri;
  78.           break;
  79.           case "Title":
  80.             if (value != "")
  81.               item.title = value;
  82.           break;
  83.           case "Length":
  84.             var length = parseInt(value, 10);
  85.             if (!isNaN(length) && length >= 0)
  86.               item.length = length;
  87.           break;
  88.         }
  89.       }
  90.     }
  91.  
  92.     // Ignore all other lines
  93.  
  94.   }, this);
  95.  
  96.   // Copy the items we found in the playlist into an array for sorting
  97.   var itemList = [];
  98.   for (var i in playlistItems) {
  99.     itemList.push({ index: i, data: playlistItems[i]});
  100.   }
  101.  
  102.   // Sort the items by index
  103.   itemList.sort(function(a, b) { a.index - b.index });
  104.  
  105.   var toAdd = [];
  106.   itemList.forEach(function(e) {
  107.     var data = e.data;
  108.     if (data.uri) {
  109.       var item = { uri: data.uri, properties: {} };
  110.       toAdd.push(item);
  111.       if (data.title)
  112.         item.properties[SBProperties.trackName] = data.title;
  113.       if (data.length)
  114.         item.properties[SBProperties.duration] = data.length * 1000000;
  115.     }
  116.   });
  117.  
  118.   SB_AddItems(toAdd, aMediaList, aReplace);
  119. }
  120.  
  121. sbPLSPlaylistHandler.prototype.vote =
  122. function(aURL)
  123. {
  124.   return 10000;
  125. }
  126.  
  127. sbPLSPlaylistHandler.prototype.name =
  128. function()
  129. {
  130.   return "Songbird PLS Reader";
  131. }
  132.  
  133. sbPLSPlaylistHandler.prototype.description =
  134. function()
  135. {
  136.   return "Loads PLS playlists from remote and local locations.";
  137. }
  138.  
  139. sbPLSPlaylistHandler.prototype.supportedMIMETypes =
  140. function(aMIMECount, aMIMETypes)
  141. {
  142.   var mimeTypes = ["audio/x-scpls"];
  143.   aMIMECount.value = mimeTypes.length;
  144.   return mimeTypes;
  145. }
  146.  
  147. sbPLSPlaylistHandler.prototype.supportedFileExtensions =
  148. function(aExtCount, aExts)
  149. {
  150.   var exts = ["pls"];
  151.   aExtCount.value = exts.length;
  152.   return exts;
  153. }
  154.  
  155. sbPLSPlaylistHandler.prototype.QueryInterface =
  156. function(iid)
  157. {
  158.   if (!iid.equals(Ci.sbIPlaylistReader) &&
  159.       !iid.equals(Ci.nsISupports))
  160.     throw Cr.NS_ERROR_NO_INTERFACE;
  161.   return this;
  162. }
  163.  
  164.