2023-05-23 16:38:25 +00:00
|
|
|
#!/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)
|
2023-05-25 06:14:13 +00:00
|
|
|
window.XMPlayer = {};
|
|
|
|
|
2023-05-23 16:38:25 +00:00
|
|
|
var XMPlayer = window.XMPlayer;
|
2023-05-25 06:14:13 +00:00
|
|
|
var was_init = false
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript
|
|
|
|
function b64toBlob(base64) {
|
|
|
|
const decoded = atob(base64);
|
|
|
|
const uInt8Array = new Uint8Array(decoded.length);
|
|
|
|
for (let i = 0; i < decoded.length; ++i)
|
|
|
|
uInt8Array[i] = decoded.charCodeAt(i);
|
|
|
|
return new Blob([uInt8Array]);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function decompressGzippedBase64(str) {
|
|
|
|
const ds = new DecompressionStream(`gzip`);
|
|
|
|
const decompressedStream = b64toBlob(str).stream().pipeThrough(ds);
|
|
|
|
return new Response(decompressedStream).blob();
|
|
|
|
}
|
2023-05-23 16:38:25 +00:00
|
|
|
|
|
|
|
window.loadAndPlayTrack = function(url) {
|
2023-05-25 06:14:13 +00:00
|
|
|
if (!was_init) {
|
|
|
|
XMPlayer.init();
|
|
|
|
was_init = true;
|
|
|
|
}
|
2023-05-23 16:38:25 +00:00
|
|
|
var request = new XMLHttpRequest();
|
2023-05-25 06:14:13 +00:00
|
|
|
request.responseType = `text`;
|
2023-05-23 16:38:25 +00:00
|
|
|
request.open('GET', url);
|
|
|
|
request.send();
|
2023-05-25 06:14:13 +00:00
|
|
|
request.onload = async(_) => {
|
2023-05-23 16:38:25 +00:00
|
|
|
if (request.readyState === 4 && request.status === 200) {
|
|
|
|
XMPlayer.stop();
|
2023-05-25 06:14:13 +00:00
|
|
|
XMPlayer.load(await (await decompressGzippedBase64(request.response)).arrayBuffer());
|
2023-05-23 16:38:25 +00:00
|
|
|
XMPlayer.play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})(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:
|
2023-05-25 06:14:13 +00:00
|
|
|
# note: Base64 gzip encoded data is expected.
|
|
|
|
if not f.endswith('.xm.txt'):
|
2023-05-23 16:38:25 +00:00
|
|
|
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)
|