JSON schema v0.0.2
This commit is contained in:
parent
96be306b2b
commit
e9c55a67d3
2 changed files with 14 additions and 10 deletions
|
@ -25,7 +25,7 @@ async def handler(socket: SocketT) -> None:
|
|||
match data['action']:
|
||||
|
||||
case 'list': # list tracks in album
|
||||
await socket.send(response.ok_playlist(
|
||||
await socket.send(response.playlist(
|
||||
await ydl_wrap.get_playlist_items(
|
||||
ydls.get_ydl(data['site']),
|
||||
data['url'],
|
||||
|
@ -38,7 +38,7 @@ async def handler(socket: SocketT) -> None:
|
|||
data['url'],
|
||||
data.get('items'),
|
||||
)
|
||||
await socket.send(response.ok_downloaded(ret))
|
||||
await socket.send(response.dl_end(ret))
|
||||
|
||||
# TODO: cancellation
|
||||
|
||||
|
|
|
@ -1,25 +1,29 @@
|
|||
import json
|
||||
import traceback
|
||||
|
||||
OK = '{"ok":true}'
|
||||
|
||||
def ok_playlist(items: list[str]) -> str:
|
||||
def playlist(items: list[str]) -> str:
|
||||
return json.dumps({
|
||||
"ok": True,
|
||||
"type": "items",
|
||||
"data": items,
|
||||
})
|
||||
|
||||
def ok_downloaded(ret: int) -> str:
|
||||
def dl_progress(msg: str) -> str:
|
||||
return json.dumps({
|
||||
"type": "downloaded",
|
||||
"type": "dl_progress",
|
||||
"data": msg,
|
||||
})
|
||||
|
||||
def dl_end(ret: int) -> str:
|
||||
return json.dumps({
|
||||
"type": "dl_end",
|
||||
"data": ret,
|
||||
})
|
||||
|
||||
def error(ex: Exception) -> str:
|
||||
traceback.print_tb(ex.__traceback__)
|
||||
return json.dumps({
|
||||
"ok": False,
|
||||
"error": {
|
||||
"type": "error",
|
||||
"data": {
|
||||
"type": ex.__class__.__qualname__,
|
||||
"message": str(ex),
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue