sort tracks better

This commit is contained in:
iou1name 2019-02-05 11:33:58 -05:00
parent 9cd963f910
commit 6c27ea933b
2 changed files with 6 additions and 3 deletions

View File

@ -35,6 +35,7 @@ class Track:
m = mutagen.mp3.EasyMP3(filepath)
else:
m = mutagen.File(filepath)
self.tracknumber = m.get('tracknumber', [''])[0]
self.title = m.get('title', [''])[0]
self.artist = m.get('artist', [''])[0]
self.album = m.get('album', [''])[0]
@ -55,6 +56,7 @@ def build_library(root_dir):
filepath = os.path.join(root_dir, dir_name, file)
track = Track(filepath)
tracks.append(track)
print("Done")
return tracks
@ -133,7 +135,9 @@ class Selection(Resource):
found.append(track)
if not found:
abort(404, message="Album does not exist.")
return [t.title for t in found]
found = [t.tracknumber + " - " + t.title for t in found]
found.sort()
return found
elif args.get('artist'):
found = []

View File

@ -43,7 +43,7 @@ function select_album(select) {
nav_items = JSON.parse(httpRequest.responseText);
let html_str = '';
for (let i = 0; i < nav_items.length; i++) {
html_str += '<option value="' + nav_items[i] + '">' + nav_items[i] + '</option>';
html_str += '<option value="' + nav_items[i].replace(/\d* - /, '') + '">' + nav_items[i] + '</option>';
}
document.getElementById('trackList').innerHTML = html_str;
};
@ -59,7 +59,6 @@ function select_track(select) {
if (httpRequest.status !== 200) { return; }
let track = JSON.parse(httpRequest.responseText);
console.log(track);
let source = document.getElementById('stream');
source.src = track.streampath;
let player = document.getElementById('player');