sbPLSPlaylistHandler.js
Go to the documentation of this file.
1 
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 
function sbPLSPlaylistHandler()
function SB_DetectCharsetAndProcessFile(aFile, aCallback, aThis)
Detect the charset of the file aFile, convert the file encode to the detected one, and process the file line by line with the callback function aCallback.
function num(elem, prop)
return null
Definition: FeedWriter.js:1143
var uri
Definition: FeedWriter.js:1135
function SB_AddItems(aItems, aMediaList, aAddDistinctOnly)
countRef value
Definition: FeedWriter.js:1423
const Cr
const Ci
function SB_ResolveURI(aStringURL, aBaseURI)
observe data
Definition: FeedWriter.js:1329
_getSelectedPageStyle s i