Compare commits

..

No commits in common. "2f80e3c7a22ed5259482c5f6be801773d6227d39" and "ade66a4a1b9f426f76595b30b4d7abfe9c698a13" have entirely different histories.

4 changed files with 23 additions and 79 deletions

View File

@ -8,7 +8,7 @@ import random
import subprocess import subprocess
from urllib import parse from urllib import parse
from flask import Flask, Response, render_template, send_file from flask import Flask, Response, render_template
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
MUSIC_DIR = "/mnt/music/Music" MUSIC_DIR = "/mnt/music/Music"
@ -32,7 +32,6 @@ def index():
nav_items.sort() nav_items.sort()
nav_items = [item + '/' for item in nav_items] 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_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 = "/" cd = "/"
return render_template('index.html', **locals()) return render_template('index.html', **locals())
@ -85,7 +84,7 @@ def get_dir(directory):
@app.route('/get_shuffle') @app.route('/get_shuffle')
def shuffle(): def shuffle():
"""Returns a randomly selected track from the library.""" """Returns a randomly selected song from the library."""
item = random.choice(os.listdir(MUSIC_DIR)) item = random.choice(os.listdir(MUSIC_DIR))
path = os.path.join(MUSIC_DIR, item) path = os.path.join(MUSIC_DIR, item)
n = 0 n = 0
@ -102,18 +101,5 @@ def shuffle():
return path.replace(MUSIC_DIR, '') 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__": if __name__ == "__main__":
app.run(host='0.0.0.0', port=5150) app.run(host='0.0.0.0', port=5150)

View File

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

View File

@ -1,20 +1,17 @@
var httpRequest var httpRequest
function load() { function load() {
// track has ended
document.getElementById('player').addEventListener('ended', function() { document.getElementById('player').addEventListener('ended', function() {
// shuffle if (!document.getElementById('shuffle').checked) { return; }
if (document.getElementById('shuffle').checked) { httpRequest = new XMLHttpRequest();
httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function() {
httpRequest.onreadystatechange = function() { if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; }
if (httpRequest.readyState !== XMLHttpRequest.DONE) { return; } if (httpRequest.status !== 200) { return; }
if (httpRequest.status !== 200) { return; } let track = httpRequest.responseText;
let track = httpRequest.responseText; change_track(track);
change_track(track);
}
httpRequest.open('GET', '/musik/get_shuffle', true);
httpRequest.send();
} }
httpRequest.open('GET', '/musik/get_shuffle', true);
httpRequest.send();
}); });
} }
@ -40,10 +37,6 @@ function change_track(track) {
player.load(); player.load();
player.play(); player.play();
document.getElementById('nowPlaying').innerHTML = track; document.getElementById('nowPlaying').innerHTML = track;
let cd = document.getElementById('currentDirectory').innerText;
let art = document.getElementById('albumCover');
art.firstChild.src = '/musik/album_cover' + cd + 'folder.jpg';
} }
function get_dir(item) { function get_dir(item) {

View File

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