Compare commits
2 Commits
b4882ea4d9
...
c3e19308aa
Author | SHA1 | Date | |
---|---|---|---|
c3e19308aa | |||
d7eb2c0863 |
20
events.py
20
events.py
|
@ -55,6 +55,26 @@ async def select_track(request, ws, data):
|
|||
fpath = fpath.replace('flac', 'opus')
|
||||
fpath = parse.quote(fpath)
|
||||
track['url'] = fpath
|
||||
coverart = parse.urljoin(fpath, 'folder.jpg')
|
||||
track['coverart'] = coverart
|
||||
ret = {'event': 'track', 'ok': True, 'data': track}
|
||||
await ws.send_json(ret)
|
||||
|
||||
|
||||
async def random_track(request, ws, data):
|
||||
"""Select a random track."""
|
||||
async with request.app['pool'].acquire() as conn:
|
||||
track = await conn.fetchrow(
|
||||
"SELECT * FROM TRACK ORDER BY random() LIMIT 1")
|
||||
track = dict(track)
|
||||
fpath = track.pop('filepath')
|
||||
track.pop('last_modified')
|
||||
fpath = config.static_prefix + os.path.relpath(fpath, config.music_dir)
|
||||
fpath = fpath.replace('.flac', '.opus')
|
||||
fpath = parse.quote(fpath)
|
||||
track['url'] = fpath
|
||||
coverart = parse.urljoin(fpath, 'folder.jpg')
|
||||
track['coverart'] = coverart
|
||||
ret = {'event': 'track', 'ok': True, 'data': track}
|
||||
await ws.send_json(ret)
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@ body {
|
|||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
img {
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
main {
|
||||
height: 100%;
|
||||
display: grid;
|
||||
|
|
|
@ -2,6 +2,11 @@ var socket;
|
|||
|
||||
function load() {
|
||||
socket = init_websocket();
|
||||
document.querySelector('#player').addEventListener('ended', function() {
|
||||
if (document.querySelector('#shuffle').checked) {
|
||||
socket.send_event('random_track', {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* Websocket setup */
|
||||
|
@ -117,6 +122,7 @@ function track_recv(data) {
|
|||
player.firstElementChild.src = data['url'];
|
||||
player.load();
|
||||
player.play();
|
||||
document.querySelector('#albumCover').firstChild.src = data['coverart'];
|
||||
}
|
||||
|
||||
/* Websocket send */
|
||||
|
|
Loading…
Reference in New Issue
Block a user