summaryrefslogtreecommitdiff
path: root/static/player.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/player.js')
-rw-r--r--static/player.js55
1 files changed, 32 insertions, 23 deletions
diff --git a/static/player.js b/static/player.js
index b120fe1..eedb943 100644
--- a/static/player.js
+++ b/static/player.js
@@ -108,6 +108,36 @@ function output_link(obj) {
song_links.appendChild(li);
}
+function output_album(album) {
+ var li = document.createElement('li');
+ li.setAttribute('class', 'album');
+ li.appendChild(document.createTextNode(album ? album : '(No album)'));
+
+ var song_links = document.getElementById('song-links');
+ song_links.appendChild(li);
+}
+
+function add_results(json) {
+ var lastalbum = false;
+ for(var i = 0; i < json.length; i++) {
+ var type = json[i]["type"];
+ var path = json[i]["name"];
+ var track = json[i]["track"];
+ var name = path.substring(path.lastIndexOf('/')+1);
+ var cached = type == "file" ? json[i]["cached"] : false;
+ var metadata = json[i]["metadata"];
+
+ if(type == 'file' && metadata.album != lastalbum) {
+ output_album(metadata.album);
+ lastalbum = metadata.album;
+ }
+
+ var l = new MusicListing(type, path, name, track, metadata, cached);
+ output_link(l);
+ }
+ log('add_results: ' + lastalbum);
+}
+
function list(root) {
log('listing ' + root);
var xmlhttp = new XMLHttpRequest();
@@ -124,19 +154,7 @@ function list(root) {
l = new MusicListing('dir', up, '..');
output_link(l);
}
- for(var i = 0; i < json.length; i++) {
- var type = json[i]["type"];
- var path = json[i]["name"];
- var track = json[i]["track"];
- var name = path.substring(path.lastIndexOf('/')+1);
- var cached = type == "file" ? json[i]["cached"] : false;
- var metadata = json[i]["metadata"];
- log(metadata.artist);
- if('artist' in json[i]["metadata"])
- log('got artist');
- var l = new MusicListing(type, path, name, track, metadata, cached);
- output_link(l);
- }
+ add_results(json);
}
}
@@ -155,16 +173,7 @@ function do_search(e) {
var json = JSON.parse(xmlhttp.responseText);
document.getElementById('song-links').innerHTML = '';
output_link(new MusicListing('dir', '/', 'Go to root directory'));
- for(var i = 0; i < json.length; i++) {
- var type = json[i]["type"];
- var path = json[i]["name"];
- var track = json[i]["track"];
- var name = path.substring(path.lastIndexOf('/')+1);
- var cached = type == "file" ? json[i]["cached"] : false;
- var metadata = json[i]["metadata"];
- var l = new MusicListing(type, path, name, track, metadata, cached);
- output_link(l);
- }
+ add_results(json);
}
}