feat: playback mode selection in the web interface.
This commit is contained in:
parent
a46a1d7073
commit
45f6923534
44
interface.py
44
interface.py
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from flask import Flask, render_template, request, redirect, send_file, Response, jsonify
|
from flask import Flask, render_template, request, redirect, send_file, Response, jsonify, abort
|
||||||
import variables as var
|
import variables as var
|
||||||
import util
|
import util
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -132,6 +132,19 @@ def playlist():
|
|||||||
|
|
||||||
return jsonify({ 'items': items })
|
return jsonify({ 'items': items })
|
||||||
|
|
||||||
|
def status():
|
||||||
|
if (var.playlist.length() > 0):
|
||||||
|
return jsonify({'ver': var.playlist.version,
|
||||||
|
'empty': False,
|
||||||
|
'play': not var.botamusique.is_pause,
|
||||||
|
'mode': var.playlist.mode})
|
||||||
|
else:
|
||||||
|
return jsonify({'ver': var.playlist.version,
|
||||||
|
'empty': True,
|
||||||
|
'play': False,
|
||||||
|
'mode': var.playlist.mode})
|
||||||
|
|
||||||
|
|
||||||
@web.route("/post", methods=['POST'])
|
@web.route("/post", methods=['POST'])
|
||||||
@requires_auth
|
@requires_auth
|
||||||
def post():
|
def post():
|
||||||
@ -145,7 +158,7 @@ def post():
|
|||||||
item = {'type': 'file',
|
item = {'type': 'file',
|
||||||
'path' : request.form['add_file_bottom'],
|
'path' : request.form['add_file_bottom'],
|
||||||
'title' : '',
|
'title' : '',
|
||||||
'user' : 'Web'}
|
'user' : 'Remote Control'}
|
||||||
item = var.playlist.append(util.get_music_tag_info(item))
|
item = var.playlist.append(util.get_music_tag_info(item))
|
||||||
logging.info('web: add to playlist(bottom): ' + util.format_debug_song_string(item))
|
logging.info('web: add to playlist(bottom): ' + util.format_debug_song_string(item))
|
||||||
|
|
||||||
@ -155,7 +168,7 @@ def post():
|
|||||||
item = {'type': 'file',
|
item = {'type': 'file',
|
||||||
'path' : request.form['add_file_next'],
|
'path' : request.form['add_file_next'],
|
||||||
'title' : '',
|
'title' : '',
|
||||||
'user' : 'Web'}
|
'user' : 'Remote Control'}
|
||||||
item = var.playlist.insert(
|
item = var.playlist.insert(
|
||||||
var.playlist.current_index + 1,
|
var.playlist.current_index + 1,
|
||||||
item
|
item
|
||||||
@ -188,7 +201,7 @@ def post():
|
|||||||
files = list(map(lambda file:
|
files = list(map(lambda file:
|
||||||
{'type':'file',
|
{'type':'file',
|
||||||
'path': os.path.join(folder, file),
|
'path': os.path.join(folder, file),
|
||||||
'user':'Web'}, files))
|
'user':'Remote Control'}, files))
|
||||||
|
|
||||||
files = var.playlist.extend(files)
|
files = var.playlist.extend(files)
|
||||||
|
|
||||||
@ -199,7 +212,7 @@ def post():
|
|||||||
elif 'add_url' in request.form:
|
elif 'add_url' in request.form:
|
||||||
music = {'type':'url',
|
music = {'type':'url',
|
||||||
'url': request.form['add_url'],
|
'url': request.form['add_url'],
|
||||||
'user': 'Web',
|
'user': 'Remote Control',
|
||||||
'ready': 'validation'}
|
'ready': 'validation'}
|
||||||
music = var.botamusique.validate_music(music)
|
music = var.botamusique.validate_music(music)
|
||||||
if music:
|
if music:
|
||||||
@ -212,7 +225,7 @@ def post():
|
|||||||
elif 'add_radio' in request.form:
|
elif 'add_radio' in request.form:
|
||||||
music = var.playlist.append({'type': 'radio',
|
music = var.playlist.append({'type': 'radio',
|
||||||
'path': request.form['add_radio'],
|
'path': request.form['add_radio'],
|
||||||
'user': "Web"})
|
'user': "Remote Control"})
|
||||||
logging.info("web: add to playlist: " + util.format_debug_song_string(music))
|
logging.info("web: add to playlist: " + util.format_debug_song_string(music))
|
||||||
|
|
||||||
elif 'delete_music' in request.form:
|
elif 'delete_music' in request.form:
|
||||||
@ -265,11 +278,17 @@ def post():
|
|||||||
if action == "randomize":
|
if action == "randomize":
|
||||||
var.botamusique.stop()
|
var.botamusique.stop()
|
||||||
var.playlist.set_mode("random")
|
var.playlist.set_mode("random")
|
||||||
|
var.db.set('playlist', 'playback_mode', "random")
|
||||||
|
logging.info("web: playback mode changed to random.")
|
||||||
var.botamusique.resume()
|
var.botamusique.resume()
|
||||||
if action == "one-shot":
|
if action == "one-shot":
|
||||||
var.playlist.set_mode("one-shot")
|
var.playlist.set_mode("one-shot")
|
||||||
|
var.db.set('playlist', 'playback_mode', "one-shot")
|
||||||
|
logging.info("web: playback mode changed to one-shot.")
|
||||||
if action == "repeat":
|
if action == "repeat":
|
||||||
var.playlist.set_mode("repeat")
|
var.playlist.set_mode("repeat")
|
||||||
|
var.db.set('playlist', 'playback_mode', "repeat")
|
||||||
|
logging.info("web: playback mode changed to one-shot.")
|
||||||
elif action == "stop":
|
elif action == "stop":
|
||||||
var.botamusique.stop()
|
var.botamusique.stop()
|
||||||
elif action == "pause":
|
elif action == "pause":
|
||||||
@ -293,10 +312,7 @@ def post():
|
|||||||
var.db.set('bot', 'volume', str(var.botamusique.volume_set))
|
var.db.set('bot', 'volume', str(var.botamusique.volume_set))
|
||||||
logging.info("web: volume up to %d" % (var.botamusique.volume_set * 100))
|
logging.info("web: volume up to %d" % (var.botamusique.volume_set * 100))
|
||||||
|
|
||||||
if(var.playlist.length() > 0):
|
return status()
|
||||||
return jsonify({'ver': var.playlist.version, 'empty': False, 'play': not var.botamusique.is_pause})
|
|
||||||
else:
|
|
||||||
return jsonify({'ver': var.playlist.version, 'empty': True, 'play': False})
|
|
||||||
|
|
||||||
@web.route('/upload', methods=["POST"])
|
@web.route('/upload', methods=["POST"])
|
||||||
def upload():
|
def upload():
|
||||||
@ -358,8 +374,8 @@ def download():
|
|||||||
try:
|
try:
|
||||||
return send_file(filepath, as_attachment=True)
|
return send_file(filepath, as_attachment=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.exception(e)
|
logging.exception(e)
|
||||||
self.Error(400)
|
abort(404)
|
||||||
elif 'directory' in request.args:
|
elif 'directory' in request.args:
|
||||||
requested_dir = request.args['directory']
|
requested_dir = request.args['directory']
|
||||||
folder_path = var.music_folder
|
folder_path = var.music_folder
|
||||||
@ -373,8 +389,8 @@ def download():
|
|||||||
try:
|
try:
|
||||||
return send_file(zipfile, as_attachment=True)
|
return send_file(zipfile, as_attachment=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.exception(e)
|
logging.exception(e)
|
||||||
self.Error(400)
|
abort(404)
|
||||||
|
|
||||||
return redirect("./", code=400)
|
return redirect("./", code=400)
|
||||||
|
|
||||||
|
@ -120,11 +120,6 @@
|
|||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="btn-group" style="margin-bottom: 5px;">
|
<div class="btn-group" style="margin-bottom: 5px;">
|
||||||
<button type="button" class="btn btn-primary btn-space"
|
|
||||||
onclick="request('post', {action : 'randomize'})">
|
|
||||||
<i class="fas fa-random" aria-hidden="true"></i>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button type="button" id="play-btn" class="btn btn-info btn-space"
|
<button type="button" id="play-btn" class="btn btn-info btn-space"
|
||||||
onclick="request('post', {action : 'resume'})" disabled>
|
onclick="request('post', {action : 'resume'})" disabled>
|
||||||
<i class="fas fa-play" aria-hidden="true"></i>
|
<i class="fas fa-play" aria-hidden="true"></i>
|
||||||
@ -142,6 +137,28 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-group" style="float: right;">
|
<div class="btn-group" style="float: right;">
|
||||||
|
<button type="button" id="oneshot-btn" class="btn btn-primary btn-space"
|
||||||
|
title="One-shot Playlist"
|
||||||
|
style="height: 38px; width: 45px"
|
||||||
|
onclick="request('post', {action : 'one-shot'})">
|
||||||
|
<span class="fa-stack" style="font-size: 0.9em; margin-left:-8px; margin-top:-2px;">
|
||||||
|
<i class="fas fa-slash fa-stack-1x"></i>
|
||||||
|
<i class="fas fa-redo fa-stack-1x"></i>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button type="button" id="random-btn" class="btn btn-primary btn-space"
|
||||||
|
title="Randomize Playlist"
|
||||||
|
onclick="request('post', {action : 'randomize'})">
|
||||||
|
<i class="fas fa-random" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button type="button" id="repeat-btn" class="btn btn-primary btn-space"
|
||||||
|
title="Repeat Playlist"
|
||||||
|
onclick="request('post', {action : 'repeat'})">
|
||||||
|
<i class="fas fa-redo" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
<button type="button" class="btn btn-warning btn-space"
|
<button type="button" class="btn btn-warning btn-space"
|
||||||
onclick="request('post', {action : 'volume_down'})">
|
onclick="request('post', {action : 'volume_down'})">
|
||||||
<i class="fa fa-volume-down" aria-hidden="true"></i>
|
<i class="fa fa-volume-down" aria-hidden="true"></i>
|
||||||
@ -313,7 +330,7 @@
|
|||||||
updatePlaylist();
|
updatePlaylist();
|
||||||
playlist_ver = data.ver;
|
playlist_ver = data.ver;
|
||||||
}
|
}
|
||||||
updateControls(data.empty, data.play);
|
updateControls(data.empty, data.play, data.mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -343,7 +360,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateControls(empty, play){
|
function updateControls(empty, play, mode){
|
||||||
if(empty){
|
if(empty){
|
||||||
$("#play-btn").prop("disabled", true);
|
$("#play-btn").prop("disabled", true);
|
||||||
$("#pause-btn").prop("disabled", true);
|
$("#pause-btn").prop("disabled", true);
|
||||||
@ -359,6 +376,20 @@
|
|||||||
$("#stop-btn").prop("disabled", true);
|
$("#stop-btn").prop("disabled", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(mode === "one-shot"){
|
||||||
|
$("#oneshot-btn").removeClass("btn-primary").addClass("btn-secondary").prop("disabled", true);
|
||||||
|
$("#repeat-btn").removeClass("btn-secondary").addClass("btn-primary").prop("disabled", false);
|
||||||
|
$("#random-btn").removeClass("btn-secondary").addClass("btn-primary");
|
||||||
|
}else if(mode === "repeat"){
|
||||||
|
$("#repeat-btn").removeClass("btn-primary").addClass("btn-secondary").prop("disabled", true);
|
||||||
|
$("#oneshot-btn").removeClass("btn-secondary").addClass("btn-primary").prop("disabled", false);
|
||||||
|
$("#random-btn").removeClass("btn-secondary").addClass("btn-primary");
|
||||||
|
}else if(mode === "random"){
|
||||||
|
$("#random-btn").removeClass("btn-primary").addClass("btn-secondary");
|
||||||
|
$("#oneshot-btn").removeClass("btn-secondary").addClass("btn-primary").prop("disabled", false);
|
||||||
|
$("#repeat-btn").removeClass("btn-secondary").addClass("btn-primary").prop("disabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the version of playlist to see if update is needed.
|
// Check the version of playlist to see if update is needed.
|
||||||
@ -372,7 +403,7 @@
|
|||||||
updatePlaylist();
|
updatePlaylist();
|
||||||
playlist_ver = data.ver;
|
playlist_ver = data.ver;
|
||||||
}
|
}
|
||||||
updateControls(data.empty, data.play);
|
updateControls(data.empty, data.play, data.mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user