aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiล„ski <harry666t@gmail.com>2015-04-16 21:56:47 +0200
committerKamil Cholewiล„ski <harry666t@gmail.com>2015-04-16 21:56:47 +0200
commit695c2aad12e9f782a72ecdefd3ba489e68ed954c (patch)
treec832968145f4a2b2078b4153f6715c12d7c1ef4d
parent1a792d8f621ac96393c2ecbe9b4609123aad71cf (diff)
downloadmpw-695c2aad12e9f782a72ecdefd3ba489e68ed954c.zip
mpw-695c2aad12e9f782a72ecdefd3ba489e68ed954c.tar.gz
mpw-695c2aad12e9f782a72ecdefd3ba489e68ed954c.tar.bz2
Add a knob to change symbols to simple/fancy
-rw-r--r--mpw.py102
-rw-r--r--templates/base.html13
-rw-r--r--templates/browse.html3
3 files changed, 86 insertions, 32 deletions
diff --git a/mpw.py b/mpw.py
index 6c124ad..ac19011 100644
--- a/mpw.py
+++ b/mpw.py
@@ -5,28 +5,57 @@ import uuid
SYMBOLS = {
- "volume": {
- 0: "๐Ÿ”‡", 1: "๐Ÿ”ˆ", 2: "๐Ÿ”‰", 3: "๐Ÿ”Š",
+ "fancy": {
+ "volume": {
+ 0: "๐Ÿ”‡", 1: "๐Ÿ”ˆ", 2: "๐Ÿ”‰", 3: "๐Ÿ”Š",
+ },
+ "controls": {
+ "stop": "โ—ผ",
+ "play-pause": "โฏ",
+ "play": "โต",
+ "pause": "โธ",
+ "prev": "โฎ",
+ "next": "โญ",
+ "fbackward": "โช",
+ "fforward": "โฉ",
+ },
+ "other": {
+ "refresh": "๐Ÿ”ƒ",
+ "shuffle": "๐Ÿ”ƒ",
+ "delete": "โŒ",
+ "add": "โž•",
+ "song": "๐ŸŽถ",
+ "folder": "๐Ÿ“‚",
+ "logo": "๐„ž",
+ },
},
- "controls": {
- "stop": "โ—ผ",
- "play-pause": "โฏ",
- "play": "โต",
- "pause": "โธ",
- "prev": "โฎ",
- "next": "โญ",
- "fbackward": "โช",
- "fforward": "โฉ",
- },
- "other": {
- "refresh": "๐Ÿ”ƒ",
- "delete": "โŒ",
- "add": "โž•",
- "song": "๐ŸŽถ",
- "folder": "๐Ÿ“‚",
+ "simple": {
+ "volume": {
+ 0: "[muted]", 1: "[quiet]", 2: "[normal]", 3: "[loud]",
+ },
+ "controls": {
+ "stop": "[stop]",
+ "play-pause": "[play/pause]",
+ "play": "[play]",
+ "pause": "[pause]",
+ "prev": "[prev]",
+ "next": "[next]",
+ "fbackward": "[fast forward]",
+ "fforward": "[fast backward]",
+ },
+ "other": {
+ "refresh": "[refresh]",
+ "shuffle": "[shuffle]",
+ "delete": "[del]",
+ "add": "[add]",
+ "song": "[song]",
+ "folder": "[folder]",
+ "logo": "[music]",
+ },
},
}
+
app = flask.Flask(__name__)
app.mpd = mpd.MPDClient()
app.secret_key = hex(uuid.getnode()) # WARNING: **VERY INSECURE**
@@ -49,19 +78,24 @@ def mpd_disconnect(response):
return response
+def get_symbols(default="simple"):
+ return SYMBOLS[flask.session.setdefault("symbols", default)]
+
+
def rehydrate(item):
+ symbols = get_symbols()
if "file" in item:
item.setdefault("title", os.path.basename(item["file"]))
item.setdefault("artist", "?")
item.setdefault("type", "file")
item.setdefault("path", item["file"])
item.setdefault("label", item["title"])
- item.setdefault("icon", SYMBOLS["other"]["song"])
+ item.setdefault("icon", symbols["other"]["song"])
elif "directory" in item:
item.setdefault("type", "directory")
item.setdefault("path", item["directory"])
item.setdefault("label", os.path.basename(item["path"]))
- item.setdefault("icon", SYMBOLS["other"]["folder"])
+ item.setdefault("icon", symbols["other"]["folder"])
return item
@@ -69,18 +103,24 @@ def get_current_context():
playlist = list(map(rehydrate, app.mpd.playlistinfo()))
song = rehydrate(app.mpd.currentsong())
status = app.mpd.status()
- state = SYMBOLS["controls"][status["state"]]
+ symbols = get_symbols()
+ state = symbols["controls"][status["state"]]
+ logo = symbols["other"]["logo"]
status_line = (
- "{state} {artist} - {title}".format(state=state, **song)
+ "{logo} {state} {artist} - {title}".format(
+ logo=logo, state=state, **song
+ )
if status["state"] in {"play", "pause"} else
- "{state} Not playing".format(state=state)
+ "{logo} {state} Not playing".format(logo=logo, state=state)
)
return {
"playlist": playlist,
"song": song,
"status": status,
"status_line": status_line,
- "symbols": SYMBOLS,
+ "symbols": symbols,
+ "autorefresh": flask.session["autorefresh"],
+ "symbols_mode": flask.session["symbols"],
}
@@ -99,7 +139,6 @@ def make_breadcrumbs(path):
@app.route("/")
def index():
context = get_current_context()
- context["autorefresh"] = flask.session["autorefresh"]
return flask.render_template("base.html", **context)
@@ -111,7 +150,6 @@ def browse(path=""):
context["listing"] = listing
context["path"] = path
context["breadcrumbs"] = make_breadcrumbs(path)
- context["autorefresh"] = flask.session["autorefresh"]
return flask.render_template("browse.html", **context)
@@ -176,9 +214,15 @@ def library(action, path):
return flask.redirect(flask.url_for("index"))
-@app.route("/settings/autorefresh/<int:value>", methods=["POST"])
-def settings_autorefresh(value):
- flask.session["autorefresh"] = int(value)
+@app.route("/settings/<string:key>/<string:value>", methods=["POST"])
+def settings(key, value):
+ schema = {
+ "autorefresh": int,
+ "symbols": str,
+ }
+ if key not in schema:
+ flask.abort(404)
+ flask.session[key] = schema[key](value)
return flask.redirect(flask.url_for("index"))
diff --git a/templates/base.html b/templates/base.html
index 94d117c..a8a1aee 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -22,7 +22,7 @@
{% endblock %}
<title>
{% block title %}
- ๐„ž {{ status_line }}
+ {{ status_line }}
{% endblock %}
</title>
<style>
@@ -36,7 +36,7 @@
</style>
</head>
<body>
- <h1>๐„ž {{ status_line }}</h1>
+ <h1>{{ status_line }}</h1>
{% block control %}
<div class="playback controls">
{{ button("/controls/prev", symbols.controls.prev) }}
@@ -95,7 +95,7 @@
{{ button("/playlist/clear-old",
symbols.other.delete + " CLEAR OLD") }}
{{ button("/playlist/shuffle",
- symbols.other.refresh + " SHUFFLE") }}
+ symbols.other.shuffle + " SHUFFLE") }}
</div>
{% endblock %}
{% block settings %}
@@ -109,6 +109,13 @@
{{ button("/settings/autorefresh/30", "Enable (30s)") }}
{% endif %}
</span>
+ <span>Symbols
+ {% if symbols_mode == "simple" %}
+ {{ button("/settings/symbols/fancy", "Go fancy") }}
+ {% else %}
+ {{ button("/settings/symbols/simple", "Go simple") }}
+ {% endif %}
+ </span>
</div>
{% endblock %}
</body>
diff --git a/templates/browse.html b/templates/browse.html
index 95a684b..c1d5c3d 100644
--- a/templates/browse.html
+++ b/templates/browse.html
@@ -5,6 +5,9 @@
{# don't use autorefresh #}
{% block autorefresh %}
{% endblock %}
+{# don't show settings #}
+{% block settings %}
+{% endblock %}
{% block browse %}
<table>
<thead>