From 6c27ea933b4c7689058bb4cb9560c08918ceeb03 Mon Sep 17 00:00:00 2001 From: iou1name Date: Tue, 5 Feb 2019 11:33:58 -0500 Subject: [PATCH] sort tracks better --- musik.py | 6 +++++- static/musik.js | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/musik.py b/musik.py index 80bb014..61401b7 100755 --- a/musik.py +++ b/musik.py @@ -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 = [] diff --git a/static/musik.js b/static/musik.js index ab1d2e2..e58a5ad 100644 --- a/static/musik.js +++ b/static/musik.js @@ -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 += ''; + html_str += ''; } 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');