summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorgana <Morgana@icolotl.com>2026-09-16 14:42:36 -0500
committerMorgana <Morgana@icolotl.com>2026-09-16 14:42:36 -0500
commita7cbcf6efdc7c50814374b22d41a05f69eeb1ef4 (patch)
treea289c89d6d1216edcd8ed78e0a4cdd6ff9205936
parent971a7225d784a624b4ceb56b9e367d6f33625482 (diff)
Improve music hostingHEADmain
-rw-r--r--.gitignore3
-rw-r--r--ivt.py19
-rw-r--r--static/script/main.js17
3 files changed, 17 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
index c89489d..82afffe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
__pycache__/
.venv/
data/
-music/ \ No newline at end of file
+music/
+static/dl/ \ No newline at end of file
diff --git a/ivt.py b/ivt.py
index a2683bd..94d5bf5 100644
--- a/ivt.py
+++ b/ivt.py
@@ -22,9 +22,12 @@ from argparse import ArgumentParser, ArgumentError, Namespace, _SubParsersAction
from typing import Literal
import sqlite3
from hashlib import scrypt
-from os import urandom, listdir
+from os import urandom, listdir, mkdir, link
+from os.path import isdir
+from uuid import uuid4, UUID
from hmac import compare_digest
from colorsys import rgb_to_hsv
+from shutil import rmtree
import requests
from websockets.asyncio.server import serve, ServerConnection
@@ -51,6 +54,9 @@ class IVTModel:
cur.execute("SELECT value FROM config WHERE key = 'light_url'")
self.light_url = cur.fetchone()[0]
+ if not isdir("static/dl"):
+ mkdir("static/dl")
+
async def newSession(self, websocket: ServerConnection) -> None:
name = self.genNewAnonName()
session = IVTSession(self, name, websocket)
@@ -94,6 +100,7 @@ class IVTModel:
await server.serve_forever()
except (InterruptedError, asyncio.exceptions.CancelledError):
print("Exiting.")
+ rmtree("static/dl")
def makeParser(self) -> ArgumentParser:
parser = ArgumentParser(
@@ -391,9 +398,9 @@ class IVTSession:
await self.send_error("song not found")
return
await self.send_text(f"Playing {album}/{song}...")
- with open(f"music/{album}/{song}.mp3", "rb") as musicfile:
- await self.send_prelude("music")
- await self.socket.send(musicfile.read())
+ songuuid = uuid4()
+ link(f"music/{album}/{song}.mp3", f"static/dl/{songuuid}.mp3")
+ await self.send_music(songuuid)
async def send_password_request(
self, pwdreturn: str, pwddata: Namespace, prompt: str, text: str
@@ -413,8 +420,8 @@ class IVTSession:
async def send_action(self, action: str) -> None:
await self.socket.send(dumps({"act": "action", "action": action}))
- async def send_prelude(self, action: str) -> None:
- await self.socket.send(dumps({"act": "prelude", "action": action}))
+ async def send_music(self, uuid: UUID) -> None:
+ await self.socket.send(dumps({"act": "music", "uuid": str(uuid)}))
async def send_display(self, msg) -> None:
await self.socket.send(dumps({"act": "display", "msg": msg}))
diff --git a/static/script/main.js b/static/script/main.js
index c023851..f6534e3 100644
--- a/static/script/main.js
+++ b/static/script/main.js
@@ -72,7 +72,6 @@ class IVTClient {
this.username = null;
this.pwdreturn = false;
this.oldprompt = null;
- this.prelude = null;
this.printTextCLS(BANNER, "term-bold term-centered");
this.stdinBox.addEventListener("submit", (event) => {
event.preventDefault();
@@ -104,14 +103,6 @@ class IVTClient {
this.stdinBtn.disabled = true;
})
this.socket.addEventListener("message", (event) => {
- if (this.prelude) {
- var fxn = this["on_" + this.prelude + "_prelude"];
- if (fxn) {
- fxn.call(this, event.data)
- }
- this.prelude = null;
- return
- }
var data = JSON.parse(event.data);
var fxn = this["on_" + data.act + "_msg"];
if (fxn) {
@@ -157,13 +148,9 @@ class IVTClient {
}
}
- on_prelude_msg(data) {
- this.prelude = data.action;
- }
-
- async on_music_prelude(data) {
+ async on_music_msg(data) {
var elem = document.createElement("audio");
- elem.src = window.URL.createObjectURL(data);
+ elem.src = `dl/${data.uuid}.mp3`;
elem.controls = true;
elem.autoplay = true;
this.stdout.append(elem);