2021-04-27 10:07:17 +01:00
|
|
|
import time
|
|
|
|
from datetime import datetime
|
2021-06-07 14:44:50 +01:00
|
|
|
from quart import g, render_template, request, jsonify, websocket
|
2021-04-27 10:07:17 +01:00
|
|
|
from http import HTTPStatus
|
2021-06-07 14:44:50 +01:00
|
|
|
import trio
|
2021-04-27 10:07:17 +01:00
|
|
|
from lnbits.decorators import check_user_exists, validate_uuids
|
|
|
|
from lnbits.core.models import Payment
|
|
|
|
|
2021-05-12 15:47:21 +01:00
|
|
|
import json
|
2021-04-27 10:07:17 +01:00
|
|
|
from . import jukebox_ext
|
|
|
|
from .crud import get_jukebox
|
2021-06-11 15:42:50 +01:00
|
|
|
from .views_api import api_get_jukebox_device_check
|
2021-04-27 10:07:17 +01:00
|
|
|
|
2021-04-29 08:47:58 +01:00
|
|
|
|
2021-04-27 10:07:17 +01:00
|
|
|
@jukebox_ext.route("/")
|
|
|
|
@validate_uuids(["usr"], required=True)
|
|
|
|
@check_user_exists()
|
|
|
|
async def index():
|
|
|
|
return await render_template("jukebox/index.html", user=g.user)
|
|
|
|
|
|
|
|
|
|
|
|
@jukebox_ext.route("/<juke_id>")
|
2021-06-11 20:27:13 +01:00
|
|
|
async def connect_to_jukebox(juke_id):
|
2021-04-27 10:07:17 +01:00
|
|
|
jukebox = await get_jukebox(juke_id)
|
2021-05-05 23:03:22 +01:00
|
|
|
if not jukebox:
|
|
|
|
return "error"
|
2021-06-11 20:27:13 +01:00
|
|
|
deviceCheck = await api_get_jukebox_device_check(juke_id)
|
|
|
|
devices = json.loads(deviceCheck[0].text)
|
|
|
|
deviceConnected = False
|
|
|
|
for device in devices["devices"]:
|
|
|
|
if device["id"] == jukebox.sp_device.split("-")[1]:
|
|
|
|
deviceConnected = True
|
|
|
|
if deviceConnected:
|
2021-06-11 15:42:50 +01:00
|
|
|
return await render_template(
|
|
|
|
"jukebox/jukebox.html",
|
|
|
|
playlists=jukebox.sp_playlists.split(","),
|
|
|
|
juke_id=juke_id,
|
|
|
|
price=jukebox.price,
|
|
|
|
inkey=jukebox.inkey,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return await render_template("jukebox/error.html")
|