add shuffle
This commit is contained in:
parent
b4882ea4d9
commit
d7eb2c0863
16
events.py
16
events.py
|
@ -59,6 +59,22 @@ async def select_track(request, ws, data):
|
||||||
await ws.send_json(ret)
|
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
|
||||||
|
ret = {'event': 'track', 'ok': True, 'data': track}
|
||||||
|
await ws.send_json(ret)
|
||||||
|
|
||||||
|
|
||||||
events = {}
|
events = {}
|
||||||
for obj in dir():
|
for obj in dir():
|
||||||
if type(locals()[obj]) == types.FunctionType:
|
if type(locals()[obj]) == types.FunctionType:
|
||||||
|
|
|
@ -2,6 +2,11 @@ var socket;
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
socket = init_websocket();
|
socket = init_websocket();
|
||||||
|
document.querySelector('#player').addEventListener('ended', function() {
|
||||||
|
if (document.querySelector('#shuffle').checked) {
|
||||||
|
socket.send_event('random_track', {});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Websocket setup */
|
/* Websocket setup */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user