Добавлены настройки расширения, введена поддержка локализации, изменены и адаптированы иконки приложений
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from contextlib import asynccontextmanager
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
@ -12,7 +13,61 @@ from jinja2 import Environment, FileSystemLoader
|
||||
import config
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
class TextStyle:
|
||||
PURPLE = '\033[95m'
|
||||
CYAN = '\033[96m'
|
||||
DARKCYAN = '\033[36m'
|
||||
BLUE = '\033[94m'
|
||||
GREEN = '\033[92m'
|
||||
YELLOW = '\033[93m'
|
||||
RED = '\033[91m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
END = '\033[0m'
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
bold = (TextStyle.BOLD, TextStyle.END)
|
||||
print('%sProgram Name:%s\tYT Music Live' % bold)
|
||||
print('%sVersion:%s\t1.0.0' % bold)
|
||||
print('%sAuthor:%s\t\tcsasq' % bold)
|
||||
print('%sEmail:%s\t\tcsasq@csasq.ru' % bold)
|
||||
print('%sWebsite:%s\thttps://csasq.ru/' % bold)
|
||||
print('%sLicense:%s\tCreative Commons Attribution-NonCommercial 4.0 International' % bold)
|
||||
print()
|
||||
print("%sYou are free to:%s" % bold)
|
||||
print("\t%sShare%s — copy and redistribute the material in any medium or format." % bold)
|
||||
print("\t%sAdapt%s — remix, transform, and build upon the material." % bold)
|
||||
print('\tThe licensor cannot revoke these freedoms as long as you follow the license terms.')
|
||||
print("%sUnder the following terms:%s" % bold)
|
||||
print("\t%sAttribution%s — You must give appropriate credit , provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use." % bold)
|
||||
print('\t%sNonCommercial%s — You may not use the material for commercial purposes.' % bold)
|
||||
print('\t%sNo additional restrictions%s — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.' % bold)
|
||||
print()
|
||||
print('%sSee the legal code:%s' % bold)
|
||||
print('https://creativecommons.org/licenses/by-nc/4.0/')
|
||||
print()
|
||||
print('%sSee the Git repository:%s' % bold)
|
||||
print('https://git.csasq.ru/csasq/yt-music-live')
|
||||
print()
|
||||
print('Application startup complete (Press CTRL+C to quit)')
|
||||
print('Widget is available at %shttp://%s:%d/overlay%s' % (
|
||||
TextStyle.BOLD,
|
||||
config.Main.host,
|
||||
config.Main.port,
|
||||
TextStyle.END,
|
||||
))
|
||||
yield
|
||||
print('Application shutdown complete')
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
openapi_url=None,
|
||||
docs_url=None,
|
||||
redoc_url=None,
|
||||
lifespan=lifespan,
|
||||
)
|
||||
app.mount(
|
||||
path='/static',
|
||||
app=StaticFiles(
|
||||
@ -51,42 +106,16 @@ class ConnectionManager:
|
||||
|
||||
|
||||
overlay_manager = ConnectionManager()
|
||||
plugin_manager = ConnectionManager()
|
||||
|
||||
|
||||
@app.options(
|
||||
path='/api/v1/overlay',
|
||||
)
|
||||
async def function():
|
||||
return Response(
|
||||
headers={
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': '*',
|
||||
'Access-Control-Allow-Headers': '*',
|
||||
},
|
||||
status_code=200,
|
||||
)
|
||||
server_manager = ConnectionManager()
|
||||
|
||||
|
||||
@app.get(
|
||||
path='/overlay',
|
||||
)
|
||||
async def function(
|
||||
justify_content: str = Query(
|
||||
default='end',
|
||||
alias='justify-content',
|
||||
),
|
||||
align_items: str = Query(
|
||||
default='end',
|
||||
alias='align-items',
|
||||
),
|
||||
):
|
||||
async def _():
|
||||
template = env.get_template('overlay.jinja2')
|
||||
return HTMLResponse(
|
||||
content=await template.render_async(
|
||||
justify_content=justify_content,
|
||||
align_items=align_items,
|
||||
),
|
||||
content=await template.render_async(),
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
@ -94,7 +123,7 @@ async def function(
|
||||
@app.get(
|
||||
path='/image',
|
||||
)
|
||||
async def function(
|
||||
async def _(
|
||||
src: str = Query(
|
||||
default=...,
|
||||
),
|
||||
@ -125,27 +154,41 @@ async def function(
|
||||
)
|
||||
|
||||
|
||||
@app.options(
|
||||
path='/api/v1/overlay',
|
||||
)
|
||||
async def _():
|
||||
return Response(
|
||||
headers={
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': '*',
|
||||
'Access-Control-Allow-Headers': '*',
|
||||
},
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
|
||||
@app.websocket('/ws/v1/overlay')
|
||||
async def function(
|
||||
async def _(
|
||||
websocket: WebSocket,
|
||||
):
|
||||
await overlay_manager.connect(websocket)
|
||||
try:
|
||||
while True:
|
||||
data = await websocket.receive_json()
|
||||
await plugin_manager.broadcast(data)
|
||||
await server_manager.broadcast(data)
|
||||
except WebSocketDisconnect:
|
||||
overlay_manager.disconnect(websocket)
|
||||
|
||||
|
||||
@app.websocket('/ws/v1/plugin')
|
||||
async def function(
|
||||
@app.websocket('/ws/v1/server')
|
||||
async def _(
|
||||
websocket: WebSocket,
|
||||
):
|
||||
await plugin_manager.connect(websocket)
|
||||
await server_manager.connect(websocket)
|
||||
try:
|
||||
while True:
|
||||
data = await websocket.receive_json()
|
||||
await overlay_manager.broadcast(data)
|
||||
except WebSocketDisconnect:
|
||||
plugin_manager.disconnect(websocket)
|
||||
server_manager.disconnect(websocket)
|
||||
|
Reference in New Issue
Block a user