summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-08-16 21:53:06 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-08-16 21:53:06 +0200
commitf847dca4f388f30fb6c8cdd814b2e8508b753181 (patch)
tree430807ff5bf699533a392aefcdad1cea1a3c8dff
parenta3e86f3be768c8fa1fc2af12d5e5d66d9d9b82e8 (diff)
Simple metadata support for cue sheets.
-rw-r--r--directory.py15
-rw-r--r--static/player.js30
-rw-r--r--static/playlist.js4
3 files changed, 38 insertions, 11 deletions
diff --git a/directory.py b/directory.py
index 79024f4..5a757bd 100644
--- a/directory.py
+++ b/directory.py
@@ -5,9 +5,10 @@ from config import config
class DirectoryEntry(object):
'''Base class for directory entries.'''
- def __init__(self, path, isabs = False, track = None):
+ def __init__(self, path, isabs = False, track = None, metadata = {}):
self.path = path
self.track = track
+ self.metadata = metadata
if isabs:
self.abs_path = path
@@ -28,7 +29,7 @@ class DirectoryEntry(object):
return '<a href="/files/{path}">{name}</a><br />'.format(path = self.path, name = os.path.basename(self.path))
def json(self):
- return {'type': self.entry_type, 'name': self.path, 'track': self.track}
+ return {'type': self.entry_type, 'name': self.path, 'track': self.track, 'metadata': self.metadata}
class Directory(DirectoryEntry):
'''A directory entry inside a directory.'''
@@ -48,7 +49,15 @@ class Directory(DirectoryEntry):
if os.path.splitext(f)[1] == '.cue':
cue = cuesheet.Cuesheet(abs_path)
for t in cue.tracks:
- files.append(File(rel_path, track = t.track[0]))
+ metadata = {}
+ info = cue.info[0]
+ if info.performer:
+ metadata['artist'] = info.performer
+ if info.title:
+ metadata['album'] = info.title
+ if t.title:
+ metadata['title'] = t.title
+ files.append(File(rel_path, track = t.track[0], metadata = metadata))
else:
files.append(File(rel_path))
return sorted(directories) + sorted(files)
diff --git a/static/player.js b/static/player.js
index b358eb5..330938b 100644
--- a/static/player.js
+++ b/static/player.js
@@ -12,14 +12,32 @@ for(var i = 0; i < cache_images.length; i++) {
img.src = '/static/icons/' + cache_images[i];
}
-function MusicListing(type, path, name, track, cached) {
+function MusicListing(type, path, name, track, metadata, cached) {
this.type = type;
this.path = path;
this.name = name ? name : path.split('/').pop();
this.track = track;
+ this.metadata = metadata;
this.a = document.createElement('a');
this.a.ml = this;
+ this.get_text = function() {
+ if(!metadata)
+ return name;
+ var s = '';
+ if('artist' in metadata)
+ s = metadata['artist'] + ' - ';
+ if('album' in metadata)
+ s += metadata['album'] + ' - ';
+ if('title' in metadata)
+ s += metadata['title'];
+ if(s.length > 0 && track)
+ s = track + ' ' + s;
+ if(s.length == 0)
+ s = name;
+ return s;
+ }
+
this.play = function() {
var path = '/play?path=' + encodeURIComponent(this.path);
if(this.track)
@@ -49,9 +67,7 @@ function MusicListing(type, path, name, track, cached) {
className += ' file-cached'
a.setAttribute('class', className);
a.setAttribute('href', '#');
- var name = this.name;
- if(this.track)
- name += ' (track ' + this.track + ')';
+ var name = this.get_text();
a.appendChild(document.createTextNode(name));
var ml = this;
@@ -116,7 +132,11 @@ function list(root) {
var track = json[i]["track"];
var name = path.substring(path.lastIndexOf('/')+1);
var cached = type == "file" ? json[i]["cached"] : false;
- var l = new MusicListing(type, path, name, track, cached);
+ 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);
}
}
diff --git a/static/playlist.js b/static/playlist.js
index d2ac424..92758b0 100644
--- a/static/playlist.js
+++ b/static/playlist.js
@@ -20,9 +20,7 @@ function Playlist(pl, audio) {
this.add = function(ml) {
var a = document.createElement('a');
a.setAttribute('href', '#');
- var name = ml.name;
- if(ml.track)
- name += ' (track ' + ml.track + ')';
+ var name = ml.get_text();
a.appendChild(document.createTextNode(name));
a.ml = ml;
var li = document.createElement('li');