diff options
Diffstat (limited to 'ivt.py')
| -rw-r--r-- | ivt.py | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -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})) |
