changed css, added preliminary support for album art display

This commit is contained in:
iou1name 2018-09-20 10:00:07 -04:00
parent ade66a4a1b
commit f23b55e5bd
3 changed files with 60 additions and 14 deletions

View File

@ -8,7 +8,7 @@ import random
import subprocess
from urllib import parse
from flask import Flask, Response, render_template
from flask import Flask, Response, render_template, send_file
from werkzeug.utils import secure_filename
MUSIC_DIR = "/mnt/music/Music"
@ -32,6 +32,7 @@ def index():
nav_items.sort()
nav_items = [item + '/' for item in nav_items]
initial_track = "/Accept/Accept - Balls to the Wall (1983) [FLAC] {74321 93214 2}/01 - Balls to the Wall.flac"
initial_cover = "/Accept/Accept - Balls to the Wall (1983) [FLAC] {74321 93214 2}/folder.jpg"
cd = "/"
return render_template('index.html', **locals())
@ -84,7 +85,7 @@ def get_dir(directory):
@app.route('/get_shuffle')
def shuffle():
"""Returns a randomly selected song from the library."""
"""Returns a randomly selected track from the library."""
item = random.choice(os.listdir(MUSIC_DIR))
path = os.path.join(MUSIC_DIR, item)
n = 0
@ -101,5 +102,18 @@ def shuffle():
return path.replace(MUSIC_DIR, '')
@app.route('/album_cover/<path:cover>')
def album_cover(cover):
"""View for the raw audio file."""
path = os.path.join(MUSIC_DIR, cover)
path = os.path.abspath(path)
if not path.startswith(MUSIC_DIR):
return "False"
if not os.path.isfile(path):
return "False"
return send_file(path)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5150)

View File

@ -1,11 +1,20 @@
#mainContainer {
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 100%;
body {
margin: 0;
}
img {
max-width:100%;
max-height:100%;
}
#globalContainer {
display: flex;
flex-direction: column;
height: 100vh;
}
#titleContainer {
text-align: center;
}
#navigationContainer {
@ -15,6 +24,25 @@
border-bottom: 2px solid #ccc;
}
#currentDirectory {
padding-left: 0.5em;
}
#navItems {
list-style-type: none;
}
#playerContainer {
flex: 0 0 auto;
display: flex;
flex-direction: row;
justify-content: center;
}
#albumCover {
padding-right: 1em;
}
#playerControls {
text-align: center;
}

View File

@ -7,8 +7,8 @@
<script>window.onload = load;</script>
</head>
<body>
<div id="mainContainer">
<center><h1>Musik</h1></center>
<div id="globalContainer">
<div id="titleContainer"><h1>Musik</h1></div>
<div id="navigationContainer">
<div id="currentDirectory">{{ cd }}</div>
<ul id="navItems">
@ -18,13 +18,17 @@
</ul>
</div>
<div id="playerContainer">
<center>
<div><h3 id="nowPlaying">{{ initial_track }}</h3></div>
<div id="albumCover"><img src="/musik/album_cover{{ initial_cover }}"/></div>
<div id="playerControls">
<h3 id="nowPlaying">{{ initial_track }}</h3>
<audio id="player" controls>
<source id="stream" src="{{ url_for('stream', track=initial_track) }}" type="audio/ogg">
</audio>
<div><input type="checkbox" id="shuffle">Shuffle</input>
</center>
<div>
<input type="checkbox" name="shuffle" id="shuffle" checked="true">
<label for="shuffle">Shuffle</label>
</div>
</div>
</div>
</div>
</body>