81 lines
2.3 KiB
Python
81 lines
2.3 KiB
Python
|
#!/usr/bin/python3
|
||
|
|
||
|
from sys import argv, exit
|
||
|
from os import walk, path
|
||
|
|
||
|
if len(argv) <= 1:
|
||
|
print("No directory was supplied")
|
||
|
exit(-1)
|
||
|
|
||
|
page = """<!DOCTYPE html>
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
||
|
<head>
|
||
|
<meta charset="utf-8"/>
|
||
|
<title>Tracks</title>
|
||
|
<link type="text/css" rel="stylesheet" href="/style.css"/>
|
||
|
<script type="text/javascript" src="/xm.js"></script>
|
||
|
<script type="text/javascript">
|
||
|
(function (window, document) {
|
||
|
if (!window.XMPlayer)
|
||
|
window.XMPlayer = {};
|
||
|
var XMPlayer = window.XMPlayer;
|
||
|
|
||
|
window.loadAndPlayTrack = function(url) {
|
||
|
var request = new XMLHttpRequest();
|
||
|
request.responseType = "arraybuffer";
|
||
|
request.open('GET', url);
|
||
|
request.send();
|
||
|
request.onload = (_) => {
|
||
|
if (request.readyState === 4 && request.status === 200) {
|
||
|
XMPlayer.stop();
|
||
|
XMPlayer.load(request.response);
|
||
|
XMPlayer.play();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.onload = function() {
|
||
|
XMPlayer.init();
|
||
|
}
|
||
|
})(window, document)
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<div style="display: flex;">
|
||
|
<div>
|
||
|
<h2 id="mjestečko">mjestečko</h2>
|
||
|
<ul class="nav">
|
||
|
<li><a href="/">main page</a></li>
|
||
|
<li><a href="https://git.poto.cafe/veclavtalica/mjestecko">source</a></li>
|
||
|
<li><a href="/tracks.html">tracks</a></li>
|
||
|
<li><a href="/feed.xml">rss</a></li>
|
||
|
<li><a href="/articles/mjestečko.html">about</a></li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
|
||
|
<div class="container">
|
||
|
<h3 id="articles">Tracks</h3>
|
||
|
<p>.xm module tracks of my own. Btw, they're playable in browser :3</p>
|
||
|
<p>Note that some files are rendered incorrectly.</p>
|
||
|
<hr/>
|
||
|
"""
|
||
|
|
||
|
for _, _, files in walk(argv[1]):
|
||
|
files.sort()
|
||
|
for f in files:
|
||
|
if not f.endswith('.xm'):
|
||
|
continue
|
||
|
page += (
|
||
|
f""" <div><p style="display: inline;">{f}</p><button style="float: right;" onclick="window.loadAndPlayTrack('/tracks/{f}')">play</button></div>\n"""
|
||
|
" <hr/>\n"
|
||
|
)
|
||
|
|
||
|
page += """ </div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|
||
|
"""
|
||
|
|
||
|
print(page)
|