3 var parseNum = function (index, len) {
4 if (len > 4) return parseBigNum(index, len);
6 var num = text.charCodeAt(index) & 255;
7 for (var i = 1; i < len; i++) {
9 num += text.charCodeAt(index + i) & 255;
14 var parseBigNum = function (index, len) {
15 var num = new BigNumber(text.charCodeAt(index) & 255);
16 for (var i = 1; i < len; i++) {
17 num = num.multiply(256);
18 num = num.add(text.charCodeAt(index + i) & 255);
23 this.name = function (index) {
24 return text.substring(index, index+4);
26 this.length = function (index) {
27 return parseNum(index+4, 4);
29 this.byteVal = function (index) {
30 return parseNum(index+8, 1);
32 this.shortVal = function (index) {
33 return parseNum(index+8, 2);
35 this.intVal = function (index) {
36 return parseNum(index+8, 4);
38 this.longVal = function (index) {
39 return parseNum(index+8, 8);
41 this.longlongVal = function (index) {
43 0: parseNum(index+8, 4),
44 1: parseNum(index+12, 4),
45 2: parseNum(index+16, 4),
46 3: parseNum(index+20, 4)
49 this.stringVal = function (index) {
50 var length = this.length(index);
52 for ( var i = 8; i < 8+length;) {
53 var c = text.charCodeAt(index + i) & 255;
56 string += String.fromCharCode(c);
58 } else if (c > 191 && c < 224) {
59 c2 = text.charCodeAt(index + i + 1) & 255;
60 string += String.fromCharCode(((c & 31)) << 6 | (c2 & 63));
63 c2 = text.charCodeAt(index + i + 1) & 255;
64 c3 = text.charCodeAt(index + i + 2) & 255;
65 string += String.fromCharCode(((c & 15)) << 12 | (c2 & 63) << 6
72 this.dateVal = function (index) {
73 return parseNum(index+8, 8);
75 this.versionVal = function (index) {
76 var version = text.charCodeAt(index+8) & 255;
79 version += text.charCodeAt(index+8 + i) & 255;
83 this.children = function (index) {
84 var kids = new Array();
85 var len = index + 8 + this.length(index);
89 i += 8 + this.length(i);
95 function PlayStatusUpdate(tree, index) {
97 var kids = tree.children(index);
108 for (child in kids) {
109 var node = kids[child];
110 switch (tree.name(node)) {
112 this.status = tree.byteVal(node);
115 this.revision = tree.intVal(node);
118 this.title = tree.stringVal(node);
121 this.artist = tree.stringVal(node);
124 this.album = tree.stringVal(node);
127 this.genre = tree.stringVal(node);
130 this.container = tree.longlongVal(node)[1];
131 this.id = tree.longlongVal(node)[3];
137 function findNode(tree, index, tag) {
138 var kids = tree.children(index);
139 for (child in kids) {
140 if (tree.name(kids[child]) == tag) {
147 function getItems(tree, index, handler) {
149 var items = new Array();
151 var kids = tree.children(index);
152 for (child in kids) {
153 items.push(handler(tree, kids[child]));
159 function Container(tree, index) {
168 var kids = tree.children(index);
169 for (child in kids) {
170 var node = kids[child];
171 switch (tree.name(node)) {
173 this.id = tree.intVal(node);
176 this.persistent = tree.longVal(node);
179 this.name = tree.stringVal(node);
182 this.base = tree.byteVal(node);
185 this.parent = tree.intVal(node);
188 this.items = tree.intVal(node);
194 function Playlist(tree, index) {
196 this.tracks = new Array();
198 var kids = tree.children(index);
200 for (child in kids) {
201 if (tree.name(kids[child]) == "mlcl") {
209 kids = tree.children(list);
210 for (child in kids) {
211 this.tracks.push(new Track(tree, kids[child]));
215 function Album(tree, index) {
220 this.persistantId = 0;
222 var kids = tree.children(index);
223 for (child in kids) {
224 var node = kids[child];
225 switch (tree.name(node)) {
227 this.id = tree.intVal(node);
230 this.name = tree.stringVal(node);
233 this.artist = tree.stringVal(node);
236 this.persistantId = tree.longVal(node);
242 function Track(tree, index) {
251 var kids = tree.children(index);
252 for (child in kids) {
253 var node = kids[child];
254 switch (tree.name(node)) {
256 this.album = tree.stringVal(node);
259 this.title = tree.stringVal(node);
262 this.artist = tree.stringVal(node);
265 this.genre = tree.stringVal(node);
268 this.id = tree.intVal(node);
271 this.persistent = tree.longVal(node);
277 function sysout(text) {
278 var p = document.createElement("PRE");
279 p.className = "debug";
280 p.appendChild(document.createTextNode(text));
281 document.body.appendChild(p);