samples, list, player
This commit is contained in:
parent
b50d177465
commit
1ccbb59b8e
6 changed files with 67 additions and 2 deletions
BIN
.sampleplayer.py.swp
Normal file
BIN
.sampleplayer.py.swp
Normal file
Binary file not shown.
Binary file not shown.
|
@ -1,9 +1,26 @@
|
||||||
|
from playsound import playsound
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
from flask import render_template
|
||||||
|
from markupsafe import escape
|
||||||
|
from os import listdir
|
||||||
|
from os.path import join
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
samplefiles = listdir('samples')
|
||||||
|
samples = []
|
||||||
|
for f in samplefiles:
|
||||||
|
if '.wav' in f:
|
||||||
|
samples.append(f.replace('.wav', ''))
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def hello():
|
def hello():
|
||||||
return '<h1>Hello, World!</h1>'
|
return render_template('index.html', samples=samples)
|
||||||
|
|
||||||
|
@app.route('/play/<sample>')
|
||||||
|
def door(sample):
|
||||||
|
if sample in samples:
|
||||||
|
playsound(join('samples', f'{sample}.wav'))
|
||||||
|
return f'<h1>{escape(sample)}!</h1>'
|
||||||
|
else:
|
||||||
|
return 'no such sample'
|
||||||
|
|
||||||
|
|
BIN
samples/door.wav
Normal file
BIN
samples/door.wav
Normal file
Binary file not shown.
BIN
templates/.index.html.swp
Normal file
BIN
templates/.index.html.swp
Normal file
Binary file not shown.
48
templates/index.html
Normal file
48
templates/index.html
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Sample Player</title>
|
||||||
|
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
background-color: #f0f0f2;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||||
|
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
width: 600px;
|
||||||
|
margin: 5em auto;
|
||||||
|
padding: 2em;
|
||||||
|
background-color: #fdfdff;
|
||||||
|
border-radius: 0.5em;
|
||||||
|
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
|
||||||
|
}
|
||||||
|
a:link, a:visited {
|
||||||
|
color: #38488f;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
div {
|
||||||
|
margin: 0 auto;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<h1>Sample Player</h1>
|
||||||
|
<p>This domain is for use in illustrative examples in documents. You may use this
|
||||||
|
domain in literature without prior coordination or asking for permission.</p>
|
||||||
|
{% for sample in samples %}
|
||||||
|
<p><a href="/play/{{sample}}">{{sample}}</a></p>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue