-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_ui.py
executable file
·112 lines (86 loc) · 3.46 KB
/
start_ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
""" Full screen mode for GMusicBrowser.
Start the UI, waits for update_ui.py to change it trough POST requests.
- *Date:* 09 January 2018.
- *Author:* Lilian Besson, © 2018.
- *Licence:* MIT Licence, https://lbesson.mit-license.org/.
- *Web:* https://github.com/Naereen/GMusicBrowser-FullScreen-WebApp
"""
from __future__ import print_function, division # Python 2 compatibility if needed
from subprocess import call
def cmd_gmusicbrowser(arg):
return call(["gmusicbrowser", "-cmd", arg])
def cmd_Volumesh(arg):
"""Requires my Volume.sh script, download it from https://github.com/Naereen/GMusicBrowser-FullScreen-WebApp/blob/master/Volume.sh and place it somewhere in your PATH (or leave it here)."""
try:
return call(["Volume.sh", arg])
except:
pritn("Requires my Volume.sh script, download it from https://github.com/Naereen/GMusicBrowser-FullScreen-WebApp/blob/master/Volume.sh and place it somewhere in your PATH (or leave it here in the same folder as 'start_ui.py').")
try:
from flask import Flask, request, render_template
except ImportError:
print("'flask' module could not be found...")
print("Install it with 'pip install flask' or 'pip3 install flask'")
app = Flask("Full screen mode for GMusicBrowser")
app.template_folder = '.'
action = None
data = {}
@app.route("/")
def hello():
global action, data
if action is None:
pause()
play()
print("Server handles a '/' GET request...") # DEBUG
return render_template("template.html", action=action, data=data)
@app.route("/start", methods=['POST'])
def start():
global action, data
action = "start"
data = request.form.to_dict()
print("Server handles a '/start' POST request...") # DEBUG
print("request.form =", request.form) # DEBUG
return render_template("template.html", action=action, data=data)
@app.route("/stop", methods=['POST'])
def stop():
global action, data
action = "stop"
data = request.form.to_dict()
print("Server handles a '/start' POST request...") # DEBUG
print("request.form =", request.form) # DEBUG
return render_template("template.html", action=action, data=data)
@app.route("/prev", methods=['GET', 'POST'])
def prev():
cmd_gmusicbrowser("PrevSong")
return render_template("template.html", action=action, data=data)
@app.route("/play", methods=['GET', 'POST'])
def play():
cmd_gmusicbrowser("Play")
return render_template("template.html", action=action, data=data)
@app.route("/playpause", methods=['GET', 'POST'])
def playpause():
cmd_gmusicbrowser("PlayPause")
return render_template("template.html", action=action, data=data)
@app.route("/pause", methods=['GET', 'POST'])
def pause():
cmd_gmusicbrowser("Pause")
return render_template("template.html", action=action, data=data)
@app.route("/next", methods=['GET', 'POST'])
def next():
cmd_gmusicbrowser("NextSong")
return render_template("template.html", action=action, data=data)
@app.route("/volumedown", methods=['GET', 'POST'])
def volumedown():
cmd_Volumesh("-")
return render_template("template.html", action=action, data=data)
@app.route("/volumeup", methods=['GET', 'POST'])
def volumeup():
cmd_Volumesh("+")
return render_template("template.html", action=action, data=data)
def main():
print("""Run this Flask app with the following bash lines:
$ FLASK_APP=start_ui.py flask run
""")
if __name__ == '__main__':
main()