Add dummy room
This commit is contained in:
parent
96fbe8058b
commit
bc9bf71824
3 changed files with 30 additions and 2 deletions
|
@ -9,6 +9,8 @@ from .room import Room
|
||||||
from .song import Song, init_db, get_song_by_title_artist, add_song_in_db
|
from .song import Song, init_db, get_song_by_title_artist, add_song_in_db
|
||||||
from .song_fetch import lastfm_query_search, download_song_mp3
|
from .song_fetch import lastfm_query_search, download_song_mp3
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +23,18 @@ db_conn = get_connection()
|
||||||
state = State(app, db_conn.cursor())
|
state = State(app, db_conn.cursor())
|
||||||
init_db(state.db)
|
init_db(state.db)
|
||||||
|
|
||||||
|
state.rooms[1000] = Room(
|
||||||
|
id=1000,
|
||||||
|
coord=(1.0, 5.5),
|
||||||
|
name="Test Room",
|
||||||
|
pin=None,
|
||||||
|
tags=set(),
|
||||||
|
songs={},
|
||||||
|
history=[],
|
||||||
|
playing=[Song(uuid="<uuid>", title="<title>", artist="<artist>", tags=[], image_id="<img>", youtube_id="<yt>")],
|
||||||
|
playing_idx=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def error(msg: str, status: int = 400) -> Response:
|
def error(msg: str, status: int = 400) -> Response:
|
||||||
res = jsonify({"success": False, "error": msg})
|
res = jsonify({"success": False, "error": msg})
|
||||||
|
@ -28,6 +42,17 @@ def error(msg: str, status: int = 400) -> Response:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def ws_broadcast(event: str, *, room_id: int | None = None, data: Any) -> None:
|
||||||
|
final = {}
|
||||||
|
|
||||||
|
if room_id is not None:
|
||||||
|
final["room_id"] = room_id
|
||||||
|
|
||||||
|
final["data"] = data
|
||||||
|
|
||||||
|
emit(event, final, broadcast=True, namespace="/")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/join")
|
@app.get("/api/join")
|
||||||
def join():
|
def join():
|
||||||
room_id = request.args.get("room")
|
room_id = request.args.get("room")
|
||||||
|
@ -144,6 +169,8 @@ def add_song():
|
||||||
## add in DB
|
## add in DB
|
||||||
add_song_in_db(info.artist, info.title, info.tags, info.img_id, yt_id)
|
add_song_in_db(info.artist, info.title, info.tags, info.img_id, yt_id)
|
||||||
|
|
||||||
|
## HERE: add song in the room list
|
||||||
|
|
||||||
return {"artist": info.artist, "title": info.title, "tags": info.tags, "image_id": info.img_id}
|
return {"artist": info.artist, "title": info.title, "tags": info.tags, "image_id": info.img_id}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,8 @@ class Room:
|
||||||
songs: dict[str, UserScoredSong] # all songs + user score (the playlist)
|
songs: dict[str, UserScoredSong] # all songs + user score (the playlist)
|
||||||
history: list[Song] # all songs previously played
|
history: list[Song] # all songs previously played
|
||||||
|
|
||||||
playing: list[Song] # queue
|
## playing queue info
|
||||||
|
playing: list[Song]
|
||||||
playing_idx: int
|
playing_idx: int
|
||||||
|
|
||||||
def renew_queue(self):
|
def renew_queue(self):
|
||||||
|
|
|
@ -18,7 +18,7 @@ def init_db(db: Cursor):
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True, slots=True, kw_only=True)
|
||||||
class Song:
|
class Song:
|
||||||
uuid: str
|
uuid: str
|
||||||
title: str
|
title: str
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue